Skip to content

Commit

Permalink
update: Android firebase-messaging to 17.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziomoscon committed Oct 23, 2020
1 parent 756d256 commit 68b4d93
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 70 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ dependencies {
compile 'com.twilio:voice-android:2.0.7'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.facebook.react:react-native:+'
compile 'com.google.firebase:firebase-messaging:17.+'
compile 'com.google.firebase:firebase-messaging:17.3.4'
testCompile 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.media.AudioManager;
import android.os.Build;

import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
Expand All @@ -38,8 +39,10 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import com.google.firebase.FirebaseApp;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
import com.twilio.voice.Call;
import com.twilio.voice.CallException;
import com.twilio.voice.CallInvite;
Expand Down Expand Up @@ -494,15 +497,16 @@ public void initWithAccessToken(final String accessToken, Promise promise) {
if (accessToken.equals("")) {
promise.reject(new JSApplicationIllegalArgumentException("Invalid access token"));
return;
}
}

if(!checkPermissionForMicrophone()) {
promise.reject(new AssertionException("Can't init without microphone permission"));
}
return;
}

TwilioVoiceModule.this.accessToken = accessToken;
if (BuildConfig.DEBUG) {
Log.d(TAG, "initWithAccessToken ACTION_FCM_TOKEN");
Log.d(TAG, "initWithAccessToken");
}
registerForCallInvites();
WritableMap params = Arguments.createMap();
Expand Down Expand Up @@ -533,20 +537,28 @@ private void clearIncomingNotification(CallInvite callInvite) {
* If a valid google-services.json has not been provided or the FirebaseInstanceId has not been
* initialized the fcmToken will be null.
*
* In the case where the FirebaseInstanceId has not yet been initialized the
* VoiceFirebaseInstanceIDService.onTokenRefresh should result in a LocalBroadcast to this
* activity which will attempt registerForCallInvites again.
*
*/
private void registerForCallInvites() {
FirebaseApp.initializeApp(getReactApplicationContext());
final String fcmToken = FirebaseInstanceId.getInstance().getToken();
if (fcmToken != null) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Registering with FCM");
}
Voice.register(getReactApplicationContext(), accessToken, Voice.RegistrationChannel.FCM, fcmToken, registrationListener);
}
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "getInstanceId failed", task.getException());
return;
}

// Get new Instance ID token
String fcmToken = task.getResult().getToken();
if (fcmToken != null) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Registering with FCM");
}
Voice.register(getReactApplicationContext(), accessToken, Voice.RegistrationChannel.FCM, fcmToken, registrationListener);
}
}
});

}

@ReactMethod
Expand Down Expand Up @@ -778,14 +790,15 @@ private boolean checkPermissionForMicrophone() {
}

private void requestPermissionForMicrophone() {
if (getCurrentActivity() != null) {
if (ActivityCompat.shouldShowRequestPermissionRationale(getCurrentActivity(), Manifest.permission.RECORD_AUDIO)) {
// Snackbar.make(coordinatorLayout,
// "Microphone permissions needed. Please allow in your application settings.",
// SNACKBAR_DURATION).show();
} else {
ActivityCompat.requestPermissions(getCurrentActivity(), new String[]{Manifest.permission.RECORD_AUDIO}, MIC_PERMISSION_REQUEST_CODE);
}
if (getCurrentActivity() == null) {
return;
}
if (ActivityCompat.shouldShowRequestPermissionRationale(getCurrentActivity(), Manifest.permission.RECORD_AUDIO)) {
// Snackbar.make(coordinatorLayout,
// "Microphone permissions needed. Please allow in your application settings.",
// SNACKBAR_DURATION).show();
} else {
ActivityCompat.requestPermissions(getCurrentActivity(), new String[]{Manifest.permission.RECORD_AUDIO}, MIC_PERMISSION_REQUEST_CODE);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import android.app.ActivityManager;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
Expand All @@ -28,6 +27,7 @@
import java.util.Random;

import static com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule.TAG;
import static com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule.ACTION_FCM_TOKEN;
import static com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule.ACTION_INCOMING_CALL;
import static com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule.INCOMING_CALL_INVITE;
import static com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule.INCOMING_CALL_NOTIFICATION_ID;
Expand All @@ -43,6 +43,15 @@ public void onCreate() {
callNotificationManager = new CallNotificationManager();
}

@Override
public void onNewToken(String token) {
Log.d(TAG, "Refreshed token: " + token);

// Notify Activity of FCM token
Intent intent = new Intent(ACTION_FCM_TOKEN);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

/**
* Called when message is received.
*
Expand Down

0 comments on commit 68b4d93

Please sign in to comment.