[Android] Use automated java enum gen for GoogleServiceAuthError State
Currently we are using outdated java file that doesn't correspond to the native enum for GoogleServiceAuthError. This cl uses automated java enum build from native enum. This cl also add the capability of converting between native and java counterparts of GoogleServiceAuthError. Bug: 404745044 Change-Id: I2b47f27e312b0afb22c50bd1de496b5dcad6dce7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6368881 Commit-Queue: Tanmoy Mollik <triploblastic@google.com> Reviewed-by: Boris Sazonov <bsazonov@chromium.org> Reviewed-by: Marc Treib <treib@chromium.org> Cr-Commit-Position: refs/heads/main@{#1439329}
This commit is contained in:
parent
78d5fe115e
commit
b71e1a71b1
chrome
android
BUILD.gn
java/src/org/chromium/chrome/browser/sync/settings
javatests
browser
password_manager/android
sync/test/android
components
signin/public/android
sync/android
BUILD.gn
java/src/org/chromium/components/sync
sync_service_android_bridge.ccsync_service_android_bridge.hgoogle_apis
@ -377,6 +377,7 @@ if (current_toolchain == default_toolchain) {
|
||||
"//chrome/browser/creator/android:java",
|
||||
"//chrome/browser/data_sharing:factory_java",
|
||||
"//chrome/browser/data_sharing:instant_message_delegate_factory_java",
|
||||
"//google_apis/gaia/android:java",
|
||||
|
||||
# TODO(ssid): Decouple dependency on internal library.
|
||||
"//chrome/browser/autofill/android:third_party_provider_java",
|
||||
|
@ -39,12 +39,12 @@ import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
|
||||
import org.chromium.chrome.browser.sync.SyncServiceFactory;
|
||||
import org.chromium.chrome.browser.sync.TrustedVaultClient;
|
||||
import org.chromium.components.signin.base.CoreAccountInfo;
|
||||
import org.chromium.components.signin.base.GoogleServiceAuthError;
|
||||
import org.chromium.components.signin.identitymanager.ConsentLevel;
|
||||
import org.chromium.components.sync.SyncService;
|
||||
import org.chromium.components.sync.TrustedVaultUserActionTriggerForUMA;
|
||||
import org.chromium.components.sync.UserSelectableType;
|
||||
import org.chromium.components.user_prefs.UserPrefs;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthErrorState;
|
||||
import org.chromium.ui.widget.Toast;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@ -253,8 +253,9 @@ public class SyncSettingsUtils {
|
||||
return context.getString(R.string.sync_settings_not_confirmed);
|
||||
}
|
||||
|
||||
if (syncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
|
||||
return getSyncStatusSummaryForAuthError(context, syncService.getAuthError());
|
||||
@GoogleServiceAuthErrorState int authErrorState = syncService.getAuthError().getState();
|
||||
if (authErrorState != GoogleServiceAuthErrorState.NONE) {
|
||||
return getSyncStatusSummaryForAuthError(context, authErrorState);
|
||||
}
|
||||
|
||||
if (syncService.requiresClientUpgrade()) {
|
||||
@ -298,30 +299,33 @@ public class SyncSettingsUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sync status summary for a given {@link GoogleServiceAuthError.State}.
|
||||
* Gets the sync status summary for a given {@link GoogleServiceAuthErrorState}.
|
||||
*
|
||||
* @param context The application context, used by the method to get string resources.
|
||||
* @param state Must not be GoogleServiceAuthError.State.None.
|
||||
*/
|
||||
private static String getSyncStatusSummaryForAuthError(
|
||||
Context context, @GoogleServiceAuthError.State int state) {
|
||||
switch (state) {
|
||||
case GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS:
|
||||
return context.getString(R.string.sync_error_ga);
|
||||
case GoogleServiceAuthError.State.CONNECTION_FAILED:
|
||||
return context.getString(R.string.sync_error_connection);
|
||||
case GoogleServiceAuthError.State.SERVICE_UNAVAILABLE:
|
||||
return context.getString(R.string.sync_error_service_unavailable);
|
||||
case GoogleServiceAuthError.State.REQUEST_CANCELED:
|
||||
case GoogleServiceAuthError.State.UNEXPECTED_SERVICE_RESPONSE:
|
||||
case GoogleServiceAuthError.State.SERVICE_ERROR:
|
||||
return context.getString(R.string.sync_error_generic);
|
||||
case GoogleServiceAuthError.State.NONE:
|
||||
Context context, @GoogleServiceAuthErrorState int state) {
|
||||
return switch (state) {
|
||||
case GoogleServiceAuthErrorState.INVALID_GAIA_CREDENTIALS -> context.getString(
|
||||
R.string.sync_error_ga);
|
||||
case GoogleServiceAuthErrorState.CONNECTION_FAILED -> context.getString(
|
||||
R.string.sync_error_connection);
|
||||
case GoogleServiceAuthErrorState.SERVICE_UNAVAILABLE -> context.getString(
|
||||
R.string.sync_error_service_unavailable);
|
||||
case GoogleServiceAuthErrorState.REQUEST_CANCELED,
|
||||
GoogleServiceAuthErrorState.UNEXPECTED_SERVICE_RESPONSE,
|
||||
GoogleServiceAuthErrorState.SERVICE_ERROR -> context.getString(
|
||||
R.string.sync_error_generic);
|
||||
case GoogleServiceAuthErrorState.NONE -> {
|
||||
assert false : "No summary if there's no auth error";
|
||||
return "";
|
||||
default:
|
||||
yield "";
|
||||
}
|
||||
default -> {
|
||||
assert false : "Unknown auth error state";
|
||||
return "";
|
||||
}
|
||||
yield "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** Returns an icon that represents the current sync state. */
|
||||
@ -592,7 +596,8 @@ public class SyncSettingsUtils {
|
||||
SyncService syncService = SyncServiceFactory.getForProfile(profile);
|
||||
assert syncService != null;
|
||||
|
||||
if (syncService.getAuthError() == GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS) {
|
||||
if (syncService.getAuthError().getState()
|
||||
== GoogleServiceAuthErrorState.INVALID_GAIA_CREDENTIALS) {
|
||||
return SyncError.AUTH_ERROR;
|
||||
}
|
||||
|
||||
@ -600,7 +605,7 @@ public class SyncSettingsUtils {
|
||||
return SyncError.CLIENT_OUT_OF_DATE;
|
||||
}
|
||||
|
||||
if (syncService.getAuthError() != GoogleServiceAuthError.State.NONE
|
||||
if (syncService.getAuthError().getState() != GoogleServiceAuthErrorState.NONE
|
||||
|| syncService.hasUnrecoverableError()) {
|
||||
return SyncError.OTHER_ERRORS;
|
||||
}
|
||||
|
@ -335,6 +335,7 @@ chrome_test_java_helper_deps = [
|
||||
"//content/public/common:common_java",
|
||||
"//content/public/test/android:content_java_test_support",
|
||||
"//content/public/test/android:content_transit_java",
|
||||
"//google_apis/gaia/android:java",
|
||||
"//media/base/android:java_switches",
|
||||
"//media/base/android:media_java",
|
||||
"//mojo/public/java:bindings_java",
|
||||
|
@ -62,6 +62,7 @@ include_rules = [
|
||||
"+components/ukm/android/java",
|
||||
"+components/webauthn/android/java",
|
||||
"+components/webxr/android",
|
||||
"+google_apis/gaia/android/java",
|
||||
|
||||
"-content/public/android/java",
|
||||
"+content/public/android/java/src/org/chromium/content_public",
|
||||
|
@ -40,7 +40,8 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
|
||||
import org.chromium.chrome.test.R;
|
||||
import org.chromium.chrome.test.util.ChromeRenderTestRule;
|
||||
import org.chromium.chrome.test.util.browser.signin.SigninTestRule;
|
||||
import org.chromium.components.signin.base.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthErrorState;
|
||||
import org.chromium.ui.test.util.ViewUtils;
|
||||
|
||||
/** Test suite for IdentityErrorCardPreference */
|
||||
@ -95,7 +96,8 @@ public class IdentityErrorCardPreferenceTest {
|
||||
@LargeTest
|
||||
@Feature("RenderTest")
|
||||
public void testIdentityErrorCardForAuthError() throws Exception {
|
||||
mFakeSyncServiceImpl.setAuthError(GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
|
||||
mFakeSyncServiceImpl.setAuthError(
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.INVALID_GAIA_CREDENTIALS));
|
||||
mSigninTestRule.addTestAccountThenSignin();
|
||||
|
||||
try (HistogramWatcher watchIdentityErrorCardShownHistogram =
|
||||
@ -248,7 +250,8 @@ public class IdentityErrorCardPreferenceTest {
|
||||
@Test
|
||||
@LargeTest
|
||||
public void testIdentityErrorCardNotShownForUnrecoverableErrors() throws Exception {
|
||||
mFakeSyncServiceImpl.setAuthError(GoogleServiceAuthError.State.CONNECTION_FAILED);
|
||||
mFakeSyncServiceImpl.setAuthError(
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.CONNECTION_FAILED));
|
||||
mSigninTestRule.addTestAccountThenSignin();
|
||||
|
||||
mSettingsActivityTestRule.startSettingsActivity();
|
||||
|
4
chrome/android/javatests/src/org/chromium/chrome/browser/sync/settings/ManageSyncSettingsTest.java
4
chrome/android/javatests/src/org/chromium/chrome/browser/sync/settings/ManageSyncSettingsTest.java
@ -111,6 +111,8 @@ import org.chromium.components.sync.TransportState;
|
||||
import org.chromium.components.sync.UserSelectableType;
|
||||
import org.chromium.components.sync.internal.SyncPrefNames;
|
||||
import org.chromium.components.user_prefs.UserPrefs;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthErrorState;
|
||||
import org.chromium.ui.modaldialog.ModalDialogManagerHolder;
|
||||
import org.chromium.ui.test.util.ViewUtils;
|
||||
|
||||
@ -1423,6 +1425,8 @@ public class ManageSyncSettingsTest {
|
||||
.thenReturn(biometricAvailabilityStatus);
|
||||
SyncServiceFactory.setInstanceForTesting(mSyncService);
|
||||
when(mSyncService.getTransportState()).thenReturn(transportState);
|
||||
when(mSyncService.getAuthError())
|
||||
.thenReturn(new GoogleServiceAuthError(GoogleServiceAuthErrorState.NONE));
|
||||
}
|
||||
|
||||
private void setupMockSyncService() {
|
||||
|
@ -68,9 +68,10 @@ import org.chromium.chrome.test.util.ActivityTestUtils;
|
||||
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
|
||||
import org.chromium.components.signin.AccountManagerFacadeProvider;
|
||||
import org.chromium.components.signin.base.CoreAccountInfo;
|
||||
import org.chromium.components.signin.base.GoogleServiceAuthError;
|
||||
import org.chromium.components.signin.test.util.FakeAccountManagerFacade;
|
||||
import org.chromium.components.sync.DataType;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthErrorState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -262,7 +263,8 @@ public class ManageSyncSettingsWithFakeSyncServiceImplTest {
|
||||
public void testIdentityErrorCardActionForAuthError() throws Exception {
|
||||
final FakeSyncServiceImpl fakeSyncService =
|
||||
(FakeSyncServiceImpl) mSyncTestRule.getSyncService();
|
||||
fakeSyncService.setAuthError(GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
|
||||
fakeSyncService.setAuthError(
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.INVALID_GAIA_CREDENTIALS));
|
||||
|
||||
// Sign in and open settings.
|
||||
mSyncTestRule.setUpAccountAndSignInForTesting();
|
||||
@ -280,7 +282,8 @@ public class ManageSyncSettingsWithFakeSyncServiceImplTest {
|
||||
doAnswer(
|
||||
invocation -> {
|
||||
// Simulate re-auth by clearing the auth error.
|
||||
fakeSyncService.setAuthError(GoogleServiceAuthError.State.NONE);
|
||||
fakeSyncService.setAuthError(
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.NONE));
|
||||
return null;
|
||||
})
|
||||
.when(fakeAccountManagerFacade)
|
||||
|
@ -65,7 +65,8 @@ import org.chromium.chrome.test.util.ChromeRenderTestRule;
|
||||
import org.chromium.components.embedder_support.util.UrlConstants;
|
||||
import org.chromium.components.messages.MessageBannerProperties;
|
||||
import org.chromium.components.messages.MessageDispatcher;
|
||||
import org.chromium.components.signin.base.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthErrorState;
|
||||
import org.chromium.ui.modelutil.PropertyModel;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -130,13 +131,15 @@ public class SyncErrorMessageTest {
|
||||
|
||||
// Sign in.
|
||||
mSyncTestRule.setUpAccountAndSignInForTesting();
|
||||
mFakeSyncServiceImpl.setAuthError(GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
|
||||
mFakeSyncServiceImpl.setAuthError(
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.INVALID_GAIA_CREDENTIALS));
|
||||
mSyncTestRule.loadUrl(UrlConstants.VERSION_URL);
|
||||
verifyHasShownMessage();
|
||||
watchIdentityErrorMessageShownHistogram.assertExpected();
|
||||
|
||||
// Resolving the error should dismiss the current message.
|
||||
mFakeSyncServiceImpl.setAuthError(GoogleServiceAuthError.State.NONE);
|
||||
mFakeSyncServiceImpl.setAuthError(
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.NONE));
|
||||
verifyHasDismissedMessage();
|
||||
}
|
||||
|
||||
@ -310,7 +313,8 @@ public class SyncErrorMessageTest {
|
||||
// Sign in.
|
||||
mSyncTestRule.setUpAccountAndSignInForTesting();
|
||||
mFakeSyncServiceImpl.setEngineInitialized(true);
|
||||
mFakeSyncServiceImpl.setAuthError(GoogleServiceAuthError.State.NONE);
|
||||
mFakeSyncServiceImpl.setAuthError(
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.NONE));
|
||||
mFakeSyncServiceImpl.setPassphraseRequiredForPreferredDataTypes(false);
|
||||
mFakeSyncServiceImpl.setRequiresClientUpgrade(false);
|
||||
|
||||
@ -346,7 +350,8 @@ public class SyncErrorMessageTest {
|
||||
SyncErrorMessage.setMessageDispatcherForTesting(null);
|
||||
// Sign in.
|
||||
mSyncTestRule.setUpAccountAndSignInForTesting();
|
||||
mFakeSyncServiceImpl.setAuthError(GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
|
||||
mFakeSyncServiceImpl.setAuthError(
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.INVALID_GAIA_CREDENTIALS));
|
||||
mSyncTestRule.loadUrl(UrlConstants.VERSION_URL);
|
||||
ViewGroup view = mSyncTestRule.getActivity().findViewById(R.id.message_container);
|
||||
// Wait until the message ui is shown.
|
||||
|
@ -394,6 +394,7 @@ robolectric_binary("password_manager_junit_tests") {
|
||||
"//components/sync/protocol:protocol_java",
|
||||
"//components/user_prefs/android:java",
|
||||
"//content/public/android:content_java",
|
||||
"//google_apis/gaia/android:java",
|
||||
"//third_party/android_deps:espresso_java",
|
||||
"//third_party/android_deps:protobuf_lite_runtime_java",
|
||||
"//third_party/androidx:androidx_annotation_annotation_java",
|
||||
|
@ -82,12 +82,13 @@ import org.chromium.components.browser_ui.test.BrowserUiDummyFragmentActivity;
|
||||
import org.chromium.components.prefs.PrefService;
|
||||
import org.chromium.components.signin.base.CoreAccountInfo;
|
||||
import org.chromium.components.signin.base.GaiaId;
|
||||
import org.chromium.components.signin.base.GoogleServiceAuthError;
|
||||
import org.chromium.components.sync.DataType;
|
||||
import org.chromium.components.sync.SyncService;
|
||||
import org.chromium.components.sync.UserSelectableType;
|
||||
import org.chromium.components.user_prefs.UserPrefs;
|
||||
import org.chromium.components.user_prefs.UserPrefsJni;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthErrorState;
|
||||
import org.chromium.ui.modaldialog.ModalDialogManager;
|
||||
import org.chromium.ui.modaldialog.ModalDialogProperties;
|
||||
import org.chromium.ui.modelutil.PropertyModel;
|
||||
@ -158,7 +159,8 @@ public class PasswordManagerHelperTest {
|
||||
.thenReturn(false);
|
||||
SyncServiceFactory.setInstanceForTesting(mSyncServiceMock);
|
||||
when(mSyncServiceMock.isEngineInitialized()).thenReturn(true);
|
||||
when(mSyncServiceMock.getAuthError()).thenReturn(GoogleServiceAuthError.State.NONE);
|
||||
when(mSyncServiceMock.getAuthError())
|
||||
.thenReturn(new GoogleServiceAuthError(GoogleServiceAuthErrorState.NONE));
|
||||
when(mLoadingModalDialogCoordinator.getState())
|
||||
.thenReturn(LoadingModalDialogCoordinator.State.PENDING);
|
||||
mModalDialogManager =
|
||||
@ -255,7 +257,9 @@ public class PasswordManagerHelperTest {
|
||||
when(mSyncServiceMock.isEngineInitialized()).thenReturn(true);
|
||||
when(mSyncServiceMock.hasSyncConsent()).thenReturn(true);
|
||||
when(mSyncServiceMock.getAuthError())
|
||||
.thenReturn(GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
|
||||
.thenReturn(
|
||||
new GoogleServiceAuthError(
|
||||
GoogleServiceAuthErrorState.INVALID_GAIA_CREDENTIALS));
|
||||
|
||||
assertFalse(mPasswordManagerHelper.canUseUpm());
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ android_library("test_support_java") {
|
||||
"//components/signin/public/android:java",
|
||||
"//components/sync/android:sync_java",
|
||||
"//content/public/test/android:content_java_test_support",
|
||||
"//google_apis/gaia/android:java",
|
||||
"//third_party/androidx:androidx_annotation_annotation_java",
|
||||
]
|
||||
}
|
||||
|
10
chrome/browser/sync/test/android/java/src/org/chromium/chrome/browser/sync/FakeSyncServiceImpl.java
10
chrome/browser/sync/test/android/java/src/org/chromium/chrome/browser/sync/FakeSyncServiceImpl.java
@ -13,11 +13,12 @@ import org.chromium.base.Callback;
|
||||
import org.chromium.base.ThreadUtils;
|
||||
import org.chromium.chrome.browser.profiles.ProfileManager;
|
||||
import org.chromium.components.signin.base.CoreAccountInfo;
|
||||
import org.chromium.components.signin.base.GoogleServiceAuthError;
|
||||
import org.chromium.components.sync.LocalDataDescription;
|
||||
import org.chromium.components.sync.SyncService;
|
||||
import org.chromium.components.sync.SyncServiceImpl;
|
||||
import org.chromium.components.sync.UserSelectableType;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthErrorState;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
@ -37,7 +38,8 @@ public class FakeSyncServiceImpl implements SyncService {
|
||||
private boolean mTrustedVaultRecoverabilityDegraded;
|
||||
private boolean mEncryptEverythingEnabled;
|
||||
private boolean mRequiresClientUpgrade;
|
||||
@GoogleServiceAuthError.State private int mAuthError;
|
||||
private GoogleServiceAuthError mAuthError =
|
||||
new GoogleServiceAuthError(GoogleServiceAuthErrorState.NONE);
|
||||
private Set<Integer> mTypesWithUnsyncedData = Set.of();
|
||||
|
||||
public FakeSyncServiceImpl() {
|
||||
@ -60,13 +62,13 @@ public class FakeSyncServiceImpl implements SyncService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @GoogleServiceAuthError.State int getAuthError() {
|
||||
public GoogleServiceAuthError getAuthError() {
|
||||
ThreadUtils.assertOnUiThread();
|
||||
return mAuthError;
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
public void setAuthError(@GoogleServiceAuthError.State int authError) {
|
||||
public void setAuthError(GoogleServiceAuthError authError) {
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
mAuthError = authError;
|
||||
|
@ -52,7 +52,6 @@ android_library("java") {
|
||||
"java/src/org/chromium/components/signin/base/CoreAccountId.java",
|
||||
"java/src/org/chromium/components/signin/base/CoreAccountInfo.java",
|
||||
"java/src/org/chromium/components/signin/base/GaiaId.java",
|
||||
"java/src/org/chromium/components/signin/base/GoogleServiceAuthError.java",
|
||||
"java/src/org/chromium/components/signin/identitymanager/AccountInfoService.java",
|
||||
"java/src/org/chromium/components/signin/identitymanager/AccountInfoServiceImpl.java",
|
||||
"java/src/org/chromium/components/signin/identitymanager/AccountInfoServiceProvider.java",
|
||||
@ -82,7 +81,6 @@ generate_jni("jni_headers") {
|
||||
"java/src/org/chromium/components/signin/base/CoreAccountId.java",
|
||||
"java/src/org/chromium/components/signin/base/CoreAccountInfo.java",
|
||||
"java/src/org/chromium/components/signin/base/GaiaId.java",
|
||||
"java/src/org/chromium/components/signin/base/GoogleServiceAuthError.java",
|
||||
"java/src/org/chromium/components/signin/identitymanager/AccountManagedStatusFinder.java",
|
||||
"java/src/org/chromium/components/signin/identitymanager/IdentityManager.java",
|
||||
"java/src/org/chromium/components/signin/identitymanager/IdentityMutator.java",
|
||||
|
@ -1,105 +0,0 @@
|
||||
// Copyright 2013 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.components.signin.base;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import org.jni_zero.CalledByNative;
|
||||
|
||||
import org.chromium.build.annotations.NullMarked;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* This class mirrors the native GoogleServiceAuthError class State enum from:
|
||||
* google_apis/gaia/google_service_auth_error.h.
|
||||
*/
|
||||
@NullMarked
|
||||
public class GoogleServiceAuthError {
|
||||
@IntDef({
|
||||
State.NONE,
|
||||
State.INVALID_GAIA_CREDENTIALS,
|
||||
State.USER_NOT_SIGNED_UP,
|
||||
State.CONNECTION_FAILED,
|
||||
State.SERVICE_UNAVAILABLE,
|
||||
State.REQUEST_CANCELED,
|
||||
State.UNEXPECTED_SERVICE_RESPONSE,
|
||||
State.SERVICE_ERROR
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface State {
|
||||
// The user is authenticated.
|
||||
int NONE = 0;
|
||||
|
||||
// The credentials supplied to GAIA were either invalid, or the locally
|
||||
// cached credentials have expired.
|
||||
int INVALID_GAIA_CREDENTIALS = 1;
|
||||
|
||||
// The GAIA user is not authorized to use the service.
|
||||
int USER_NOT_SIGNED_UP = 2;
|
||||
|
||||
// Could not connect to server to verify credentials. This could be in
|
||||
// response to either failure to connect to GAIA or failure to connect to
|
||||
// the service needing GAIA tokens during authentication.
|
||||
int CONNECTION_FAILED = 3;
|
||||
|
||||
// DEPRECATED.
|
||||
// The user needs to satisfy a CAPTCHA challenge to unlock their account.
|
||||
// If no other information is available, this can be resolved by visiting
|
||||
// https://www.google.com/accounts/DisplayUnlockCaptcha. Otherwise,
|
||||
// captcha() will provide details about the associated challenge.
|
||||
// int CAPTCHA_REQUIRED = 4;
|
||||
|
||||
// DEPRECATED.
|
||||
// The user account has been deleted.
|
||||
// int ACCOUNT_DELETED = 5;
|
||||
|
||||
// DEPRECATED.
|
||||
// The user account has been disabled.
|
||||
// int ACCOUNT_DISABLED = 6;
|
||||
|
||||
// The service is not available; try again later.
|
||||
int SERVICE_UNAVAILABLE = 7;
|
||||
|
||||
// DEPRECATED.
|
||||
// The password is valid but we need two factor to get a token.
|
||||
// int TWO_FACTOR = 8;
|
||||
|
||||
// The requestor of the authentication step cancelled the request
|
||||
// prior to completion.
|
||||
int REQUEST_CANCELED = 9;
|
||||
|
||||
// HOSTED accounts are deprecated.
|
||||
// int HOSTED_NOT_ALLOWED_DEPRECATED = 10;
|
||||
|
||||
// Indicates the service responded to a request, but we cannot
|
||||
// interpret the response.
|
||||
int UNEXPECTED_SERVICE_RESPONSE = 11;
|
||||
|
||||
// Indicates the service responded and response carried details of the
|
||||
// application error.
|
||||
int SERVICE_ERROR = 12;
|
||||
|
||||
// DEPRECATED.
|
||||
// The password is valid but web login is required to get a token.
|
||||
// int WEB_LOGIN_REQUIRED = 13;
|
||||
|
||||
int NUM_ENTRIES = 14;
|
||||
}
|
||||
|
||||
private final @State int mState;
|
||||
|
||||
@VisibleForTesting
|
||||
@CalledByNative
|
||||
public GoogleServiceAuthError(@State int state) {
|
||||
mState = state;
|
||||
}
|
||||
|
||||
public @State int getState() {
|
||||
return mState;
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ android_library("sync_java") {
|
||||
"//base:base_java",
|
||||
"//base:service_loader_java",
|
||||
"//components/signin/public/android:java",
|
||||
"//google_apis/gaia/android:java",
|
||||
"//third_party/android_deps:protobuf_lite_runtime_java",
|
||||
"//third_party/androidx:androidx_annotation_annotation_java",
|
||||
"//third_party/jni_zero:jni_zero_java",
|
||||
|
@ -13,7 +13,7 @@ import org.chromium.base.Callback;
|
||||
import org.chromium.build.annotations.NullMarked;
|
||||
import org.chromium.build.annotations.Nullable;
|
||||
import org.chromium.components.signin.base.CoreAccountInfo;
|
||||
import org.chromium.components.signin.base.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthError;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
@ -63,7 +63,7 @@ public interface SyncService {
|
||||
// codebase. See ConsentLevel::kSync documentation for details.
|
||||
public boolean isSyncFeatureActive();
|
||||
|
||||
public @GoogleServiceAuthError.State int getAuthError();
|
||||
public GoogleServiceAuthError getAuthError();
|
||||
|
||||
/**
|
||||
* Checks whether Sync is disabled by enterprise policy (through prefs) or account policy
|
||||
|
@ -8,6 +8,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import org.jni_zero.CalledByNative;
|
||||
import org.jni_zero.JNINamespace;
|
||||
import org.jni_zero.JniType;
|
||||
import org.jni_zero.NativeMethods;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -21,7 +22,7 @@ import org.chromium.components.signin.AccountManagerFacade;
|
||||
import org.chromium.components.signin.AccountManagerFacadeProvider;
|
||||
import org.chromium.components.signin.AccountsChangeObserver;
|
||||
import org.chromium.components.signin.base.CoreAccountInfo;
|
||||
import org.chromium.components.signin.base.GoogleServiceAuthError;
|
||||
import org.chromium.google_apis.gaia.GoogleServiceAuthError;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -97,14 +98,10 @@ public class SyncServiceImpl implements SyncService, AccountsChangeObserver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @GoogleServiceAuthError.State int getAuthError() {
|
||||
public GoogleServiceAuthError getAuthError() {
|
||||
mThreadChecker.assertOnValidThread();
|
||||
assert mSyncServiceAndroidBridge != 0;
|
||||
int authErrorCode = SyncServiceImplJni.get().getAuthError(mSyncServiceAndroidBridge);
|
||||
if (authErrorCode < 0 || authErrorCode >= GoogleServiceAuthError.State.NUM_ENTRIES) {
|
||||
throw new IllegalArgumentException("No state for code: " + authErrorCode);
|
||||
}
|
||||
return authErrorCode;
|
||||
return SyncServiceImplJni.get().getAuthError(mSyncServiceAndroidBridge);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -610,7 +607,8 @@ public class SyncServiceImpl implements SyncService, AccountsChangeObserver {
|
||||
|
||||
void getAllNodes(long nativeSyncServiceAndroidBridge, Callback<JSONArray> callback);
|
||||
|
||||
int getAuthError(long nativeSyncServiceAndroidBridge);
|
||||
@JniType("GoogleServiceAuthError")
|
||||
GoogleServiceAuthError getAuthError(long nativeSyncServiceAndroidBridge);
|
||||
|
||||
boolean hasUnrecoverableError(long nativeSyncServiceAndroidBridge);
|
||||
|
||||
|
@ -390,8 +390,8 @@ void SyncServiceAndroidBridge::GetAllNodes(
|
||||
base::BindOnce(&NativeGetAllNodesCallback, env, java_callback));
|
||||
}
|
||||
|
||||
jint SyncServiceAndroidBridge::GetAuthError(JNIEnv* env) {
|
||||
return native_sync_service_->GetAuthError().state();
|
||||
GoogleServiceAuthError SyncServiceAndroidBridge::GetAuthError(JNIEnv* env) {
|
||||
return native_sync_service_->GetAuthError();
|
||||
}
|
||||
|
||||
jboolean SyncServiceAndroidBridge::HasUnrecoverableError(JNIEnv* env) {
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "base/android/scoped_java_ref.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "components/sync/service/sync_service_observer.h"
|
||||
#include "google_apis/gaia/google_service_auth_error.h"
|
||||
|
||||
namespace syncer {
|
||||
|
||||
@ -89,7 +90,7 @@ class SyncServiceAndroidBridge : public SyncServiceObserver {
|
||||
jlong GetExplicitPassphraseTime(JNIEnv* env);
|
||||
void GetAllNodes(JNIEnv* env,
|
||||
const base::android::JavaParamRef<jobject>& callback);
|
||||
jint GetAuthError(JNIEnv* env);
|
||||
GoogleServiceAuthError GetAuthError(JNIEnv* env);
|
||||
jboolean HasUnrecoverableError(JNIEnv* env);
|
||||
jboolean RequiresClientUpgrade(JNIEnv* env);
|
||||
base::android::ScopedJavaLocalRef<jobject> GetAccountInfo(JNIEnv* env);
|
||||
|
@ -191,6 +191,10 @@ component("google_apis") {
|
||||
frameworks = [ "Foundation.framework" ]
|
||||
}
|
||||
|
||||
if (is_android) {
|
||||
deps += [ "gaia/android:jni_headers" ]
|
||||
}
|
||||
|
||||
defines = [ "IS_GOOGLE_APIS_IMPL" ]
|
||||
}
|
||||
|
||||
|
25
google_apis/gaia/android/BUILD.gn
Normal file
25
google_apis/gaia/android/BUILD.gn
Normal file
@ -0,0 +1,25 @@
|
||||
import("//build/config/android/rules.gni")
|
||||
import("//third_party/jni_zero/jni_zero.gni")
|
||||
|
||||
android_library("java") {
|
||||
sources =
|
||||
[ "java/src/org/chromium/google_apis/gaia/GoogleServiceAuthError.java" ]
|
||||
deps = [
|
||||
"//build/android:build_java",
|
||||
"//third_party/androidx:androidx_annotation_annotation_java",
|
||||
"//third_party/jni_zero:jni_zero_java",
|
||||
]
|
||||
srcjar_deps = [
|
||||
":google_apis_enum_javagen",
|
||||
":jni_headers",
|
||||
]
|
||||
}
|
||||
|
||||
java_cpp_enum("google_apis_enum_javagen") {
|
||||
sources = [ "../google_service_auth_error.h" ]
|
||||
}
|
||||
|
||||
generate_jni("jni_headers") {
|
||||
sources =
|
||||
[ "java/src/org/chromium/google_apis/gaia/GoogleServiceAuthError.java" ]
|
||||
}
|
28
google_apis/gaia/android/java/src/org/chromium/google_apis/gaia/GoogleServiceAuthError.java
Normal file
28
google_apis/gaia/android/java/src/org/chromium/google_apis/gaia/GoogleServiceAuthError.java
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2013 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.google_apis.gaia;
|
||||
|
||||
import org.jni_zero.CalledByNative;
|
||||
|
||||
import org.chromium.build.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* This class mirrors the native GoogleServiceAuthError class from:
|
||||
* google_apis/gaia/google_service_auth_error.h.
|
||||
*/
|
||||
@NullMarked
|
||||
public class GoogleServiceAuthError {
|
||||
private final @GoogleServiceAuthErrorState int mState;
|
||||
|
||||
@CalledByNative
|
||||
public GoogleServiceAuthError(@GoogleServiceAuthErrorState int state) {
|
||||
mState = state;
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
public @GoogleServiceAuthErrorState int getState() {
|
||||
return mState;
|
||||
}
|
||||
}
|
@ -13,6 +13,10 @@
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "net/base/net_errors.h"
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
#include "google_apis/gaia/android/jni_headers/GoogleServiceAuthError_jni.h"
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
namespace {
|
||||
const char* InvalidCredentialsReasonToString(
|
||||
GoogleServiceAuthError::InvalidGaiaCredentialsReason reason) {
|
||||
@ -265,3 +269,30 @@ bool GoogleServiceAuthError::IsTransientError() const {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
// static
|
||||
GoogleServiceAuthError GoogleServiceAuthError::FromJavaObject(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaRef<jobject>& j_auth_error) {
|
||||
CHECK(j_auth_error);
|
||||
GoogleServiceAuthError::State state =
|
||||
static_cast<GoogleServiceAuthError::State>(
|
||||
Java_GoogleServiceAuthError_getState(env, j_auth_error));
|
||||
if (state == GoogleServiceAuthError::SCOPE_LIMITED_UNRECOVERABLE_ERROR) {
|
||||
// Android doesn't provide reasons for this type of errors and only creates
|
||||
// them for enterprise policy enforced scopes. So we hardcode the value
|
||||
// here.
|
||||
return GoogleServiceAuthError::FromScopeLimitedUnrecoverableErrorReason(
|
||||
GoogleServiceAuthError::ScopeLimitedUnrecoverableErrorReason::
|
||||
kAdminPolicyEnforced);
|
||||
} else {
|
||||
return GoogleServiceAuthError(state);
|
||||
}
|
||||
}
|
||||
|
||||
jni_zero::ScopedJavaLocalRef<jobject> GoogleServiceAuthError::ToJavaObject(
|
||||
JNIEnv* env) const {
|
||||
return Java_GoogleServiceAuthError_Constructor(env, state_);
|
||||
}
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
@ -16,12 +16,18 @@
|
||||
#include "base/component_export.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
#include "base/android/scoped_java_ref.h"
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
class COMPONENT_EXPORT(GOOGLE_APIS) GoogleServiceAuthError {
|
||||
public:
|
||||
//
|
||||
// These enumerations are referenced by integer value in HTML login code and
|
||||
// in UMA histograms. Do not change the numeric values.
|
||||
//
|
||||
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.google_apis.gaia
|
||||
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: GoogleServiceAuthErrorState
|
||||
enum State {
|
||||
// The user is authenticated.
|
||||
NONE = 0,
|
||||
@ -208,6 +214,14 @@ class COMPONENT_EXPORT(GOOGLE_APIS) GoogleServiceAuthError {
|
||||
// both.
|
||||
bool IsTransientError() const;
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
static GoogleServiceAuthError FromJavaObject(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaRef<jobject>& j_auth_error);
|
||||
|
||||
jni_zero::ScopedJavaLocalRef<jobject> ToJavaObject(JNIEnv* env) const;
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
private:
|
||||
GoogleServiceAuthError(State s, int error);
|
||||
|
||||
@ -230,4 +244,24 @@ class COMPONENT_EXPORT(GOOGLE_APIS) GoogleServiceAuthError {
|
||||
scope_limited_unrecoverable_error_reason_;
|
||||
};
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
namespace jni_zero {
|
||||
|
||||
template <>
|
||||
inline GoogleServiceAuthError FromJniType<GoogleServiceAuthError>(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaRef<jobject>& j_auth_error) {
|
||||
return GoogleServiceAuthError::FromJavaObject(env, j_auth_error);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline ScopedJavaLocalRef<jobject> ToJniType(
|
||||
JNIEnv* env,
|
||||
const GoogleServiceAuthError& auth_error) {
|
||||
return auth_error.ToJavaObject(env);
|
||||
}
|
||||
|
||||
} // namespace jni_zero
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
#endif // GOOGLE_APIS_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user