Commit 6b599ca0 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Farewell GCM

parent 5a678af5
...@@ -26,6 +26,13 @@ android { ...@@ -26,6 +26,13 @@ android {
keyAlias System.getenv("KEY_ALIAS") keyAlias System.getenv("KEY_ALIAS")
keyPassword System.getenv("KEY_PASSWORD") keyPassword System.getenv("KEY_PASSWORD")
} }
debug {
storeFile project.rootProject.file('debug.keystore').getCanonicalFile()
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
} }
buildTypes { buildTypes {
...@@ -40,6 +47,7 @@ android { ...@@ -40,6 +47,7 @@ android {
debug { debug {
buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"' buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"'
buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.63.0"' buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.63.0"'
signingConfig signingConfigs.debug
applicationIdSuffix ".dev" applicationIdSuffix ".dev"
} }
} }
...@@ -73,7 +81,7 @@ dependencies { ...@@ -73,7 +81,7 @@ dependencies {
kapt libraries.daggerProcessor kapt libraries.daggerProcessor
kapt libraries.daggerAndroidApt kapt libraries.daggerAndroidApt
implementation libraries.playServicesGcm implementation libraries.fcm
implementation libraries.room implementation libraries.room
kapt libraries.roomProcessor kapt libraries.roomProcessor
......
...@@ -3,17 +3,9 @@ ...@@ -3,17 +3,9 @@
package="chat.rocket.android"> package="chat.rocket.android">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<application <application
android:name=".app.RocketChatApplication" android:name=".app.RocketChatApplication"
android:allowBackup="true" android:allowBackup="true"
...@@ -90,18 +82,6 @@ ...@@ -90,18 +82,6 @@
android:name=".settings.about.ui.AboutActivity" android:name=".settings.about.ui.AboutActivity"
android:theme="@style/AppTheme" /> android:theme="@style/AppTheme" />
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<receiver <receiver
android:name=".push.DirectReplyReceiver" android:name=".push.DirectReplyReceiver"
android:enabled="true" android:enabled="true"
...@@ -118,13 +98,13 @@ ...@@ -118,13 +98,13 @@
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter> </intent-filter>
</service> </service>
<service
android:name=".push.GcmListenerService" <service android:name=".push.FirebaseMessagingService">
android:exported="false">
<intent-filter> <intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter> </intent-filter>
</service> </service>
<service <service
android:name=".chatroom.service.MessageService" android:name=".chatroom.service.MessageService"
android:exported="true" android:exported="true"
......
...@@ -2,10 +2,10 @@ package chat.rocket.android.dagger.module ...@@ -2,10 +2,10 @@ package chat.rocket.android.dagger.module
import chat.rocket.android.chatroom.di.MessageServiceProvider import chat.rocket.android.chatroom.di.MessageServiceProvider
import chat.rocket.android.chatroom.service.MessageService import chat.rocket.android.chatroom.service.MessageService
import chat.rocket.android.push.FirebaseMessagingService
import chat.rocket.android.push.FirebaseTokenService import chat.rocket.android.push.FirebaseTokenService
import chat.rocket.android.push.GcmListenerService import chat.rocket.android.push.di.FirebaseMessagingServiceProvider
import chat.rocket.android.push.di.FirebaseTokenServiceProvider import chat.rocket.android.push.di.FirebaseTokenServiceProvider
import chat.rocket.android.push.di.GcmListenerServiceProvider
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
...@@ -14,8 +14,8 @@ import dagger.android.ContributesAndroidInjector ...@@ -14,8 +14,8 @@ import dagger.android.ContributesAndroidInjector
@ContributesAndroidInjector(modules = [FirebaseTokenServiceProvider::class]) @ContributesAndroidInjector(modules = [FirebaseTokenServiceProvider::class])
abstract fun bindFirebaseTokenService(): FirebaseTokenService abstract fun bindFirebaseTokenService(): FirebaseTokenService
@ContributesAndroidInjector(modules = [GcmListenerServiceProvider::class]) @ContributesAndroidInjector(modules = [FirebaseMessagingServiceProvider::class])
abstract fun bindGcmListenerService(): GcmListenerService abstract fun bindGcmListenerService(): FirebaseMessagingService
@ContributesAndroidInjector(modules = [MessageServiceProvider::class]) @ContributesAndroidInjector(modules = [MessageServiceProvider::class])
abstract fun bindMessageService(): MessageService abstract fun bindMessageService(): MessageService
......
package chat.rocket.android.main.ui package chat.rocket.android.main.ui
import DrawableHelper
import android.app.Activity import android.app.Activity
import android.app.AlertDialog import android.app.AlertDialog
import android.os.Bundle import android.os.Bundle
...@@ -11,8 +12,8 @@ import android.view.MenuItem ...@@ -11,8 +12,8 @@ import android.view.MenuItem
import android.view.View import android.view.View
import chat.rocket.android.BuildConfig import chat.rocket.android.BuildConfig
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.main.adapter.Selector
import chat.rocket.android.main.adapter.AccountsAdapter import chat.rocket.android.main.adapter.AccountsAdapter
import chat.rocket.android.main.adapter.Selector
import chat.rocket.android.main.presentation.MainPresenter import chat.rocket.android.main.presentation.MainPresenter
import chat.rocket.android.main.presentation.MainView import chat.rocket.android.main.presentation.MainView
import chat.rocket.android.main.viewmodel.NavHeaderViewModel import chat.rocket.android.main.viewmodel.NavHeaderViewModel
...@@ -22,8 +23,8 @@ import chat.rocket.android.util.extensions.fadeOut ...@@ -22,8 +23,8 @@ import chat.rocket.android.util.extensions.fadeOut
import chat.rocket.android.util.extensions.rotateBy import chat.rocket.android.util.extensions.rotateBy
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.common.model.UserStatus import chat.rocket.common.model.UserStatus
import com.google.android.gms.gcm.GoogleCloudMessaging import com.google.firebase.iid.FirebaseInstanceId
import com.google.android.gms.iid.InstanceID import com.google.firebase.messaging.FirebaseMessaging
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector import dagger.android.DispatchingAndroidInjector
...@@ -52,8 +53,8 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp ...@@ -52,8 +53,8 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp
launch(CommonPool) { launch(CommonPool) {
try { try {
val token = InstanceID.getInstance(this@MainActivity).getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null) val token = FirebaseInstanceId.getInstance().token
Timber.d("GCM token: $token") Timber.d("FCM token: $token")
presenter.refreshToken(token) presenter.refreshToken(token)
} catch (ex: Exception) { } catch (ex: Exception) {
Timber.d(ex, "Missing play services...") Timber.d(ex, "Missing play services...")
...@@ -135,7 +136,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp ...@@ -135,7 +136,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp
} }
override fun invalidateToken(token: String) { override fun invalidateToken(token: String) {
InstanceID.getInstance(this).deleteToken(token, GoogleCloudMessaging.INSTANCE_ID_SCOPE) FirebaseInstanceId.getInstance().deleteToken(token, FirebaseMessaging.INSTANCE_ID_SCOPE)
} }
private fun setupAccountsList(header: View, accounts: List<Account>) { private fun setupAccountsList(header: View, accounts: List<Account>) {
......
package chat.rocket.android.push package chat.rocket.android.push
import android.os.Bundle import androidx.core.os.bundleOf
import com.google.android.gms.gcm.GcmListenerService import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
import javax.inject.Inject import javax.inject.Inject
class GcmListenerService : GcmListenerService() { class FirebaseMessagingService : FirebaseMessagingService() {
@Inject @Inject
lateinit var pushManager: PushManager lateinit var pushManager: PushManager
...@@ -15,9 +16,9 @@ class GcmListenerService : GcmListenerService() { ...@@ -15,9 +16,9 @@ class GcmListenerService : GcmListenerService() {
AndroidInjection.inject(this) AndroidInjection.inject(this)
} }
override fun onMessageReceived(from: String?, data: Bundle?) { override fun onMessageReceived(message: RemoteMessage) {
data?.let { message.data?.let {
pushManager.handle(data) pushManager.handle(bundleOf(*(it.map { Pair(it.key, it.value) }).toTypedArray()))
} }
} }
} }
\ No newline at end of file
package chat.rocket.android.push package chat.rocket.android.push
import chat.rocket.android.R
import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.GetCurrentServerInteractor import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.retryIO import chat.rocket.android.util.retryIO
import chat.rocket.common.RocketChatException import chat.rocket.common.RocketChatException
import chat.rocket.core.internal.rest.registerPushToken import chat.rocket.core.internal.rest.registerPushToken
import com.google.android.gms.gcm.GoogleCloudMessaging import com.google.firebase.iid.FirebaseInstanceId
import com.google.android.gms.iid.InstanceID
import com.google.firebase.iid.FirebaseInstanceIdService import com.google.firebase.iid.FirebaseInstanceIdService
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.experimental.launch
...@@ -31,21 +29,18 @@ class FirebaseTokenService : FirebaseInstanceIdService() { ...@@ -31,21 +29,18 @@ class FirebaseTokenService : FirebaseInstanceIdService() {
} }
override fun onTokenRefresh() { override fun onTokenRefresh() {
//TODO: We need to use the Cordova Project gcm_sender_id since it's the one configured on RC
// default push gateway. We should register this project's own project sender id into it.
try { try {
val gcmToken = InstanceID.getInstance(this) val fcmToken = FirebaseInstanceId.getInstance().token
.getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null)
val currentServer = getCurrentServerInteractor.get() val currentServer = getCurrentServerInteractor.get()
val client = currentServer?.let { factory.create(currentServer) } val client = currentServer?.let { factory.create(currentServer) }
gcmToken?.let { fcmToken?.let {
localRepository.save(LocalRepository.KEY_PUSH_TOKEN, gcmToken) localRepository.save(LocalRepository.KEY_PUSH_TOKEN, fcmToken)
client?.let { client?.let {
launch { launch {
try { try {
Timber.d("Registering push token: $gcmToken for ${client.url}") Timber.d("Registering push token: $fcmToken for ${client.url}")
retryIO("register push token") { client.registerPushToken(gcmToken) } retryIO("register push token") { client.registerPushToken(fcmToken) }
} catch (ex: RocketChatException) { } catch (ex: RocketChatException) {
Timber.e(ex, "Error registering push token") Timber.e(ex, "Error registering push token")
} }
...@@ -53,7 +48,7 @@ class FirebaseTokenService : FirebaseInstanceIdService() { ...@@ -53,7 +48,7 @@ class FirebaseTokenService : FirebaseInstanceIdService() {
} }
} }
} catch (ex: Exception) { } catch (ex: Exception) {
Timber.d(ex, "Error refreshing Firebase TOKEN") Timber.e(ex, "Error refreshing Firebase TOKEN")
} }
} }
} }
\ No newline at end of file
package chat.rocket.android.push.di package chat.rocket.android.push.di
import chat.rocket.android.dagger.module.AppModule import chat.rocket.android.dagger.module.AppModule
import chat.rocket.android.push.GcmListenerService import chat.rocket.android.push.FirebaseMessagingService
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
@Module abstract class GcmListenerServiceProvider { @Module abstract class FirebaseMessagingServiceProvider {
@ContributesAndroidInjector(modules = [AppModule::class]) @ContributesAndroidInjector(modules = [AppModule::class])
abstract fun provideGcmListenerService(): GcmListenerService abstract fun provideFirebaseMessagingService(): FirebaseMessagingService
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- This is the Cordova GCM sender id-->
<string name="gcm_sender_id" translatable="false">673693445664</string>
</resources>
\ No newline at end of file
File added
...@@ -15,6 +15,7 @@ ext { ...@@ -15,6 +15,7 @@ ext {
dagger : '2.14.1', dagger : '2.14.1',
exoPlayer : '2.6.0', exoPlayer : '2.6.0',
playServices : '11.8.0', playServices : '11.8.0',
firebase : '15.0.0',
room : '1.0.0', room : '1.0.0',
lifecycle : '1.1.1', lifecycle : '1.1.1',
rxKotlin : '2.2.0', rxKotlin : '2.2.0',
...@@ -58,7 +59,7 @@ ext { ...@@ -58,7 +59,7 @@ ext {
daggerSupport : "com.google.dagger:dagger-android-support:${versions.dagger}", daggerSupport : "com.google.dagger:dagger-android-support:${versions.dagger}",
daggerProcessor : "com.google.dagger:dagger-compiler:${versions.dagger}", daggerProcessor : "com.google.dagger:dagger-compiler:${versions.dagger}",
daggerAndroidApt : "com.google.dagger:dagger-android-processor:${versions.dagger}", daggerAndroidApt : "com.google.dagger:dagger-android-processor:${versions.dagger}",
playServicesGcm : "com.google.android.gms:play-services-gcm:${versions.playServices}", fcm : "com.google.firebase:firebase-messaging:${versions.firebase}",
exoPlayer : "com.google.android.exoplayer:exoplayer:${versions.exoPlayer}", exoPlayer : "com.google.android.exoplayer:exoplayer:${versions.exoPlayer}",
room : "android.arch.persistence.room:runtime:${versions.room}", room : "android.arch.persistence.room:runtime:${versions.room}",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment