Fixed build if google services API not available
This commit is contained in:
parent
b64d62cc4a
commit
1cfdc5c2ff
6 changed files with 29 additions and 18 deletions
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue