Skip to content

Commit

Permalink
[Android][Signin] Remove deprecated capability API
Browse files Browse the repository at this point in the history
This CL removes the deprecated capability API from
AccountManagerFacade as all its previous users have already switched
to the new capability API.

Bug: 1320720
Change-Id: Ibdf867f2e11ca68f6d3524d330de37d1f6478a2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3629246
Reviewed-by: Marc Treib <treib@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: Nohemi Fernandez <fernandex@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1000968}
  • Loading branch information
Alice Wang authored and Chromium LUCI CQ committed May 9, 2022
1 parent 427e89d commit 9c25a43
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import androidx.test.espresso.matcher.ViewMatchers.Visibility;
import androidx.test.filters.MediumTest;

import com.google.common.base.Optional;

import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.After;
Expand Down Expand Up @@ -91,6 +89,7 @@
import org.chromium.chrome.test.util.browser.suggestions.mostvisited.FakeMostVisitedSites;
import org.chromium.components.browser_ui.widget.RecyclerViewTestUtils;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.signin.test.util.AccountCapabilitiesBuilder;
import org.chromium.components.signin.test.util.FakeAccountManagerFacade;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.NetworkChangeNotifier;
Expand Down Expand Up @@ -129,7 +128,6 @@ public class FeedV2NewTabPageTest {
Swipe.FAST, GeneralLocation.CENTER, GeneralLocation.CENTER_LEFT, Press.FINGER);

private boolean mIsCachePopulatedInAccountManagerFacade = true;
private boolean mCanOfferExtendedSyncPromos = true;

private final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
Expand All @@ -144,11 +142,6 @@ public Promise<List<Account>> getAccounts() {
}
return new Promise<>();
}

@Override
public Optional<Boolean> canOfferExtendedSyncPromos(Account account) {
return Optional.of(mCanOfferExtendedSyncPromos);
}
};

