Fixed build if google services API not available

This commit is contained in:
Sylvain Berfini 2019-04-03 15:05:14 +02:00
parent b64d62cc4a
commit 1cfdc5c2ff
6 changed files with 29 additions and 18 deletions

View file

@ -117,6 +117,7 @@ import org.linphone.utils.DeviceUtils;
import org.linphone.utils.IntentUtils; import org.linphone.utils.IntentUtils;
import org.linphone.utils.LinphoneGenericActivity; import org.linphone.utils.LinphoneGenericActivity;
import org.linphone.utils.LinphoneUtils; import org.linphone.utils.LinphoneUtils;
import org.linphone.utils.PushNotificationUtils;
import org.linphone.views.AddressText; import org.linphone.views.AddressText;
import org.linphone.xmlrpc.XmlRpcHelper; import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.xmlrpc.XmlRpcListenerBase; import org.linphone.xmlrpc.XmlRpcListenerBase;
@ -1352,10 +1353,8 @@ public class LinphoneActivity extends LinphoneGenericActivity
+ Compatibility.getAppStandbyBucketNameFromValue(bucket)); + Compatibility.getAppStandbyBucketNameFromValue(bucket));
} }
boolean googlePlayServiceAvailable = DeviceUtils.isGooglePlayServicesAvailable(this); if (!PushNotificationUtils.isAvailable(this)) {
if (!googlePlayServiceAvailable) { Log.w("[Linphone Activity] Push notifications won't work !");
Log.w(
"[Linphone Activity] Device doesn't have Google Play Services, push notifications won't work !");
} }
IntentUtils.handleIntent(this, getIntent()); IntentUtils.handleIntent(this, getIntent());

View file

@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull; 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.OnCompleteListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import com.google.firebase.iid.FirebaseInstanceId; import com.google.firebase.iid.FirebaseInstanceId;
@ -61,4 +63,11 @@ public class FirebasePushHelper implements PushNotificationUtils.PushHelperInter
Log.e("[Push Notification] firebase not available."); 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;
}
} }

View file

@ -43,8 +43,8 @@ import org.linphone.core.ProxyConfig;
import org.linphone.core.tools.Log; import org.linphone.core.tools.Log;
import org.linphone.fragments.FragmentsAvailable; import org.linphone.fragments.FragmentsAvailable;
import org.linphone.settings.LinphonePreferences.AccountBuilder; import org.linphone.settings.LinphonePreferences.AccountBuilder;
import org.linphone.utils.DeviceUtils;
import org.linphone.utils.LinphoneUtils; import org.linphone.utils.LinphoneUtils;
import org.linphone.utils.PushNotificationUtils;
public class AccountPreferencesFragment extends PreferenceFragment public class AccountPreferencesFragment extends PreferenceFragment
implements AccountCreatorListener { implements AccountCreatorListener {
@ -484,7 +484,7 @@ public class AccountPreferencesFragment extends PreferenceFragment
if (!mIsNewAccount) { if (!mIsNewAccount) {
pushNotif.setChecked(mPrefs.isPushNotifEnabledForProxy(mN)); pushNotif.setChecked(mPrefs.isPushNotifEnabledForProxy(mN));
} }
if (!DeviceUtils.isGooglePlayServicesAvailable(getActivity())) { if (!PushNotificationUtils.isAvailable(getActivity())) {
pushNotif.setLayoutResource(R.layout.hidden); pushNotif.setLayoutResource(R.layout.hidden);
} }

View file

@ -65,6 +65,7 @@ import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.utils.DeviceUtils; import org.linphone.utils.DeviceUtils;
import org.linphone.utils.FileUtils; import org.linphone.utils.FileUtils;
import org.linphone.utils.PushNotificationUtils;
import org.linphone.views.LedPreference; import org.linphone.views.LedPreference;
public class SettingsFragment extends PreferenceFragment { public class SettingsFragment extends PreferenceFragment {
@ -1480,7 +1481,7 @@ public class SettingsFragment extends PreferenceFragment {
((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key))) ((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key)))
.setChecked(mPrefs.isPushNotificationEnabled()); .setChecked(mPrefs.isPushNotificationEnabled());
if (!DeviceUtils.isGooglePlayServicesAvailable(getActivity())) { if (!PushNotificationUtils.isAvailable(getActivity())) {
findPreference(getString(R.string.pref_push_notification_key)) findPreference(getString(R.string.pref_push_notification_key))
.setLayoutResource(R.layout.hidden); .setLayoutResource(R.layout.hidden);
} }

View file

@ -34,8 +34,6 @@ import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import java.util.List; import java.util.List;
import org.linphone.R; import org.linphone.R;
import org.linphone.compatibility.Compatibility; import org.linphone.compatibility.Compatibility;
@ -223,10 +221,4 @@ public class DeviceUtils {
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0; return list.size() > 0;
} }
public static boolean isGooglePlayServicesAvailable(Context context) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context);
return resultCode == ConnectionResult.SUCCESS;
}
} }

View file

@ -25,8 +25,12 @@ import org.linphone.R;
import org.linphone.core.tools.Log; import org.linphone.core.tools.Log;
public class PushNotificationUtils { public class PushNotificationUtils {
private static PushHelperInterface mHelper;
public static void init(Context context) { public static void init(Context context) {
mHelper = null;
String push_type = context.getString(R.string.push_type); String push_type = context.getString(R.string.push_type);
if (push_type.equals("firebase")) { if (push_type.equals("firebase")) {
String className = "org.linphone.firebase.FirebasePushHelper"; String className = "org.linphone.firebase.FirebasePushHelper";
try { try {
@ -34,9 +38,8 @@ public class PushNotificationUtils {
Class[] types = {}; Class[] types = {};
Constructor constructor = pushHelper.getConstructor(types); Constructor constructor = pushHelper.getConstructor(types);
Object[] parameters = {}; Object[] parameters = {};
PushHelperInterface pushHelperImpl = mHelper = (PushHelperInterface) constructor.newInstance(parameters);
(PushHelperInterface) constructor.newInstance(parameters); mHelper.init(context);
pushHelperImpl.init(context);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
Log.w("[Push Utils] Couldn't get push helper constructor"); Log.w("[Push Utils] Couldn't get push helper constructor");
} catch (ClassNotFoundException e) { } 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 { public interface PushHelperInterface {
void init(Context context); void init(Context context);
boolean isAvailable(Context context);
} }
} }