mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-22 16:07:30 +00:00
Fix Huawei push notifications
This commit is contained in:
parent
cc6f880665
commit
a27f81db30
@ -25,6 +25,8 @@ class HuaweiPushManager @Inject constructor(
|
||||
|
||||
@Synchronized
|
||||
override fun refresh(force: Boolean) {
|
||||
Log.d(TAG, "refresh() called with: force = $force")
|
||||
|
||||
val huaweiPushInstanceIdJob = huaweiPushInstanceIdJob
|
||||
|
||||
huaweiPushInstanceIdJob?.apply {
|
||||
@ -35,9 +37,12 @@ class HuaweiPushManager @Inject constructor(
|
||||
val tokenScope = "HCM"
|
||||
val hmsInstanceId = HmsInstanceId.getInstance(context)
|
||||
|
||||
genericPushManager.refresh(TextSecurePreferences.getFCMToken(context), force)
|
||||
Log.d(TAG, "hmsInstanceId: $hmsInstanceId")
|
||||
|
||||
// genericPushManager.refresh(TextSecurePreferences.getFCMToken(context), force)
|
||||
|
||||
MainScope().launch(Dispatchers.IO) {
|
||||
Log.d(TAG, "hmInstanceId getting token...")
|
||||
val token = hmsInstanceId.getToken(appId, tokenScope)
|
||||
Log.d(TAG, "refresh() hmsInstanceId => huawei token: $token")
|
||||
//
|
||||
|
@ -5,52 +5,63 @@ 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.Base64
|
||||
import org.session.libsignal.utilities.Log
|
||||
import java.lang.Exception
|
||||
import javax.inject.Inject
|
||||
|
||||
private val TAG = HuaweiPushNotificationService::class.java.simpleName
|
||||
|
||||
@AndroidEntryPoint
|
||||
class HuaweiPushNotificationService: HmsMessageService() {
|
||||
|
||||
init {
|
||||
Log.d("pnh", "init Huawei Service")
|
||||
Log.d(TAG, "init Huawei Service")
|
||||
}
|
||||
|
||||
@Inject lateinit var pushManager: PushManager
|
||||
@Inject lateinit var genericPushManager: GenericPushManager
|
||||
@Inject lateinit var pushHandler: PushHandler
|
||||
|
||||
override fun onCreate() {
|
||||
Log.d("pnh", "onCreate Huawei Service")
|
||||
Log.d(TAG, "onCreate Huawei Service")
|
||||
super.onCreate()
|
||||
}
|
||||
|
||||
override fun onMessageDelivered(p0: String?, p1: Exception?) {
|
||||
Log.d("pnh", "onMessageDelivered")
|
||||
super.onMessageDelivered(p0, p1)
|
||||
override fun onMessageReceived(message: RemoteMessage?) {
|
||||
Log.d(TAG, "onMessageReceived: $message.")
|
||||
pushHandler.onPush(message?.data?.let(Base64::decode))
|
||||
}
|
||||
|
||||
override fun onMessageSent(p0: String?) {
|
||||
Log.d("pnh", "onMessageSent")
|
||||
Log.d(TAG, "onMessageSent() called with: p0 = $p0")
|
||||
super.onMessageSent(p0)
|
||||
}
|
||||
|
||||
override fun onSendError(p0: String?, p1: Exception?) {
|
||||
Log.d(TAG, "onSendError() called with: p0 = $p0, p1 = $p1")
|
||||
super.onSendError(p0, p1)
|
||||
}
|
||||
|
||||
override fun onMessageDelivered(p0: String?, p1: Exception?) {
|
||||
Log.d(TAG, "onMessageDelivered")
|
||||
super.onMessageDelivered(p0, p1)
|
||||
}
|
||||
|
||||
|
||||
override fun onNewToken(p0: String?) {
|
||||
Log.d("pnh", "onNewToken")
|
||||
Log.d(TAG, "onNewToken")
|
||||
super.onNewToken(p0)
|
||||
}
|
||||
|
||||
override fun onNewToken(token: String?, bundle: Bundle?) {
|
||||
Log.d("pnh", "New HCM token: $token.")
|
||||
|
||||
if (token == TextSecurePreferences.getFCMToken(this)) return
|
||||
Log.d(TAG, "New HCM token: $token.")
|
||||
|
||||
TextSecurePreferences.setFCMToken(this, token)
|
||||
pushManager.refresh(true)
|
||||
}
|
||||
override fun onMessageReceived(message: RemoteMessage?) {
|
||||
Log.d("pnh", "onMessageReceived: $message.")
|
||||
pushHandler.onPush(message?.dataOfMap)
|
||||
|
||||
genericPushManager.refresh(token, true)
|
||||
}
|
||||
|
||||
override fun onDeletedMessages() {
|
||||
pushManager.refresh(true)
|
||||
}
|
||||
|
@ -506,10 +506,10 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
||||
firebaseInstanceIdJob.cancel(null);
|
||||
}
|
||||
String displayName = TextSecurePreferences.getProfileName(this);
|
||||
boolean isUsingFCM = TextSecurePreferences.isUsingFCM(this);
|
||||
boolean isUsingFCM = TextSecurePreferences.isPushEnabled(this);
|
||||
TextSecurePreferences.clearAll(this);
|
||||
if (isMigratingToV2KeyPair) {
|
||||
TextSecurePreferences.setIsUsingFCM(this, isUsingFCM);
|
||||
TextSecurePreferences.setPushEnabled(this, isUsingFCM);
|
||||
TextSecurePreferences.setProfileName(this, displayName);
|
||||
}
|
||||
getSharedPreferences(PREFERENCES_NAME, 0).edit().clear().commit();
|
||||
|
@ -12,7 +12,7 @@ class FcmTokenManager @Inject constructor(
|
||||
) {
|
||||
private val expiryManager = ExpiryManager(context)
|
||||
|
||||
val isUsingFCM get() = TextSecurePreferences.isUsingFCM(context)
|
||||
val isUsingFCM get() = TextSecurePreferences.isPushEnabled(context)
|
||||
|
||||
var fcmToken
|
||||
get() = TextSecurePreferences.getFCMToken(context)
|
||||
|
@ -33,7 +33,7 @@ class PushHandler @Inject constructor(@ApplicationContext val context: Context)
|
||||
onPush(dataMap?.asByteArray())
|
||||
}
|
||||
|
||||
private fun onPush(data: ByteArray?) {
|
||||
fun onPush(data: ByteArray?) {
|
||||
if (data == null) {
|
||||
onPush()
|
||||
return
|
||||
|
@ -165,7 +165,7 @@ class PNModeActivity : BaseActionBarActivity() {
|
||||
return
|
||||
}
|
||||
|
||||
TextSecurePreferences.setIsUsingFCM(this, (selectedOptionView == binding.fcmOptionView))
|
||||
TextSecurePreferences.setPushEnabled(this, (selectedOptionView == binding.fcmOptionView))
|
||||
val application = ApplicationContext.getInstance(this)
|
||||
application.startPollingIfNeeded()
|
||||
pushManager.refresh(true)
|
||||
|
@ -45,10 +45,10 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||
|
||||
// Set up FCM toggle
|
||||
String fcmKey = "pref_key_use_fcm";
|
||||
((SwitchPreferenceCompat)findPreference(fcmKey)).setChecked(TextSecurePreferences.isUsingFCM(getContext()));
|
||||
((SwitchPreferenceCompat)findPreference(fcmKey)).setChecked(TextSecurePreferences.isPushEnabled(getContext()));
|
||||
this.findPreference(fcmKey)
|
||||
.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
TextSecurePreferences.setIsUsingFCM(getContext(), (boolean) newValue);
|
||||
TextSecurePreferences.setPushEnabled(getContext(), (boolean) newValue);
|
||||
pushManager.refresh(true);
|
||||
return true;
|
||||
});
|
||||
|
@ -27,7 +27,9 @@ class FirebasePushManager @Inject constructor(
|
||||
|
||||
firebaseInstanceIdJob = getFcmInstanceId { task ->
|
||||
when {
|
||||
task.isSuccessful -> try { task.result?.token?.let { genericPushManager.refresh(it, force).get() } } catch(e: Exception) { Log.e(TAG, "refresh() failed", e) }
|
||||
task.isSuccessful -> try { task.result?.token?.let {
|
||||
genericPushManager.refresh(it, force).get()
|
||||
} } catch(e: Exception) { Log.e(TAG, "refresh() failed", e) }
|
||||
else -> Log.w(TAG, "getFcmInstanceId failed." + task.exception)
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ object PushManagerV1 {
|
||||
|
||||
fun register(
|
||||
device: Device,
|
||||
isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context),
|
||||
isUsingFCM: Boolean = TextSecurePreferences.isPushEnabled(context),
|
||||
token: String? = TextSecurePreferences.getFCMToken(context),
|
||||
publicKey: String? = TextSecurePreferences.getLocalNumber(context),
|
||||
legacyGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
|
||||
@ -94,7 +94,7 @@ object PushManagerV1 {
|
||||
|
||||
sendOnionRequest(request) success {
|
||||
when (it.code) {
|
||||
null, 0 -> throw Exception("error: ${it.message}.")
|
||||
null, 0 -> Log.d(TAG, "error: ${it.message}.")
|
||||
else -> Log.d(TAG, "unregisterV1 success")
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,7 @@ object PushManagerV1 {
|
||||
|
||||
fun subscribeGroup(
|
||||
closedGroupPublicKey: String,
|
||||
isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context),
|
||||
isUsingFCM: Boolean = TextSecurePreferences.isPushEnabled(context),
|
||||
publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!!
|
||||
) = if (isUsingFCM) {
|
||||
performGroupOperation("subscribe_closed_group", closedGroupPublicKey, publicKey)
|
||||
@ -113,7 +113,7 @@ object PushManagerV1 {
|
||||
|
||||
fun unsubscribeGroup(
|
||||
closedGroupPublicKey: String,
|
||||
isUsingFCM: Boolean = TextSecurePreferences.isUsingFCM(context),
|
||||
isUsingFCM: Boolean = TextSecurePreferences.isPushEnabled(context),
|
||||
publicKey: String = MessagingModuleConfiguration.shared.storage.getUserPublicKey()!!
|
||||
) = if (isUsingFCM) {
|
||||
performGroupOperation("unsubscribe_closed_group", closedGroupPublicKey, publicKey)
|
||||
|
@ -37,12 +37,12 @@ interface TextSecurePreferences {
|
||||
fun setLastConfigurationSyncTime(value: Long)
|
||||
fun getConfigurationMessageSynced(): Boolean
|
||||
fun setConfigurationMessageSynced(value: Boolean)
|
||||
fun isUsingFCM(): Boolean
|
||||
fun setIsUsingFCM(value: Boolean)
|
||||
fun getFCMToken(): String?
|
||||
fun setFCMToken(value: String)
|
||||
fun getLastFCMUploadTime(): Long
|
||||
fun setLastFCMUploadTime(value: Long)
|
||||
fun isPushEnabled(): Boolean
|
||||
fun setPushEnabled(value: Boolean)
|
||||
fun getPushToken(): String?
|
||||
fun setPushToken(value: String)
|
||||
fun getPushRegisterTime(): Long
|
||||
fun setPushRegisterTime(value: Long)
|
||||
fun isScreenLockEnabled(): Boolean
|
||||
fun setScreenLockEnabled(value: Boolean)
|
||||
fun getScreenLockTimeout(): Long
|
||||
@ -251,9 +251,9 @@ interface TextSecurePreferences {
|
||||
const val LINK_PREVIEWS = "pref_link_previews"
|
||||
const val GIF_METADATA_WARNING = "has_seen_gif_metadata_warning"
|
||||
const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
|
||||
const val IS_USING_FCM = "pref_is_using_fcm"
|
||||
const val IS_PUSH_ENABLED = "pref_is_using_fcm"
|
||||
const val FCM_TOKEN = "pref_fcm_token_2"
|
||||
const val LAST_FCM_TOKEN_UPLOAD_TIME = "pref_last_fcm_token_upload_time_2"
|
||||
const val PUSH_REGISTER_TIME = "pref_last_fcm_token_upload_time_2"
|
||||
const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time"
|
||||
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
|
||||
const val LAST_PROFILE_UPDATE_TIME = "pref_last_profile_update_time"
|
||||
@ -309,13 +309,13 @@ interface TextSecurePreferences {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isUsingFCM(context: Context): Boolean {
|
||||
return getBooleanPreference(context, IS_USING_FCM, false)
|
||||
fun isPushEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, IS_PUSH_ENABLED, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setIsUsingFCM(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, IS_USING_FCM, value)
|
||||
fun setPushEnabled(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, IS_PUSH_ENABLED, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@ -329,11 +329,11 @@ interface TextSecurePreferences {
|
||||
}
|
||||
|
||||
fun getLastFCMUploadTime(context: Context): Long {
|
||||
return getLongPreference(context, LAST_FCM_TOKEN_UPLOAD_TIME, 0)
|
||||
return getLongPreference(context, PUSH_REGISTER_TIME, 0)
|
||||
}
|
||||
|
||||
fun setLastFCMUploadTime(context: Context, value: Long) {
|
||||
setLongPreference(context, LAST_FCM_TOKEN_UPLOAD_TIME, value)
|
||||
setLongPreference(context, PUSH_REGISTER_TIME, value)
|
||||
}
|
||||
|
||||
// endregion
|
||||
@ -1032,28 +1032,28 @@ class AppTextSecurePreferences @Inject constructor(
|
||||
TextSecurePreferences._events.tryEmit(TextSecurePreferences.CONFIGURATION_SYNCED)
|
||||
}
|
||||
|
||||
override fun isUsingFCM(): Boolean {
|
||||
return getBooleanPreference(TextSecurePreferences.IS_USING_FCM, false)
|
||||
override fun isPushEnabled(): Boolean {
|
||||
return getBooleanPreference(TextSecurePreferences.IS_PUSH_ENABLED, false)
|
||||
}
|
||||
|
||||
override fun setIsUsingFCM(value: Boolean) {
|
||||
setBooleanPreference(TextSecurePreferences.IS_USING_FCM, value)
|
||||
override fun setPushEnabled(value: Boolean) {
|
||||
setBooleanPreference(TextSecurePreferences.IS_PUSH_ENABLED, value)
|
||||
}
|
||||
|
||||
override fun getFCMToken(): String? {
|
||||
override fun getPushToken(): String? {
|
||||
return getStringPreference(TextSecurePreferences.FCM_TOKEN, "")
|
||||
}
|
||||
|
||||
override fun setFCMToken(value: String) {
|
||||
override fun setPushToken(value: String) {
|
||||
setStringPreference(TextSecurePreferences.FCM_TOKEN, value)
|
||||
}
|
||||
|
||||
override fun getLastFCMUploadTime(): Long {
|
||||
return getLongPreference(TextSecurePreferences.LAST_FCM_TOKEN_UPLOAD_TIME, 0)
|
||||
override fun getPushRegisterTime(): Long {
|
||||
return getLongPreference(TextSecurePreferences.PUSH_REGISTER_TIME, 0)
|
||||
}
|
||||
|
||||
override fun setLastFCMUploadTime(value: Long) {
|
||||
setLongPreference(TextSecurePreferences.LAST_FCM_TOKEN_UPLOAD_TIME, value)
|
||||
override fun setPushRegisterTime(value: Long) {
|
||||
setLongPreference(TextSecurePreferences.PUSH_REGISTER_TIME, value)
|
||||
}
|
||||
|
||||
override fun isScreenLockEnabled(): Boolean {
|
||||
|
Loading…
x
Reference in New Issue
Block a user