Commit 9b866113 authored by Zhiqiang Zhang's avatar Zhiqiang Zhang Committed by Commit Bot

[Android MR] Check Google Play services APK version before enabling CAF

This CL checks GMS APK version before enabling CAF. The reason is that
the current SDK version is 12.0.1, while we require the APK version to
be 12.6.0 or above to make it fully functional (this is to avoid
intializing the SDK in Activity#onCreate()).

Currently we are using a fallback implementation to check GMS APK
version. Ideally this should be done via the versioned
GoogleApiAvailability.isGooglePlayServiceAvailable() API. However this
versioned API is only added in a later version. The downstream
implementation is calling the versioned API directly.

After the upstream SDK version gets updated, we can just call the
versioned API directly.

Bug: 711860
Change-Id: Iec5f84cffcc5c55fd303255b91a7f187c79b15cb
Reviewed-on: https://chromium-review.googlesource.com/1132474Reviewed-by: default avatarThomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Zhiqiang Zhang <zqzhang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574722}
parent 3e3bfb0e
......@@ -6,11 +6,16 @@ package org.chromium.chrome.browser;
import android.app.Notification;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
......@@ -330,4 +335,31 @@ public abstract class AppHooks {
public Fido2ApiHandler createFido2ApiHandler() {
return new Fido2ApiHandler();
}
/**
* Checks the Google Play services availability on the this device.
*
* This is a workaround for the
* versioned API of {@link GoogleApiAvailability#isGooglePlayServicesAvailable()}. The current
* Google Play services SDK version doesn't have this API yet.
*
* TODO(zqzhang): Remove this method after the SDK is updated.
*
* @return status code indicating whether there was an error. The possible return values are the
* same as {@link GoogleApiAvailability#isGooglePlayServicesAvailable()}.
*/
public int isGoogleApiAvailableWithMinApkVersion(int minApkVersion) {
try {
PackageInfo gmsPackageInfo =
ContextUtils.getApplicationContext().getPackageManager().getPackageInfo(
GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, /* flags= */ 0);
int apkVersion = gmsPackageInfo.versionCode;
if (apkVersion >= minApkVersion) {
return ConnectionResult.SUCCESS;
}
} catch (PackageManager.NameNotFoundException e) {
return ConnectionResult.SERVICE_MISSING;
}
return ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED;
}
}
......@@ -6,6 +6,9 @@ package org.chromium.chrome.browser.media.router;
import android.support.v7.media.MediaRouter;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.StrictModeContext;
......@@ -13,6 +16,7 @@ import org.chromium.base.SysUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.media.router.caf.CafMediaRouteProvider;
import org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider;
......@@ -33,6 +37,7 @@ import javax.annotation.Nullable;
public class ChromeMediaRouter implements MediaRouteManager {
private static final String TAG = "MediaRouter";
private static final int MIN_GOOGLE_PLAY_SERVICES_APK_VERSION = 12600000;
private static MediaRouteProvider.Factory sRouteProviderFactory =
new MediaRouteProvider.Factory() {
......@@ -43,6 +48,15 @@ public class ChromeMediaRouter implements MediaRouteManager {
if (ChromeFeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(
ChromeFeatureList.CAF_MEDIA_ROUTER_IMPL)) {
int googleApiAvailabilityResult =
AppHooks.get().isGoogleApiAvailableWithMinApkVersion(
MIN_GOOGLE_PLAY_SERVICES_APK_VERSION);
if (googleApiAvailabilityResult != ConnectionResult.SUCCESS) {
GoogleApiAvailability.getInstance().showErrorNotification(
ContextUtils.getApplicationContext(),
googleApiAvailabilityResult);
return;
}
MediaRouteProvider cafProvider = CafMediaRouteProvider.create(manager);
manager.addMediaRouteProvider(cafProvider);
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment