This commit is contained in:
andrew 2023-08-02 14:55:31 +09:30
parent 7ee9b14247
commit 41d24ef2c3
3 changed files with 49 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.notifications
import android.content.Context
import android.util.Log
import com.huawei.hmf.tasks.Tasks
import com.huawei.hms.aaid.HmsInstanceId
import dagger.hilt.android.qualifiers.ApplicationContext
@ -9,9 +10,12 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.session.libsession.utilities.TextSecurePreferences
import javax.inject.Inject
import javax.inject.Singleton
private val TAG = HuaweiPushManager::class.java.name
@Singleton
class HuaweiPushManager @Inject constructor(
@ApplicationContext private val context: Context,
@ -27,13 +31,16 @@ class HuaweiPushManager @Inject constructor(
if (force) cancel() else if (isActive) return
}
val appId = "107146885"
val tokenScope = "HCM"
val hmsInstanceId = HmsInstanceId.getInstance(context)
MainScope().launch(Dispatchers.IO) {
val task = hmsInstanceId.aaid
Tasks.await(task)
if (!isActive) return@launch // don't 'complete' task if we were canceled
task.result?.id?.let { genericPushManager.refresh(it, force) }
val token = hmsInstanceId.getToken(appId, tokenScope)
Log.d(TAG, "refresh() with huawei token: $token")
genericPushManager.refresh(token, force)
}
}
}

View File

@ -5,18 +5,45 @@ import com.huawei.hms.push.HmsMessageService
import com.huawei.hms.push.RemoteMessage
import dagger.hilt.android.AndroidEntryPoint
import org.session.libsignal.utilities.Log
import java.lang.Exception
import javax.inject.Inject
@AndroidEntryPoint
class HuaweiPushNotificationService: HmsMessageService() {
init {
Log.d("pnh", "init Huawei Service")
}
@Inject lateinit var pushManager: PushManager
@Inject lateinit var pushHandler: PushHandler
override fun onCreate() {
Log.d("pnh", "onCreate Huawei Service")
super.onCreate()
}
override fun onMessageDelivered(p0: String?, p1: Exception?) {
Log.d("pnh", "onMessageDelivered")
super.onMessageDelivered(p0, p1)
}
override fun onMessageSent(p0: String?) {
Log.d("pnh", "onMessageSent")
super.onMessageSent(p0)
}
override fun onNewToken(p0: String?) {
Log.d("pnh", "onNewToken")
super.onNewToken(p0)
}
override fun onNewToken(token: String?, bundle: Bundle?) {
Log.d("Loki", "New HCM token: $token.")
Log.d("pnh", "New HCM token: $token.")
pushManager.refresh(true)
}
override fun onMessageReceived(message: RemoteMessage?) {
Log.d("pnh", "onMessageReceived: $message.")
pushHandler.onPush(message?.dataOfMap)
}
override fun onDeletedMessages() {

View File

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