From cc6f880665a2bee676aa1018d29effb965d92013 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 3 Aug 2023 14:14:55 +0930 Subject: [PATCH] ... --- app/agconnect-services.json | 186 +++++++++--------- .../notifications/HuaweiPushManager.kt | 11 +- .../HuaweiPushNotificationService.kt | 5 + app/src/main/AndroidManifest.xml | 2 +- .../notifications/GenericPushManager.kt | 10 +- .../notifications/PushManagerV1.kt | 25 ++- 6 files changed, 131 insertions(+), 108 deletions(-) diff --git a/app/agconnect-services.json b/app/agconnect-services.json index 99e95057e4..0c81d0477a 100644 --- a/app/agconnect-services.json +++ b/app/agconnect-services.json @@ -1,92 +1,96 @@ { - "agcgw":{ - "backurl":"connect-dre.hispace.hicloud.com", - "url":"connect-dre.dbankcloud.cn", - "websocketbackurl":"connect-ws-dre.hispace.dbankcloud.com", - "websocketurl":"connect-ws-dre.hispace.dbankcloud.cn" - }, - "agcgw_all":{ - "CN":"connect-drcn.dbankcloud.cn", - "CN_back":"connect-drcn.hispace.hicloud.com", - "DE":"connect-dre.dbankcloud.cn", - "DE_back":"connect-dre.hispace.hicloud.com", - "RU":"connect-drru.hispace.dbankcloud.ru", - "RU_back":"connect-drru.hispace.dbankcloud.cn", - "SG":"connect-dra.dbankcloud.cn", - "SG_back":"connect-dra.hispace.hicloud.com" - }, - "websocketgw_all":{ - "CN":"connect-ws-drcn.hispace.dbankcloud.cn", - "CN_back":"connect-ws-drcn.hispace.dbankcloud.com", - "DE":"connect-ws-dre.hispace.dbankcloud.cn", - "DE_back":"connect-ws-dre.hispace.dbankcloud.com", - "RU":"connect-ws-drru.hispace.dbankcloud.ru", - "RU_back":"connect-ws-drru.hispace.dbankcloud.cn", - "SG":"connect-ws-dra.hispace.dbankcloud.cn", - "SG_back":"connect-ws-dra.hispace.dbankcloud.com" - }, - "client":{ - "cp_id":"30061000024605000", - "product_id":"99536292102650699", - "client_id":"993355872258247936", - "client_secret":"0A83DC166FBF0696B884D38830E0B90AE8BBFF2D9CA8C26C9D9DA26816C2A9E3", - "project_id":"99536292102650699", - "app_id":"107146885", - "api_key":"DAEDAPld5VAZXpjfD+g0PwlXfya5ykPMYTMRYkySUjGfJg055ijAFNZBUtcykDPWZiaUcc4Mo9oJqmooL6HT8n4toO5COlWZjkqGXA==", - "package_name":"network.loki.messenger" - }, - "oauth_client":{ - "client_id":"107146885", - "client_type":1 - }, - "app_info":{ - "app_id":"107146885", - "package_name":"network.loki.messenger" - }, - "service":{ - "analytics":{ - "collector_url":"datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn", - "collector_url_ru":"datacollector-drru.dt.dbankcloud.ru,datacollector-drru.dt.hicloud.com", - "collector_url_sg":"datacollector-dra.dt.hicloud.com,datacollector-dra.dt.dbankcloud.cn", - "collector_url_de":"datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn", - "collector_url_cn":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn", - "resource_id":"p1", - "channel_id":"" - }, - "search":{ - "url":"https://search-dre.cloud.huawei.com" - }, - "cloudstorage":{ - "storage_url_sg_back":"https://agc-storage-dra.cloud.huawei.asia", - "storage_url_ru_back":"https://agc-storage-drru.cloud.huawei.ru", - "storage_url_ru":"https://agc-storage-drru.cloud.huawei.ru", - "storage_url_de_back":"https://agc-storage-dre.cloud.huawei.eu", - "storage_url_de":"https://ops-dre.agcstorage.link", - "storage_url":"https://agc-storage-drcn.platform.dbankcloud.cn", - "storage_url_sg":"https://ops-dra.agcstorage.link", - "storage_url_cn_back":"https://agc-storage-drcn.cloud.huawei.com.cn", - "storage_url_cn":"https://agc-storage-drcn.platform.dbankcloud.cn" - }, - "ml":{ - "mlservice_url":"ml-api-dre.ai.dbankcloud.com,ml-api-dre.ai.dbankcloud.cn" - } - }, - "region":"DE", - "configuration_version":"3.0", - "appInfos":[ - { - "package_name":"network.loki.messenger", - "client":{ - "app_id":"107146885" - }, - "app_info":{ - "package_name":"network.loki.messenger", - "app_id":"107146885" - }, - "oauth_client":{ - "client_type":1, - "client_id":"107146885" - } - } - ] -} + "agcgw":{ + "backurl":"connect-dre.hispace.hicloud.com", + "url":"connect-dre.dbankcloud.cn", + "websocketbackurl":"connect-ws-dre.hispace.dbankcloud.com", + "websocketurl":"connect-ws-dre.hispace.dbankcloud.cn" + }, + "agcgw_all":{ + "CN":"connect-drcn.dbankcloud.cn", + "CN_back":"connect-drcn.hispace.hicloud.com", + "DE":"connect-dre.dbankcloud.cn", + "DE_back":"connect-dre.hispace.hicloud.com", + "RU":"connect-drru.hispace.dbankcloud.ru", + "RU_back":"connect-drru.hispace.dbankcloud.cn", + "SG":"connect-dra.dbankcloud.cn", + "SG_back":"connect-dra.hispace.hicloud.com" + }, + "websocketgw_all":{ + "CN":"connect-ws-drcn.hispace.dbankcloud.cn", + "CN_back":"connect-ws-drcn.hispace.dbankcloud.com", + "DE":"connect-ws-dre.hispace.dbankcloud.cn", + "DE_back":"connect-ws-dre.hispace.dbankcloud.com", + "RU":"connect-ws-drru.hispace.dbankcloud.ru", + "RU_back":"connect-ws-drru.hispace.dbankcloud.cn", + "SG":"connect-ws-dra.hispace.dbankcloud.cn", + "SG_back":"connect-ws-dra.hispace.dbankcloud.com" + }, + "client":{ + "cp_id":"890061000023000573", + "product_id":"99536292102532562", + "client_id":"954244311350791232", + "client_secret":"555999202D718B6744DAD2E923B386DC17F3F4E29F5105CE0D061EED328DADEE", + "project_id":"99536292102532562", + "app_id":"107205081", + "api_key":"DAEDABeddLEqUy0QRwa1THLwRA0OqrSuyci/HjNvVSmsdWsXRM2U2hRaCyqfvGYH1IFOKrauArssz/WPMLRHCYxliWf+DTj9bDwlWA==", + "package_name":"network.loki.messenger" + }, + "oauth_client":{ + "client_id":"107205081", + "client_type":1 + }, + "app_info":{ + "app_id":"107205081", + "package_name":"network.loki.messenger" + }, + "service":{ + "analytics":{ + "collector_url":"datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn", + "collector_url_ru":"datacollector-drru.dt.dbankcloud.ru,datacollector-drru.dt.hicloud.com", + "collector_url_sg":"datacollector-dra.dt.hicloud.com,datacollector-dra.dt.dbankcloud.cn", + "collector_url_de":"datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn", + "collector_url_cn":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn", + "resource_id":"p1", + "channel_id":"" + }, + "edukit":{ + "edu_url":"edukit.edu.cloud.huawei.com.cn", + "dh_url":"edukit.edu.cloud.huawei.com.cn" + }, + "search":{ + "url":"https://search-dre.cloud.huawei.com" + }, + "cloudstorage":{ + "storage_url_sg_back":"https://agc-storage-dra.cloud.huawei.asia", + "storage_url_ru_back":"https://agc-storage-drru.cloud.huawei.ru", + "storage_url_ru":"https://agc-storage-drru.cloud.huawei.ru", + "storage_url_de_back":"https://agc-storage-dre.cloud.huawei.eu", + "storage_url_de":"https://ops-dre.agcstorage.link", + "storage_url":"https://agc-storage-drcn.platform.dbankcloud.cn", + "storage_url_sg":"https://ops-dra.agcstorage.link", + "storage_url_cn_back":"https://agc-storage-drcn.cloud.huawei.com.cn", + "storage_url_cn":"https://agc-storage-drcn.platform.dbankcloud.cn" + }, + "ml":{ + "mlservice_url":"ml-api-dre.ai.dbankcloud.com,ml-api-dre.ai.dbankcloud.cn" + } + }, + "region":"DE", + "configuration_version":"3.0", + "appInfos":[ + { + "package_name":"network.loki.messenger", + "client":{ + "app_id":"107205081" + }, + "app_info":{ + "package_name":"network.loki.messenger", + "app_id":"107205081" + }, + "oauth_client":{ + "client_type":1, + "client_id":"107205081" + } + } + ] +} \ No newline at end of file diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt index 87a78ef035..26da350372 100644 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushManager.kt @@ -31,16 +31,17 @@ class HuaweiPushManager @Inject constructor( if (force) cancel() else if (isActive) return } - val appId = "107146885" + val appId = "107205081" val tokenScope = "HCM" val hmsInstanceId = HmsInstanceId.getInstance(context) + genericPushManager.refresh(TextSecurePreferences.getFCMToken(context), force) + MainScope().launch(Dispatchers.IO) { val token = hmsInstanceId.getToken(appId, tokenScope) - - Log.d(TAG, "refresh() with huawei token: $token") - - genericPushManager.refresh(token, force) + Log.d(TAG, "refresh() hmsInstanceId => huawei token: $token") +// +//// genericPushManager.refresh(token, force) } } } diff --git a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt index 7dae82dd30..16ac969d2c 100644 --- a/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt +++ b/app/src/huawei/kotlin/org/thoughtcrime/securesms/notifications/HuaweiPushNotificationService.kt @@ -4,6 +4,7 @@ import android.os.Bundle import com.huawei.hms.push.HmsMessageService import com.huawei.hms.push.RemoteMessage import dagger.hilt.android.AndroidEntryPoint +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.utilities.Log import java.lang.Exception import javax.inject.Inject @@ -40,6 +41,10 @@ class HuaweiPushNotificationService: HmsMessageService() { override fun onNewToken(token: String?, bundle: Bundle?) { Log.d("pnh", "New HCM token: $token.") + + if (token == TextSecurePreferences.getFCMToken(this)) return + + TextSecurePreferences.setFCMToken(this, token) pushManager.refresh(true) } override fun onMessageReceived(message: RemoteMessage?) { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d6bed361e5..ed51a7ea8d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -80,7 +80,7 @@ + android:value="appid=107205081"> { - Log.d(TAG, "refresh() called") + fun refresh(token: String?, force: Boolean): Promise<*, Exception> { + Log.d(TAG, "refresh($token, $force) called") + token ?: return emptyPromise() val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return emptyPromise() val userEdKey = KeyPairUtilities.getUserED25519KeyPair(context) ?: return emptyPromise() @@ -62,6 +63,11 @@ class GenericPushManager @Inject constructor( userEd25519Key: KeyPair, namespaces: List = listOf(Namespace.DEFAULT) ): Promise<*, Exception> { + android.util.Log.d( + TAG, + "register() called with: token = $token, publicKey = $publicKey, userEd25519Key = $userEd25519Key, namespaces = $namespaces" + ) + val v1 = PushManagerV1.register( device = device, token = token, diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt index b8894162d5..3e82bda4a3 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/PushManagerV1.kt @@ -32,18 +32,25 @@ object PushManagerV1 { token: String? = TextSecurePreferences.getFCMToken(context), publicKey: String? = TextSecurePreferences.getLocalNumber(context), legacyGroupPublicKeys: Collection = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys() - ): Promise<*, Exception> = - when { - isUsingFCM -> retryIfNeeded(maxRetryCount) { - doRegister(token, publicKey, device, legacyGroupPublicKeys) - } fail { exception -> - Log.d(TAG, "Couldn't register for FCM due to error: $exception.") - } - else -> emptyPromise() + ): Promise<*, Exception> = when { + isUsingFCM -> retryIfNeeded(maxRetryCount) { + android.util.Log.d( + TAG, + "register() called with: device = $device, isUsingFCM = $isUsingFCM, token = $token, publicKey = $publicKey, legacyGroupPublicKeys = $legacyGroupPublicKeys" + ) + doRegister(token, publicKey, device, legacyGroupPublicKeys) + } fail { exception -> + Log.d(TAG, "Couldn't register for FCM due to error: $exception... $device $token $publicKey $legacyGroupPublicKeys") } + else -> emptyPromise() + } + private fun doRegister(token: String?, publicKey: String?, device: Device, legacyGroupPublicKeys: Collection): Promise<*, Exception> { - Log.d(TAG, "registerV1 requested") + android.util.Log.d( + TAG, + "doRegister() called with: token = $token, publicKey = $publicKey, device = $device, legacyGroupPublicKeys = $legacyGroupPublicKeys" + ) token ?: return emptyPromise() publicKey ?: return emptyPromise()