diff --git a/app/src/main/java/org/linphone/LinphoneActivity.java b/app/src/main/java/org/linphone/LinphoneActivity.java index e8cfe7842..b28b22018 100644 --- a/app/src/main/java/org/linphone/LinphoneActivity.java +++ b/app/src/main/java/org/linphone/LinphoneActivity.java @@ -117,6 +117,7 @@ import org.linphone.utils.DeviceUtils; import org.linphone.utils.IntentUtils; import org.linphone.utils.LinphoneGenericActivity; import org.linphone.utils.LinphoneUtils; +import org.linphone.utils.PushNotificationUtils; import org.linphone.views.AddressText; import org.linphone.xmlrpc.XmlRpcHelper; import org.linphone.xmlrpc.XmlRpcListenerBase; @@ -1352,10 +1353,8 @@ public class LinphoneActivity extends LinphoneGenericActivity + Compatibility.getAppStandbyBucketNameFromValue(bucket)); } - boolean googlePlayServiceAvailable = DeviceUtils.isGooglePlayServicesAvailable(this); - if (!googlePlayServiceAvailable) { - Log.w( - "[Linphone Activity] Device doesn't have Google Play Services, push notifications won't work !"); + if (!PushNotificationUtils.isAvailable(this)) { + Log.w("[Linphone Activity] Push notifications won't work !"); } IntentUtils.handleIntent(this, getIntent()); diff --git a/app/src/main/java/org/linphone/firebase/FirebasePushHelper.java b/app/src/main/java/org/linphone/firebase/FirebasePushHelper.java index 08567425a..5d7338014 100644 --- a/app/src/main/java/org/linphone/firebase/FirebasePushHelper.java +++ b/app/src/main/java/org/linphone/firebase/FirebasePushHelper.java @@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import android.content.Context; import androidx.annotation.NonNull; +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.firebase.iid.FirebaseInstanceId; @@ -61,4 +63,11 @@ public class FirebasePushHelper implements PushNotificationUtils.PushHelperInter Log.e("[Push Notification] firebase not available."); } } + + @Override + public boolean isAvailable(Context context) { + GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); + int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context); + return resultCode == ConnectionResult.SUCCESS; + } } diff --git a/app/src/main/java/org/linphone/settings/AccountPreferencesFragment.java b/app/src/main/java/org/linphone/settings/AccountPreferencesFragment.java index 67992c29f..753aa85cd 100644 --- a/app/src/main/java/org/linphone/settings/AccountPreferencesFragment.java +++ b/app/src/main/java/org/linphone/settings/AccountPreferencesFragment.java @@ -43,8 +43,8 @@ import org.linphone.core.ProxyConfig; import org.linphone.core.tools.Log; import org.linphone.fragments.FragmentsAvailable; import org.linphone.settings.LinphonePreferences.AccountBuilder; -import org.linphone.utils.DeviceUtils; import org.linphone.utils.LinphoneUtils; +import org.linphone.utils.PushNotificationUtils; public class AccountPreferencesFragment extends PreferenceFragment implements AccountCreatorListener { @@ -484,7 +484,7 @@ public class AccountPreferencesFragment extends PreferenceFragment if (!mIsNewAccount) { pushNotif.setChecked(mPrefs.isPushNotifEnabledForProxy(mN)); } - if (!DeviceUtils.isGooglePlayServicesAvailable(getActivity())) { + if (!PushNotificationUtils.isAvailable(getActivity())) { pushNotif.setLayoutResource(R.layout.hidden); } diff --git a/app/src/main/java/org/linphone/settings/SettingsFragment.java b/app/src/main/java/org/linphone/settings/SettingsFragment.java index 842a56b9e..6c8751085 100644 --- a/app/src/main/java/org/linphone/settings/SettingsFragment.java +++ b/app/src/main/java/org/linphone/settings/SettingsFragment.java @@ -65,6 +65,7 @@ import org.linphone.mediastream.Version; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.utils.DeviceUtils; import org.linphone.utils.FileUtils; +import org.linphone.utils.PushNotificationUtils; import org.linphone.views.LedPreference; public class SettingsFragment extends PreferenceFragment { @@ -1480,7 +1481,7 @@ public class SettingsFragment extends PreferenceFragment { ((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key))) .setChecked(mPrefs.isPushNotificationEnabled()); - if (!DeviceUtils.isGooglePlayServicesAvailable(getActivity())) { + if (!PushNotificationUtils.isAvailable(getActivity())) { findPreference(getString(R.string.pref_push_notification_key)) .setLayoutResource(R.layout.hidden); } diff --git a/app/src/main/java/org/linphone/utils/DeviceUtils.java b/app/src/main/java/org/linphone/utils/DeviceUtils.java index 91e1962d7..b7855ee21 100644 --- a/app/src/main/java/org/linphone/utils/DeviceUtils.java +++ b/app/src/main/java/org/linphone/utils/DeviceUtils.java @@ -34,8 +34,6 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.TextView; import androidx.core.content.ContextCompat; -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GoogleApiAvailability; import java.util.List; import org.linphone.R; import org.linphone.compatibility.Compatibility; @@ -223,10 +221,4 @@ public class DeviceUtils { .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; } - - public static boolean isGooglePlayServicesAvailable(Context context) { - GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); - int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context); - return resultCode == ConnectionResult.SUCCESS; - } } diff --git a/app/src/main/java/org/linphone/utils/PushNotificationUtils.java b/app/src/main/java/org/linphone/utils/PushNotificationUtils.java index 67a465eb3..9ed6551e7 100644 --- a/app/src/main/java/org/linphone/utils/PushNotificationUtils.java +++ b/app/src/main/java/org/linphone/utils/PushNotificationUtils.java @@ -25,8 +25,12 @@ import org.linphone.R; import org.linphone.core.tools.Log; public class PushNotificationUtils { + private static PushHelperInterface mHelper; + public static void init(Context context) { + mHelper = null; String push_type = context.getString(R.string.push_type); + if (push_type.equals("firebase")) { String className = "org.linphone.firebase.FirebasePushHelper"; try { @@ -34,9 +38,8 @@ public class PushNotificationUtils { Class[] types = {}; Constructor constructor = pushHelper.getConstructor(types); Object[] parameters = {}; - PushHelperInterface pushHelperImpl = - (PushHelperInterface) constructor.newInstance(parameters); - pushHelperImpl.init(context); + mHelper = (PushHelperInterface) constructor.newInstance(parameters); + mHelper.init(context); } catch (NoSuchMethodException e) { Log.w("[Push Utils] Couldn't get push helper constructor"); } catch (ClassNotFoundException e) { @@ -49,7 +52,14 @@ public class PushNotificationUtils { } } + public static boolean isAvailable(Context context) { + if (mHelper == null) return false; + return mHelper.isAvailable(context); + } + public interface PushHelperInterface { void init(Context context); + + boolean isAvailable(Context context); } }