mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-23 00:17:34 +00:00
...
This commit is contained in:
parent
7ee9b14247
commit
41d24ef2c3
@ -1,6 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms.notifications
|
package org.thoughtcrime.securesms.notifications
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
import com.huawei.hmf.tasks.Tasks
|
import com.huawei.hmf.tasks.Tasks
|
||||||
import com.huawei.hms.aaid.HmsInstanceId
|
import com.huawei.hms.aaid.HmsInstanceId
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
@ -9,9 +10,12 @@ import kotlinx.coroutines.Job
|
|||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
private val TAG = HuaweiPushManager::class.java.name
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class HuaweiPushManager @Inject constructor(
|
class HuaweiPushManager @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
@ -27,13 +31,16 @@ class HuaweiPushManager @Inject constructor(
|
|||||||
if (force) cancel() else if (isActive) return
|
if (force) cancel() else if (isActive) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val appId = "107146885"
|
||||||
|
val tokenScope = "HCM"
|
||||||
val hmsInstanceId = HmsInstanceId.getInstance(context)
|
val hmsInstanceId = HmsInstanceId.getInstance(context)
|
||||||
|
|
||||||
MainScope().launch(Dispatchers.IO) {
|
MainScope().launch(Dispatchers.IO) {
|
||||||
val task = hmsInstanceId.aaid
|
val token = hmsInstanceId.getToken(appId, tokenScope)
|
||||||
Tasks.await(task)
|
|
||||||
if (!isActive) return@launch // don't 'complete' task if we were canceled
|
Log.d(TAG, "refresh() with huawei token: $token")
|
||||||
task.result?.id?.let { genericPushManager.refresh(it, force) }
|
|
||||||
|
genericPushManager.refresh(token, force)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,45 @@ import com.huawei.hms.push.HmsMessageService
|
|||||||
import com.huawei.hms.push.RemoteMessage
|
import com.huawei.hms.push.RemoteMessage
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
|
import java.lang.Exception
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class HuaweiPushNotificationService: HmsMessageService() {
|
class HuaweiPushNotificationService: HmsMessageService() {
|
||||||
|
|
||||||
|
init {
|
||||||
|
Log.d("pnh", "init Huawei Service")
|
||||||
|
}
|
||||||
|
|
||||||
@Inject lateinit var pushManager: PushManager
|
@Inject lateinit var pushManager: PushManager
|
||||||
@Inject lateinit var pushHandler: PushHandler
|
@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?) {
|
override fun onNewToken(token: String?, bundle: Bundle?) {
|
||||||
Log.d("Loki", "New HCM token: $token.")
|
Log.d("pnh", "New HCM token: $token.")
|
||||||
pushManager.refresh(true)
|
pushManager.refresh(true)
|
||||||
}
|
}
|
||||||
override fun onMessageReceived(message: RemoteMessage?) {
|
override fun onMessageReceived(message: RemoteMessage?) {
|
||||||
|
Log.d("pnh", "onMessageReceived: $message.")
|
||||||
pushHandler.onPush(message?.dataOfMap)
|
pushHandler.onPush(message?.dataOfMap)
|
||||||
}
|
}
|
||||||
override fun onDeletedMessages() {
|
override fun onDeletedMessages() {
|
||||||
|
@ -78,6 +78,16 @@
|
|||||||
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=107146885">
|
||||||
|
</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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user