@Rule
Expand Down Expand Up @@ -386,9 +379,10 @@ public void testSignInPromo_AccountsReady() {
@MediumTest
@Feature({"FeedNewTabPage"})
public void testSignInPromoWhenDefaultAccountCanNotOfferExtendedSyncPromos() {
mAccountManagerTestRule.addAccount("test@gmail.com");
final AccountCapabilitiesBuilder capabilitiesBuilder = new AccountCapabilitiesBuilder();
mAccountManagerTestRule.addAccount(
"test@gmail.com", capabilitiesBuilder.setCanOfferExtendedSyncPromos(false).build());
mIsCachePopulatedInAccountManagerFacade = true;
mCanOfferExtendedSyncPromos = false;

openNewTabPage();
onView(withId(R.id.feed_stream_recycler_view))
Expand Down
1 change: 0 additions & 1 deletion components/signin/public/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ android_library("java") {
"//components/externalauth/android:java",
"//net/android:net_java",
"//third_party/android_deps:chromium_play_services_availability_java",
"//third_party/android_deps:guava_android_java",
"//third_party/androidx:androidx_annotation_annotation_java",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;

import com.google.common.base.Optional;

import org.chromium.base.Callback;
import org.chromium.base.Promise;
import org.chromium.components.signin.base.AccountCapabilities;
Expand Down Expand Up @@ -110,16 +108,6 @@ interface ChildAccountStatusListener {
@MainThread
Promise<AccountCapabilities> getAccountCapabilities(Account account);

/**
* Gets the boolean for whether the account can offer extended sync promos.
* If the result is not yet fetched, the optional will be empty.
*
* This method will be removed soon. Use {@link
* AccountCapabilities#canOfferExtendedSyncPromos()} instead.
*/
@Deprecated
Optional<Boolean> canOfferExtendedSyncPromos(Account account);

/**
* Creates an intent that will ask the user to add a new account to the device. See
* {@link AccountManager#addAccount} for details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.google.common.base.Optional;

import org.chromium.base.Callback;
import org.chromium.base.ObserverList;
import org.chromium.base.Promise;
import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.task.AsyncTask;
import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskTraits;
import org.chromium.components.signin.AccountManagerDelegate.CapabilityResponse;
import org.chromium.components.signin.base.AccountCapabilities;

Expand All @@ -49,9 +45,6 @@ public class AccountManagerFacadeImpl implements AccountManagerFacade {
@VisibleForTesting
public static final String FEATURE_IS_USM_ACCOUNT_KEY = "service_usm";

@VisibleForTesting
static final String CAN_OFFER_EXTENDED_CHROME_SYNC_PROMOS = "gi2tklldmfya";

// Prefix used to define the capability name for querying Identity services. This
// prefix is not required for Android queries to GmsCore.
private static final String ACCOUNT_CAPABILITY_NAME_PREFIX = "accountcapabilities/";
Expand All @@ -64,10 +57,6 @@ public class AccountManagerFacadeImpl implements AccountManagerFacade {
private final AtomicReference<List<PatternMatcher>> mAccountRestrictionPatterns =
new AtomicReference<>();

// The map stores the boolean for whether an account can offer extended chrome sync promos
private final AtomicReference<Map<String, Boolean>> mCanOfferExtendedSyncPromos =
new AtomicReference<>(new HashMap<>());

private @NonNull Promise<List<Account>> mAccountsPromise = new Promise<>();

/**
Expand Down Expand Up @@ -172,12 +161,6 @@ protected void onPostExecute(Boolean isChild) {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

@Override
public Optional<Boolean> canOfferExtendedSyncPromos(Account account) {
return Optional.fromNullable(
mCanOfferExtendedSyncPromos.get().get(AccountUtils.canonicalizeName(account.name)));
}

/**
* Creates an intent that will ask the user to add a new account to the device. See
* {@link AccountManager#addAccount} for details.
Expand Down Expand Up @@ -244,18 +227,6 @@ protected void onPostExecute(AccountCapabilities result) {
return accountCapabilitiesPromise;
}

private void updateCanOfferExtendedSyncPromos(List<Account> accounts) {
PostTask.postTask(TaskTraits.USER_VISIBLE, () -> {
final Map<String, Boolean> canOfferExtendedSyncPromos = new HashMap<>();
for (Account account : accounts) {
canOfferExtendedSyncPromos.put(AccountUtils.canonicalizeName(account.name),
mDelegate.hasCapability(account, CAN_OFFER_EXTENDED_CHROME_SYNC_PROMOS)
== CapabilityResponse.YES);
}
mCanOfferExtendedSyncPromos.set(canOfferExtendedSyncPromos);
});
}

private void onAccountsUpdated() {
ThreadUtils.assertOnUiThread();
new AsyncTask<List<Account>>() {
Expand Down Expand Up @@ -283,7 +254,6 @@ private void updateAccounts() {
return;
}
final List<Account> newAccounts = getFilteredAccounts();
updateCanOfferExtendedSyncPromos(newAccounts);
if (mAccountsPromise.isFulfilled()) {
mAccountsPromise = Promise.fulfilled(newAccounts);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import androidx.annotation.MainThread;
import androidx.annotation.Nullable;

import com.google.common.base.Optional;

import org.chromium.base.Callback;
import org.chromium.base.Promise;
import org.chromium.base.ThreadUtils;
Expand Down Expand Up @@ -119,12 +117,6 @@ public Promise<AccountCapabilities> getAccountCapabilities(Account account) {
return Promise.fulfilled(new AccountCapabilities(new HashMap<>()));
}

@Override
public Optional<Boolean> canOfferExtendedSyncPromos(Account account) {
assert account != null;
return Optional.absent();
}

@Override
public void createAddAccountIntent(Callback<Intent> callback) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,44 +278,6 @@ public void testCheckChildAccountForAdult() {
verify(mChildAccountStatusListenerMock).onStatusReady(false, null);
}

@Test
public void testCanOfferExtendedSyncPromosForUnknownAccount() {
final Account account = AccountUtils.createAccountFromName("test@gmail.com");

Assert.assertFalse(mFacade.canOfferExtendedSyncPromos(account).isPresent());
}

@Test
public void testAccountCanNotOfferExtendedSyncPromos() {
final AccountHolder accountHolder = AccountHolder.createFromEmail("test@gmail.com");
mDelegate.addAccount(accountHolder);

Assert.assertFalse(mFacade.canOfferExtendedSyncPromos(accountHolder.getAccount()).get());
}

@Test
public void testAccountCanNotOfferExtendedSyncPromosWhenExceptionCodeReturns() {
final AccountHolder accountHolder = AccountHolder.createFromEmail("test@gmail.com");
doReturn(CapabilityResponse.EXCEPTION)
.when(mDelegate)
.hasCapability(eq(accountHolder.getAccount()), any());
mDelegate.addAccount(accountHolder);

Assert.assertFalse(mFacade.canOfferExtendedSyncPromos(accountHolder.getAccount()).get());
}

@Test
public void testAccountCanOfferExtendedSyncPromos() {
final AccountHolder accountHolder1 = AccountHolder.createFromEmail("test1@gmail.com");
mDelegate.addAccount(accountHolder1);
final AccountHolder accountHolder2 = AccountHolder.createFromEmailAndFeatures(
"test2@gmail.com", AccountManagerFacadeImpl.CAN_OFFER_EXTENDED_CHROME_SYNC_PROMOS);
mDelegate.addAccount(accountHolder2);

Assert.assertFalse(mFacade.canOfferExtendedSyncPromos(accountHolder1.getAccount()).get());
Assert.assertTrue(mFacade.canOfferExtendedSyncPromos(accountHolder2.getAccount()).get());
}

@Test
public void testGetAccessToken() throws AuthException {
final Account account = AccountUtils.createAccountFromName("test@gmail.com");
Expand Down

0 comments on commit 9c25a43

Please sign in to comment.