Skip to content

Commit

Permalink
Renaming ChromiumPlayServicesAvailability methods
Browse files Browse the repository at this point in the history
This is in response to bsazonov@'s request on the prior review. This CL
also makes the version number public so that other users can reference
it if they want to do their own checks.

TBR: bsazonov
Bug: 1145211
Change-Id: Ia0c2d62593f792fee7000e670b8b100e34253544
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2519099
Commit-Queue: Sam Maier <smaier@chromium.org>
Reviewed-by: Theresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824090}
  • Loading branch information
Sam Maier authored and Commit Bot committed Nov 4, 2020
1 parent 62150ee commit 530a7c8
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class UpdateScheduler {
@CalledByNative
/* package */ static boolean isAvailable() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|| ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(
|| ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(
ContextUtils.getApplicationContext());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public boolean canUseFirstPartyGooglePlayServices() {
protected int checkGooglePlayServicesAvailable(final Context context) {
// TODO(crbug.com/577190): Temporarily allowing disk access until more permanent fix is in.
try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
return ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(context);
return ChromiumPlayServicesAvailability.getGooglePlayServicesConnectionResult(context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class BackgroundSyncGooglePlayServicesCheckerTest {
@Test
@Feature("BackgroundSync")
public void testDisableLogicWhenGooglePlayServicesReturnsSuccess() {
ShadowChromiumPlayServicesAvailability.setIsGooglePlayServicesAvailable(
ShadowChromiumPlayServicesAvailability.setGetGooglePlayServicesConnectionResult(
ConnectionResult.SUCCESS);
assertFalse(GooglePlayServicesChecker.shouldDisableBackgroundSync());
}

@Test
@Feature("BackgroundSync")
public void testDisableLogicWhenGooglePlayServicesReturnsError() {
ShadowChromiumPlayServicesAvailability.setIsGooglePlayServicesAvailable(
ShadowChromiumPlayServicesAvailability.setGetGooglePlayServicesConnectionResult(
ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED);
assertTrue(GooglePlayServicesChecker.shouldDisableBackgroundSync());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private boolean isVrDonEnabled() {
protected boolean restrictionApplies(String restriction) {
if (TextUtils.equals(
restriction, ChromeRestriction.RESTRICTION_TYPE_GOOGLE_PLAY_SERVICES)
&& (!ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(
&& (!ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(
getTargetContext()))) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void cancel(Context context, int taskId) {
}

private GcmNetworkManager getGcmNetworkManager(Context context) {
if (ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(context)) {
if (ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(context)) {
return GcmNetworkManager.getInstance(context);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class BackgroundTaskSchedulerGcmNetworkManagerTest {

@Before
public void setUp() {
ShadowChromiumPlayServicesAvailability.setChromiumIsGooglePlayServicesAvailable(true);
ShadowChromiumPlayServicesAvailability.setIsGooglePlayServicesAvailable(true);
mGcmNetworkManager = (ShadowGcmNetworkManager) Shadow.extract(
GcmNetworkManager.getInstance(ContextUtils.getApplicationContext()));
BackgroundTaskSchedulerGcmNetworkManager.setClockForTesting(mClock);
Expand Down Expand Up @@ -297,7 +297,7 @@ public void testSchedule() {
@Test
@Feature("BackgroundTaskScheduler")
public void testScheduleNoGooglePlayServices() {
ShadowChromiumPlayServicesAvailability.setChromiumIsGooglePlayServicesAvailable(false);
ShadowChromiumPlayServicesAvailability.setIsGooglePlayServicesAvailable(false);

TaskInfo.TimingInfo timingInfo =
TaskInfo.OneOffInfo.create().setWindowEndTimeMs(TIME_24_H_TO_MS).build();
Expand Down Expand Up @@ -327,7 +327,7 @@ public void testCancel() {
@Feature("BackgroundTaskScheduler")
public void testCancelNoGooglePlayServices() {
// This simulates situation where Google Play Services is uninstalled.
ShadowChromiumPlayServicesAvailability.setChromiumIsGooglePlayServicesAvailable(false);
ShadowChromiumPlayServicesAvailability.setIsGooglePlayServicesAvailable(false);

TaskInfo.TimingInfo timingInfo =
TaskInfo.OneOffInfo.create().setWindowEndTimeMs(TIME_24_H_TO_MS).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setUp() {
TestBackgroundTask.reset();

// Initialize Google Play Services and GCM Network Manager for upgrade testing.
ShadowChromiumPlayServicesAvailability.setChromiumIsGooglePlayServicesAvailable(true);
ShadowChromiumPlayServicesAvailability.setIsGooglePlayServicesAvailable(true);
mGcmNetworkManager = (ShadowGcmNetworkManager) Shadow.extract(
GcmNetworkManager.getInstance(ContextUtils.getApplicationContext()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void onReceive(final Context context, final Intent intent) {
protected void checkCanUseGooglePlayServices() throws AccountManagerDelegateException {
Context context = ContextUtils.getApplicationContext();
final int resultCode =
ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(context);
ChromiumPlayServicesAvailability.getGooglePlayServicesConnectionResult(context);
if (resultCode == ConnectionResult.SUCCESS) {
return;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ public String getAccountGaiaId(String accountEmail) {
public boolean isGooglePlayServicesAvailable() {
// TODO(http://crbug.com/577190): Remove StrictMode override.
try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
return ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(
return ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(
ContextUtils.getApplicationContext());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class LocationProviderGmsCore implements ConnectionCallbacks, OnConnectio
private LocationRequest mLocationRequest;

public static boolean isGooglePlayServicesAvailable(Context context) {
return ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(context);
return ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(context);
}

LocationProviderGmsCore(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onConnectionError(MojoException e) {}

public static BarcodeDetectionProvider create() {
Context ctx = ContextUtils.getApplicationContext();
if (!ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(ctx)) {
if (!ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(ctx)) {
Log.w(TAG, "Google Play Services not available");
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public FaceDetectionProviderImpl() {}
public void createFaceDetection(
InterfaceRequest<FaceDetection> request, FaceDetectorOptions options) {
final boolean isGmsCoreSupported =
ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(
ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(
ContextUtils.getApplicationContext());

if (isGmsCoreSupported) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onConnectionError(MojoException e) {
}

public static TextDetection create() {
if (!ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(
if (!ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(
ContextUtils.getApplicationContext())) {
Log.e(TAG, "Google Play Services not available");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TestUtils {
public static final boolean IS_GMS_CORE_SUPPORTED = isGmsCoreSupported();

private static boolean isGmsCoreSupported() {
return ChromiumPlayServicesAvailability.chromiumIsGooglePlayServicesAvailable(
return ChromiumPlayServicesAvailability.isGooglePlayServicesAvailable(
ContextUtils.getApplicationContext());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class ChromiumPlayServicesAvailability {
* class. To see how this number originated, see
* https://bugs.chromium.org/p/chromium/issues/detail?id=1145211#c3.
*/
private static final int GMS_VERSION_NUMBER = 20415000;
public static final int GMS_VERSION_NUMBER = 20415000;

/**
* Checks, with an appropriate version number, if Play Services is available in this context.
Expand All @@ -29,7 +29,7 @@ public final class ChromiumPlayServicesAvailability {
* the user to update GMS Core or fail with exception." If in doubt, please consult with your
* PM/UX.
*/
public static int isGooglePlayServicesAvailable(final Context context) {
public static int getGooglePlayServicesConnectionResult(final Context context) {
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
context, GMS_VERSION_NUMBER);
}
Expand All @@ -43,7 +43,7 @@ public static int isGooglePlayServicesAvailable(final Context context) {
* the user to update GMS Core or fail with exception." If in doubt, please consult with your
* PM/UX.
*/
public static boolean chromiumIsGooglePlayServicesAvailable(final Context context) {
public static boolean isGooglePlayServicesAvailable(final Context context) {
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
context, GMS_VERSION_NUMBER)
== ConnectionResult.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public class ShadowChromiumPlayServicesAvailability {
private static boolean sChromiumSuccess;
private static int sConnectionResult;

public static void setChromiumIsGooglePlayServicesAvailable(boolean value) {
public static void setIsGooglePlayServicesAvailable(boolean value) {
sChromiumSuccess = value;
}
public static void setIsGooglePlayServicesAvailable(int value) {
public static void setGetGooglePlayServicesConnectionResult(int value) {
sConnectionResult = value;
}

@Implementation
public static int isGooglePlayServicesAvailable(final Context context) {
public static int getGooglePlayServicesConnectionResult(final Context context) {
return sConnectionResult;
}

@Implementation
public static boolean chromiumIsGooglePlayServicesAvailable(final Context context) {
public static boolean isGooglePlayServicesAvailable(final Context context) {
return sChromiumSuccess;
}
}

0 comments on commit 530a7c8

Please sign in to comment.