Skip to content

Commit 36dd357

Browse files
committed
Removed unneeded version check of gms
* Removed use of isGooglePlayServicesAvailable - It always returns false when the device version is older than the app version. - GoogleCloudMessaging.register works even when the device has version 3.2.25. - Still checks if the app as been disabled.
1 parent a973083 commit 36dd357

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

OneSignalSDK.jar

-167 Bytes
Binary file not shown.

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void init() {
167167
private static TrackGooglePurchase trackGooglePurchase;
168168
private static TrackAmazonPurchase trackAmazonPurchase;
169169

170-
public static final String VERSION = "030001";
170+
public static final String VERSION = "030002";
171171

172172
private static AdvertisingIdentifierProvider mainAdIdProvider = new AdvertisingIdProviderGPS();
173173

OneSignalSDK/onesignal/src/main/java/com/onesignal/PushRegistratorGPS.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
package com.onesignal;
2929

30-
import com.google.android.gms.common.ConnectionResult;
3130
import com.google.android.gms.common.GooglePlayServicesUtil;
3231
import com.google.android.gms.gcm.GoogleCloudMessaging;
3332

@@ -58,10 +57,10 @@ public void registerForPush(Context context, String googleProjectNumber, Registe
5857
registeredHandler = callback;
5958

6059
try {
61-
if (checkPlayServices())
60+
if (isGMSInstalledAndEnabled())
6261
registerInBackground(googleProjectNumber);
6362
else {
64-
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "No valid Google Play services APK found.");
63+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "'Google Play services' app not installed or disabled on the device.");
6564
registeredHandler.complete(null, -7);
6665
}
6766
} catch (Throwable t) {
@@ -81,34 +80,28 @@ private boolean isGooglePlayStoreInstalled() {
8180
return false;
8281
}
8382

84-
private boolean checkPlayServices() {
85-
// GoogleApiAvailability is the replacement for GooglePlayServicesUtil added in 7.3.
86-
87-
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(appContext);
88-
if (resultCode != ConnectionResult.SUCCESS) {
89-
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode) && isGooglePlayStoreInstalled()) {
90-
OneSignal.Log(OneSignal.LOG_LEVEL.INFO, "Google Play services Recoverable Error: " + resultCode);
83+
private boolean isGMSInstalledAndEnabled() {
84+
try {
85+
PackageManager pm = appContext.getPackageManager();
86+
PackageInfo info = pm.getPackageInfo("com.google.android.gms", PackageManager.GET_ACTIVITIES);
9187

88+
if (!info.applicationInfo.enabled && isGooglePlayStoreInstalled()) {
9289
final SharedPreferences prefs = OneSignal.getGcmPreferences(appContext);
9390
if (prefs.getBoolean("GT_DO_NOT_SHOW_MISSING_GPS", false))
9491
return false;
9592

9693
try {
97-
ShowUpdateGPSDialog(resultCode);
94+
ShowUpdateGPSDialog();
9895
} catch (Throwable t) {}
9996
}
100-
else
101-
OneSignal.Log(OneSignal.LOG_LEVEL.WARN, "Google Play services error: This device is not supported. Code:" + resultCode);
102-
103-
return false;
104-
}
105-
106-
return true;
107-
}
10897

98+
return info.applicationInfo.enabled;
99+
} catch (PackageManager.NameNotFoundException e) {}
109100

101+
return false;
102+
}
110103

111-
private void ShowUpdateGPSDialog(final int resultCode) {
104+
private void ShowUpdateGPSDialog() {
112105
OneSignal.runOnUiThread(new Runnable() {
113106
@Override
114107
public void run() {
@@ -126,6 +119,7 @@ public void run() {
126119
@Override
127120
public void onClick(DialogInterface dialog, int which) {
128121
try {
122+
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(appContext);
129123
GooglePlayServicesUtil.getErrorPendingIntent(resultCode, activity, 0).send();
130124
} catch (CanceledException e) {
131125
} catch (Throwable e) {

0 commit comments

Comments
 (0)