This commit is contained in:
andrew 2023-08-11 17:37:35 +09:30
parent 16177d5cb1
commit 77100231d2
4 changed files with 14 additions and 42 deletions

View File

@ -78,16 +78,6 @@
android:theme="@style/Theme.Session.DayNight" android:theme="@style/Theme.Session.DayNight"
tools:replace="android:allowBackup"> tools:replace="android:allowBackup">
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="appid=107205081">
</meta-data>
<meta-data
android:name="com.huawei.hms.client.cpid"
android:value="cpid=30061000024605000">
</meta-data>
<!-- Disable all analytics --> <!-- Disable all analytics -->
<meta-data <meta-data

View File

@ -44,7 +44,7 @@ class PushReceiver @Inject constructor(@ApplicationContext val context: Context)
val job = BatchMessageReceiveJob(listOf(MessageReceiveParameters(envelopeAsData)), null) val job = BatchMessageReceiveJob(listOf(MessageReceiveParameters(envelopeAsData)), null)
JobQueue.shared.add(job) JobQueue.shared.add(job)
} catch (e: Exception) { } catch (e: Exception) {
Log.d(TAG, "Failed to unwrap data for message due to error: $e.") Log.d(TAG, "Failed to unwrap data for message due to error.", e)
} }
} }
@ -67,7 +67,7 @@ class PushReceiver @Inject constructor(@ApplicationContext val context: Context)
try { try {
decrypt(Base64.decode(this["enc_payload"])) decrypt(Base64.decode(this["enc_payload"]))
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Invalid push notification: ${e.message}") Log.e(TAG, "Invalid push notification", e)
null null
} }
} }
@ -91,20 +91,11 @@ class PushReceiver @Inject constructor(@ApplicationContext val context: Context)
val metadataJson = (expectedList[0] as? BencodeString)?.value ?: error("no metadata") val metadataJson = (expectedList[0] as? BencodeString)?.value ?: error("no metadata")
val metadata: PushNotificationMetadata = Json.decodeFromString(String(metadataJson)) val metadata: PushNotificationMetadata = Json.decodeFromString(String(metadataJson))
val content: ByteArray? = return (expectedList.getOrNull(1) as? BencodeString)?.value.also {
if (expectedList.size >= 2) (expectedList[1] as? BencodeString)?.value else null // null content is valid only if we got a "data_too_long" flag
// null content is valid only if we got a "data_too_long" flag it?.let { check(metadata.data_len == it.size) { "wrong message data size" } }
if (content == null) ?: check(metadata.data_too_long) { "missing message data, but no too-long flag" }
check(metadata.data_too_long) { "missing message data, but no too-long flag" } }
else
check(metadata.data_len == content.size) { "wrong message data size" }
Log.d(
TAG,
"Received push for ${metadata.account}/${metadata.namespace}, msg ${metadata.msg_hash}, ${metadata.data_len}B"
)
return content
} }
fun getOrCreateNotificationKey(): Key { fun getOrCreateNotificationKey(): Key {

View File

@ -40,14 +40,14 @@ class PushRegistry @Inject constructor(
} }
pushRegistrationJob = MainScope().launch { pushRegistrationJob = MainScope().launch {
register(tokenFetcher.fetch()) fail { register(tokenFetcher.fetch()) fail { e ->
Log.e(TAG, "register failed", it) Log.e(TAG, "register failed", e)
} }
} }
} }
fun register(token: String?): Promise<*, Exception> { fun register(token: String?): Promise<*, Exception> {
Log.d(TAG, "refresh($token) called") Log.d(TAG, "refresh() called")
if (token?.isNotEmpty() != true) return emptyPromise() if (token?.isNotEmpty() != true) return emptyPromise()
@ -72,10 +72,7 @@ class PushRegistry @Inject constructor(
userEd25519Key: KeyPair, userEd25519Key: KeyPair,
namespaces: List<Int> = listOf(Namespace.DEFAULT) namespaces: List<Int> = listOf(Namespace.DEFAULT)
): Promise<*, Exception> { ): Promise<*, Exception> {
Log.d( Log.d(TAG, "register() called")
TAG,
"register() called with: token = $token, publicKey = $publicKey, userEd25519Key = $userEd25519Key, namespaces = $namespaces"
)
val v1 = PushRegistryV1.register( val v1 = PushRegistryV1.register(
device = device, device = device,

View File

@ -34,23 +34,17 @@ object PushRegistryV1 {
legacyGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys() legacyGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
): Promise<*, Exception> = when { ): Promise<*, Exception> = when {
isUsingFCM -> retryIfNeeded(maxRetryCount) { isUsingFCM -> retryIfNeeded(maxRetryCount) {
android.util.Log.d( Log.d(TAG, "register() called")
TAG,
"register() called with: device = $device, isUsingFCM = $isUsingFCM, token = $token, publicKey = $publicKey, legacyGroupPublicKeys = $legacyGroupPublicKeys"
)
doRegister(token, publicKey, device, legacyGroupPublicKeys) doRegister(token, publicKey, device, legacyGroupPublicKeys)
} fail { exception -> } fail { exception ->
Log.d(TAG, "Couldn't register for FCM due to error: $exception... $device $token $publicKey $legacyGroupPublicKeys") Log.d(TAG, "Couldn't register for FCM due to error", exception)
} }
else -> emptyPromise() else -> emptyPromise()
} }
private fun doRegister(token: String?, publicKey: String?, device: Device, legacyGroupPublicKeys: Collection<String>): Promise<*, Exception> { private fun doRegister(token: String?, publicKey: String?, device: Device, legacyGroupPublicKeys: Collection<String>): Promise<*, Exception> {
android.util.Log.d( Log.d(TAG, "doRegister() called")
TAG,
"doRegister() called with: token = $token, publicKey = $publicKey, device = $device, legacyGroupPublicKeys = $legacyGroupPublicKeys"
)
token ?: return emptyPromise() token ?: return emptyPromise()
publicKey ?: return emptyPromise() publicKey ?: return emptyPromise()