diff --git a/android/build.gradle b/android/build.gradle index c750e6d4..f0033873 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,14 +1,29 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + + ext.versions = [ + 'java' : JavaVersion.VERSION_1_8, + 'androidGradlePlugin': '4.1.3', + 'googleServices' : '4.3.4', + 'compileSdk' : 31, + 'buildTools' : '30.0.2', + 'minSdk' : 23, + 'targetSdk' : 30, + 'firebase' : '19.0.+', + 'voiceAndroid' : '6.0.0', + 'audioSwitch' : '1.1.2', + 'androidxLifecycle' : '2.2.0', + ] + repositories { google() jcenter() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' - classpath 'com.google.gms:google-services:4.3.4' + classpath "com.android.tools.build:gradle:${versions.androidGradlePlugin}" + classpath "com.google.gms:google-services:${versions.googleServices}" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -24,22 +39,16 @@ allprojects { apply plugin: 'com.android.library' -def DEFAULT_MIN_SDK_VERSION = 23 -def DEFAULT_COMPILE_SDK_VERSION = 30 -def DEFAULT_BUILD_TOOLS_VERSION = "29.0.3" -def DEFAULT_TARGET_SDK_VERSION = 29 -def DEFAULT_SUPPORT_LIB_VERSION = "29.0.3" - android { - compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION - buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION + compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : versions.compileSdk + buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : versions.buildTools compileOptions { - sourceCompatibility 1.8 - targetCompatibility 1.8 + sourceCompatibility versions.java + targetCompatibility versions.java } defaultConfig { - minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : DEFAULT_MIN_SDK_VERSION - targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION + minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : versions.minSdk + targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : versions.targetSdk versionCode 1 versionName "1.0" vectorDrawables.useSupportLibrary = true @@ -53,14 +62,11 @@ android { } dependencies { - def supportLibVersion = rootProject.hasProperty('supportLibVersion') ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIB_VERSION - implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.twilio:audioswitch:1.1.2' - implementation 'com.twilio:voice-android:5.4.2' - implementation "com.android.support:appcompat-v7:$supportLibVersion" - implementation 'com.facebook.react:react-native:+' - implementation 'com.google.firebase:firebase-messaging:19.0.+' - implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - testImplementation 'junit:junit:4.12' + implementation "com.twilio:audioswitch:${versions.audioSwitch}" + implementation "com.twilio:voice-android:${versions.voiceAndroid}" + implementation "com.facebook.react:react-native:+" + implementation "com.google.firebase:firebase-messaging:${versions.firebase}" + implementation "androidx.lifecycle:lifecycle-extensions:${versions.androidxLifecycle}" + testImplementation "junit:junit:4.12" } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index f6405f2b..a24470fe 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/android/src/main/java/com/hoxfon/react/RNTwilioVoice/CallNotificationManager.java b/android/src/main/java/com/hoxfon/react/RNTwilioVoice/CallNotificationManager.java index 0e5a3951..44ed14bc 100644 --- a/android/src/main/java/com/hoxfon/react/RNTwilioVoice/CallNotificationManager.java +++ b/android/src/main/java/com/hoxfon/react/RNTwilioVoice/CallNotificationManager.java @@ -81,7 +81,7 @@ public void createMissedCallNotification(ReactApplicationContext context, String context, 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT ); PendingIntent clearMissedCallsCountPendingIntent = PendingIntent.getBroadcast( @@ -155,7 +155,7 @@ public void createHangupNotification(ReactApplicationContext context, String cal context, 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT ); PendingIntent hangupPendingIntent = PendingIntent.getBroadcast( @@ -163,7 +163,7 @@ public void createHangupNotification(ReactApplicationContext context, String cal 0, new Intent(Constants.ACTION_HANGUP_CALL) .putExtra(Constants.INCOMING_CALL_NOTIFICATION_ID, Constants.HANGUP_NOTIFICATION_ID), - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT ); Bundle extras = new Bundle(); diff --git a/android/src/main/java/com/hoxfon/react/RNTwilioVoice/SoundPoolManager.java b/android/src/main/java/com/hoxfon/react/RNTwilioVoice/SoundPoolManager.java index b0cefae9..b79852db 100644 --- a/android/src/main/java/com/hoxfon/react/RNTwilioVoice/SoundPoolManager.java +++ b/android/src/main/java/com/hoxfon/react/RNTwilioVoice/SoundPoolManager.java @@ -2,7 +2,6 @@ import android.content.Context; import android.media.AudioAttributes; -import android.media.AudioManager; import android.media.Ringtone; import android.media.RingtoneManager; import android.net.Uri; diff --git a/android/src/main/java/com/hoxfon/react/RNTwilioVoice/TwilioVoiceModule.java b/android/src/main/java/com/hoxfon/react/RNTwilioVoice/TwilioVoiceModule.java index cab0d85d..7874a1ca 100644 --- a/android/src/main/java/com/hoxfon/react/RNTwilioVoice/TwilioVoiceModule.java +++ b/android/src/main/java/com/hoxfon/react/RNTwilioVoice/TwilioVoiceModule.java @@ -10,7 +10,6 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.media.AudioManager; -import android.os.Build; import androidx.annotation.NonNull; import androidx.core.app.ActivityCompat; @@ -37,10 +36,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; -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.audioswitch.AudioDevice; import com.twilio.audioswitch.AudioSwitch; @@ -693,22 +689,18 @@ public void unregister(Promise promise) { private void unregisterForCallInvites() { FirebaseInstanceId.getInstance().getInstanceId() - .addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - if (!task.isSuccessful()) { - Log.w(TAG, "FCM unregistration failed", task.getException()); - return; - } - - // Get new Instance ID token - String fcmToken = task.getResult().getToken(); - if (fcmToken != null) { - if (BuildConfig.DEBUG) { - Log.d(TAG, "Unregistering with FCM"); - } - Voice.unregister(accessToken, Voice.RegistrationChannel.FCM, fcmToken, unregistrationListener); + .addOnCompleteListener(task -> { + if (!task.isSuccessful()) { + Log.w(TAG, "FCM unregistration failed", task.getException()); + return; + } + // Get new Instance ID token + String fcmToken = task.getResult().getToken(); + if (fcmToken != null) { + if (BuildConfig.DEBUG) { + Log.d(TAG, "Unregistering with FCM"); } + Voice.unregister(accessToken, Voice.RegistrationChannel.FCM, fcmToken, unregistrationListener); } }); }