Removed Context from AppSearch singletons getInstance() methods.
Test: atest AdServicesServiceCoreAppSearchUnitTests AdExtServicesServiceCoreAppSearchUnitTests AdServicesServiceCoreUnitTests
Bug: 311183933
Change-Id: I7ac5a49a50a506d02548873c2109b9d31ccb84a4
diff --git a/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchConsentManager.java b/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchConsentManager.java
index 14c2d67..e0d4f1c 100644
--- a/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchConsentManager.java
+++ b/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchConsentManager.java
@@ -41,6 +41,7 @@
import com.android.adservices.service.topics.BlockedTopicsManager;
import com.android.adservices.service.ui.enrollment.collection.PrivacySandboxEnrollmentChannelCollection;
import com.android.adservices.service.ui.ux.collection.PrivacySandboxUxCollection;
+import com.android.adservices.shared.common.ApplicationContextSingleton;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.utils.build.SdkLevel;
@@ -73,9 +74,9 @@
}
/** Returns an instance of AppSearchConsentManager. */
- public static AppSearchConsentManager getInstance(@NonNull Context context) {
- Objects.requireNonNull(context);
- return new AppSearchConsentManager(context, AppSearchConsentWorker.getInstance(context));
+ public static AppSearchConsentManager getInstance() {
+ return new AppSearchConsentManager(
+ ApplicationContextSingleton.get(), AppSearchConsentWorker.getInstance());
}
/**
diff --git a/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchConsentWorker.java b/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchConsentWorker.java
index 8e4fdd4..42c5c1e 100644
--- a/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchConsentWorker.java
+++ b/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchConsentWorker.java
@@ -43,6 +43,7 @@
import com.android.adservices.service.consent.ConsentManager;
import com.android.adservices.service.ui.enrollment.collection.PrivacySandboxEnrollmentChannelCollection;
import com.android.adservices.service.ui.ux.collection.PrivacySandboxUxCollection;
+import com.android.adservices.shared.common.ApplicationContextSingleton;
import com.android.internal.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ListenableFuture;
@@ -153,9 +154,8 @@
}
/** Get an instance of AppSearchConsentWorker. */
- static AppSearchConsentWorker getInstance(@NonNull Context context) {
- Objects.requireNonNull(context);
- return new AppSearchConsentWorker(context);
+ static AppSearchConsentWorker getInstance() {
+ return new AppSearchConsentWorker(ApplicationContextSingleton.get());
}
/**
diff --git a/adservices/service-core/java/com/android/adservices/service/consent/ConsentManager.java b/adservices/service-core/java/com/android/adservices/service/consent/ConsentManager.java
index 4762e94..3f885c0 100644
--- a/adservices/service-core/java/com/android/adservices/service/consent/ConsentManager.java
+++ b/adservices/service-core/java/com/android/adservices/service/consent/ConsentManager.java
@@ -230,7 +230,7 @@
boolean enableAppsearchConsentData =
FlagsFactory.getFlags().getEnableAppsearchConsentData();
if (enableAppsearchConsentData) {
- appSearchConsentManager = AppSearchConsentManager.getInstance(context);
+ appSearchConsentManager = AppSearchConsentManager.getInstance();
handleConsentMigrationFromAppSearchIfNeeded(
context,
datastore,
diff --git a/adservices/service-core/java/com/android/adservices/service/topics/BlockedTopicsManager.java b/adservices/service-core/java/com/android/adservices/service/topics/BlockedTopicsManager.java
index c9377b8..20f8d96 100644
--- a/adservices/service-core/java/com/android/adservices/service/topics/BlockedTopicsManager.java
+++ b/adservices/service-core/java/com/android/adservices/service/topics/BlockedTopicsManager.java
@@ -127,9 +127,7 @@
boolean enableAppSearchConsent =
FlagsFactory.getFlags().getEnableAppsearchConsentData();
AppSearchConsentManager appSearchConsentManager =
- enableAppSearchConsent
- ? AppSearchConsentManager.getInstance(context)
- : null;
+ enableAppSearchConsent ? AppSearchConsentManager.getInstance() : null;
sSingleton =
new BlockedTopicsManager(
diff --git a/adservices/tests/unittest/service-core/appsearch/src/com/android/adservices/service/appsearch/AppSearchConsentManagerTest.java b/adservices/tests/unittest/service-core/appsearch/src/com/android/adservices/service/appsearch/AppSearchConsentManagerTest.java
index c5d55f0..a743b2b 100644
--- a/adservices/tests/unittest/service-core/appsearch/src/com/android/adservices/service/appsearch/AppSearchConsentManagerTest.java
+++ b/adservices/tests/unittest/service-core/appsearch/src/com/android/adservices/service/appsearch/AppSearchConsentManagerTest.java
@@ -55,11 +55,13 @@
import com.android.adservices.service.topics.BlockedTopicsManager;
import com.android.adservices.service.ui.enrollment.collection.PrivacySandboxEnrollmentChannelCollection;
import com.android.adservices.service.ui.ux.collection.PrivacySandboxUxCollection;
+import com.android.adservices.shared.testing.common.ApplicationContextSingletonRule;
import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.modules.utils.build.SdkLevel;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
@@ -91,6 +93,9 @@
private static final Topic TOPIC2 = Topic.create(12, 12, 12);
private static final Topic TOPIC3 = Topic.create(123, 123, 123);
+ @Rule
+ public final ApplicationContextSingletonRule appContext = new ApplicationContextSingletonRule();
+
@Before
public void setup() {
mStaticMockSession =
@@ -103,9 +108,9 @@
.initMocks(this)
.startMocking();
ExtendedMockito.doReturn(mAppSearchConsentWorker)
- .when(() -> AppSearchConsentWorker.getInstance(mContext));
+ .when(() -> AppSearchConsentWorker.getInstance());
ExtendedMockito.doReturn(mFlags).when(() -> FlagsFactory.getFlags());
- mAppSearchConsentManager = AppSearchConsentManager.getInstance(mContext);
+ mAppSearchConsentManager = AppSearchConsentManager.getInstance();
ApplicationInfo app1 = new ApplicationInfo();
app1.packageName = PACKAGE_NAME1;
ApplicationInfo app2 = new ApplicationInfo();
diff --git a/adservices/tests/unittest/service-core/appsearch/src/com/android/adservices/service/appsearch/AppSearchConsentWorkerTest.java b/adservices/tests/unittest/service-core/appsearch/src/com/android/adservices/service/appsearch/AppSearchConsentWorkerTest.java
index 102bef9..2c21f71 100644
--- a/adservices/tests/unittest/service-core/appsearch/src/com/android/adservices/service/appsearch/AppSearchConsentWorkerTest.java
+++ b/adservices/tests/unittest/service-core/appsearch/src/com/android/adservices/service/appsearch/AppSearchConsentWorkerTest.java
@@ -57,6 +57,7 @@
import com.android.adservices.service.consent.ConsentManager;
import com.android.adservices.service.ui.enrollment.collection.PrivacySandboxEnrollmentChannelCollection;
import com.android.adservices.service.ui.ux.collection.PrivacySandboxUxCollection;
+import com.android.adservices.shared.testing.common.ApplicationContextSingletonRule;
import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.google.common.collect.ImmutableList;
@@ -94,11 +95,15 @@
@Mock
Flags mMockFlags;
- @Rule
+ @Rule(order = 0)
+ public final SdkLevelSupportRule sdkLevelRule = SdkLevelSupportRule.forAtLeastS();
+
+ @Rule(order = 1)
public final AdServicesDeviceSupportedRule adServicesDeviceSupportedRule =
new AdServicesDeviceSupportedRule();
- @Rule public final SdkLevelSupportRule sdkLevelRule = SdkLevelSupportRule.forAtLeastS();
+ @Rule(order = 2)
+ public final ApplicationContextSingletonRule appContext = new ApplicationContextSingletonRule();
@Before
public void setup() {
@@ -141,7 +146,7 @@
/* userId= */ any(),
eq(API_TYPE),
any()));
- boolean result = AppSearchConsentWorker.getInstance(mContext).getConsent(API_TYPE);
+ boolean result = AppSearchConsentWorker.getInstance().getConsent(API_TYPE);
assertThat(result).isFalse();
// Confirm that the right value is returned even when it is true.
@@ -154,7 +159,7 @@
/* userId= */ any(),
eq(API_TYPE),
any()));
- boolean result2 = AppSearchConsentWorker.getInstance(mContext).getConsent(API_TYPE);
+ boolean result2 = AppSearchConsentWorker.getInstance().getConsent(API_TYPE);
assertThat(result2).isTrue();
} finally {
if (staticMockSessionLocal != null) {
@@ -178,7 +183,7 @@
assertThrows(
RuntimeException.class,
() ->
- AppSearchConsentWorker.getInstance(mContext)
+ AppSearchConsentWorker.getInstance()
.setConsent(API_TYPE, CONSENTED));
assertThat(e.getMessage()).isEqualTo(ConsentConstants.ERROR_MESSAGE_APPSEARCH_FAILURE);
} finally {
@@ -201,7 +206,7 @@
.startMocking();
initSuccessResponse();
// Verify that no exception is thrown.
- AppSearchConsentWorker.getInstance(mContext).setConsent(API_TYPE, CONSENTED);
+ AppSearchConsentWorker.getInstance().setConsent(API_TYPE, CONSENTED);
} finally {
if (staticMockSessionLocal != null) {
staticMockSessionLocal.finishMocking();
@@ -224,8 +229,7 @@
.thenReturn(mockUserHandle);
Mockito.when(mockUserHandle.getIdentifier()).thenReturn(UID);
String result =
- AppSearchConsentWorker.getInstance(mContext)
- .getUserIdentifierFromBinderCallingUid();
+ AppSearchConsentWorker.getInstance().getUserIdentifierFromBinderCallingUid();
assertThat(result).isEqualTo("" + UID);
} finally {
if (staticMockSessionLocal != null) {
@@ -305,8 +309,7 @@
() ->
AppSearchAppConsentDao.readConsentData(
any(), any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.getAppsWithConsent(TEST)).isNotNull();
assertThat(appSearchConsentWorker.getAppsWithConsent(TEST)).isEmpty();
@@ -342,8 +345,7 @@
() ->
AppSearchAppConsentDao.readConsentData(
any(), any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.getAppsWithConsent(TEST)).isNotNull();
assertThat(appSearchConsentWorker.getAppsWithConsent(TEST)).isEmpty();
@@ -380,8 +382,7 @@
Futures.immediateFailedFuture(new ExecutionException("test", null)));
ExtendedMockito.doReturn(future)
.when(() -> AppSearchDao.deleteData(any(), any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(
RuntimeException.class,
@@ -408,8 +409,7 @@
FluentFuture future = FluentFuture.from(Futures.immediateFuture(result));
ExtendedMockito.doReturn(future)
.when(() -> AppSearchDao.deleteData(any(), any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
// No exceptions are thrown.
appSearchConsentWorker.clearAppsWithConsent(TEST);
} finally {
@@ -435,8 +435,7 @@
() ->
AppSearchAppConsentDao.readConsentData(
any(), any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
// No exceptions are thrown.
assertThat(appSearchConsentWorker.addAppWithConsent(consentType, TEST)).isTrue();
ExtendedMockito.verify(
@@ -471,8 +470,7 @@
Futures.immediateFailedFuture(new ExecutionException("test", null)));
when(dao.writeData(any(), any(), any())).thenReturn(future);
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.addAppWithConsent(consentType, TEST)).isFalse();
} finally {
if (staticMockSessionLocal != null) {
@@ -503,8 +501,7 @@
FluentFuture future = FluentFuture.from(Futures.immediateFuture(result));
when(dao.writeData(any(), any(), any())).thenReturn(future);
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
// No exceptions are thrown.
assertThat(appSearchConsentWorker.addAppWithConsent(consentType, TEST)).isTrue();
verify(dao, atLeastOnce()).getApps();
@@ -532,8 +529,7 @@
() ->
AppSearchAppConsentDao.readConsentData(
any(), any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
// No exceptions are thrown.
appSearchConsentWorker.removeAppWithConsent(consentType, TEST);
ExtendedMockito.verify(
@@ -568,8 +564,7 @@
Futures.immediateFailedFuture(new ExecutionException("test", null)));
when(dao.writeData(any(), any(), any())).thenReturn(future);
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(
RuntimeException.class,
@@ -605,8 +600,7 @@
FluentFuture future = FluentFuture.from(Futures.immediateFuture(result));
when(dao.writeData(any(), any(), any())).thenReturn(future);
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
// No exceptions are thrown.
appSearchConsentWorker.removeAppWithConsent(consentType, TEST);
verify(dao, atLeastOnce()).getApps();
@@ -643,8 +637,7 @@
AppSearchNotificationDao.wasNotificationDisplayed(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.wasNotificationDisplayed()).isEqualTo(displayed);
} finally {
if (staticMockSessionLocal != null) {
@@ -678,8 +671,7 @@
AppSearchNotificationDao.wasGaUxNotificationDisplayed(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.wasGaUxNotificationDisplayed()).isEqualTo(displayed);
} finally {
if (staticMockSessionLocal != null) {
@@ -708,7 +700,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
if (isBetaUx) {
RuntimeException e =
assertThrows(
@@ -759,11 +751,11 @@
when(AppSearchNotificationDao.wasGaUxNotificationDisplayed(
any(), any(), any(), any()))
.thenReturn(false);
- AppSearchConsentWorker.getInstance(mContext).recordNotificationDisplayed(true);
+ AppSearchConsentWorker.getInstance().recordNotificationDisplayed(true);
} else {
when(AppSearchNotificationDao.wasNotificationDisplayed(any(), any(), any(), any()))
.thenReturn(false);
- AppSearchConsentWorker.getInstance(mContext).recordGaUxNotificationDisplayed(true);
+ AppSearchConsentWorker.getInstance().recordGaUxNotificationDisplayed(true);
}
} finally {
if (staticMockSessionLocal != null) {
@@ -789,8 +781,7 @@
AppSearchInteractionsDao.getPrivacySandboxFeatureType(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.getPrivacySandboxFeature()).isEqualTo(feature);
} finally {
if (staticMockSessionLocal != null) {
@@ -810,7 +801,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(
RuntimeException.class,
@@ -840,7 +831,7 @@
// Verify that no exception is thrown.
PrivacySandboxFeatureType feature =
PrivacySandboxFeatureType.PRIVACY_SANDBOX_FIRST_CONSENT;
- AppSearchConsentWorker.getInstance(mContext).setCurrentPrivacySandboxFeature(feature);
+ AppSearchConsentWorker.getInstance().setCurrentPrivacySandboxFeature(feature);
} finally {
if (staticMockSessionLocal != null) {
staticMockSessionLocal.finishMocking();
@@ -865,8 +856,7 @@
AppSearchInteractionsDao.getManualInteractions(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.getUserManualInteractionWithConsent()).isEqualTo(umi);
} finally {
if (staticMockSessionLocal != null) {
@@ -886,7 +876,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
int interactions = ConsentManager.MANUAL_INTERACTIONS_RECORDED;
RuntimeException e =
assertThrows(
@@ -916,7 +906,7 @@
when(AppSearchInteractionsDao.getRowId(any(), any())).thenReturn("" + UID);
// Verify that no exception is thrown.
int interactions = ConsentManager.MANUAL_INTERACTIONS_RECORDED;
- AppSearchConsentWorker.getInstance(mContext)
+ AppSearchConsentWorker.getInstance()
.recordUserManualInteractionWithConsent(interactions);
} finally {
if (staticMockSessionLocal != null) {
@@ -941,8 +931,7 @@
AppSearchTopicsConsentDao.getBlockedTopics(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.getBlockedTopics()).isEqualTo(mTopics);
} finally {
if (staticMockSessionLocal != null) {
@@ -962,7 +951,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(RuntimeException.class, () -> worker.recordBlockedTopic(TOPIC1));
assertThat(e.getMessage()).isEqualTo(ConsentConstants.ERROR_MESSAGE_APPSEARCH_FAILURE);
@@ -994,8 +983,7 @@
AppSearchTopicsConsentDao.readConsentData(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.recordBlockedTopic(TOPIC1);
} finally {
if (staticMockSessionLocal != null) {
@@ -1028,8 +1016,7 @@
when(dao.writeData(any(), any(), any()))
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.recordBlockedTopic(TOPIC1);
verify(dao).addBlockedTopic(TOPIC1);
verify(dao).writeData(any(), any(), any());
@@ -1057,7 +1044,7 @@
() ->
AppSearchTopicsConsentDao.readConsentData(
any(), any(), any(), any()));
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
when(dao.writeData(any(), any(), any()))
.thenReturn(
FluentFuture.from(
@@ -1095,8 +1082,7 @@
AppSearchTopicsConsentDao.readConsentData(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.recordUnblockedTopic(TOPIC1);
} finally {
if (staticMockSessionLocal != null) {
@@ -1129,8 +1115,7 @@
when(dao.writeData(any(), any(), any()))
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.recordUnblockedTopic(TOPIC1);
verify(dao).removeBlockedTopic(TOPIC1);
verify(dao).writeData(any(), any(), any());
@@ -1153,7 +1138,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(RuntimeException.class, () -> worker.clearBlockedTopics());
assertThat(e.getMessage()).isEqualTo(ConsentConstants.ERROR_MESSAGE_APPSEARCH_FAILURE);
@@ -1176,8 +1161,7 @@
.initMocks(this)
.startMocking();
initSuccessResponse();
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
// Verify no exceptions are thrown.
appSearchConsentWorker.clearBlockedTopics();
} finally {
@@ -1246,8 +1230,7 @@
.startMocking();
ExtendedMockito.doReturn(isAdIdEnabled)
.when(() -> AppSearchUxStatesDao.readIsAdIdEnabled(any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.isAdIdEnabled()).isEqualTo(isAdIdEnabled);
} finally {
if (staticMockSessionLocal != null) {
@@ -1279,8 +1262,7 @@
when(dao.writeData(any(), any(), any()))
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.setAdIdEnabled(true);
verify(dao).setAdIdEnabled(anyBoolean());
verify(dao).writeData(any(), any(), any());
@@ -1311,7 +1293,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(
RuntimeException.class, () -> worker.setAdIdEnabled(isAdIdEnabled));
@@ -1344,8 +1326,7 @@
.startMocking();
ExtendedMockito.doReturn(isU18Account)
.when(() -> AppSearchUxStatesDao.readIsU18Account(any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.isU18Account()).isEqualTo(isU18Account);
} finally {
if (staticMockSessionLocal != null) {
@@ -1377,8 +1358,7 @@
when(dao.writeData(any(), any(), any()))
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.setU18Account(true);
verify(dao).setU18Account(anyBoolean());
verify(dao).writeData(any(), any(), any());
@@ -1409,7 +1389,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(RuntimeException.class, () -> worker.setU18Account(isU18Account));
assertThat(e.getMessage()).isEqualTo(ConsentConstants.ERROR_MESSAGE_APPSEARCH_FAILURE);
@@ -1444,8 +1424,7 @@
() ->
AppSearchUxStatesDao.readIsEntryPointEnabled(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.isEntryPointEnabled()).isEqualTo(isEntryPointEnabled);
} finally {
if (staticMockSessionLocal != null) {
@@ -1477,8 +1456,7 @@
when(dao.writeData(any(), any(), any()))
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.setEntryPointEnabled(true);
verify(dao).setEntryPointEnabled(anyBoolean());
verify(dao).writeData(any(), any(), any());
@@ -1509,7 +1487,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(
RuntimeException.class,
@@ -1546,8 +1524,7 @@
() ->
AppSearchUxStatesDao.readIsAdultAccount(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.isAdultAccount()).isEqualTo(isAdultAccount);
} finally {
if (staticMockSessionLocal != null) {
@@ -1576,7 +1553,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(
RuntimeException.class, () -> worker.setAdultAccount(isAdultAccount));
@@ -1611,8 +1588,7 @@
when(dao.writeData(any(), any(), any()))
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.setAdultAccount(true);
verify(dao).setAdultAccount(anyBoolean());
verify(dao).writeData(any(), any(), any());
@@ -1647,8 +1623,7 @@
() ->
AppSearchUxStatesDao.readIsU18NotificationDisplayed(
any(), any(), any(), any()));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.wasU18NotificationDisplayed())
.isEqualTo(wasU18NotificationDisplayed);
} finally {
@@ -1678,7 +1653,7 @@
.initMocks(this)
.startMocking();
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(
RuntimeException.class,
@@ -1714,8 +1689,7 @@
when(dao.writeData(any(), any(), any()))
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
- AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker appSearchConsentWorker = AppSearchConsentWorker.getInstance();
appSearchConsentWorker.setU18NotificationDisplayed(true);
verify(dao).setU18NotificationDisplayed(anyBoolean());
verify(dao).writeData(any(), any(), any());
@@ -1741,7 +1715,7 @@
ExtendedMockito.doReturn(ux)
.when(() -> AppSearchUxStatesDao.readUx(any(), any(), any(), any()));
AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.getUx()).isEqualTo(ux);
}
} finally {
@@ -1764,7 +1738,7 @@
for (PrivacySandboxUxCollection ux : PrivacySandboxUxCollection.values()) {
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e = assertThrows(RuntimeException.class, () -> worker.setUx(ux));
assertThat(e.getMessage())
.isEqualTo(ConsentConstants.ERROR_MESSAGE_APPSEARCH_FAILURE);
@@ -1802,7 +1776,7 @@
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker.getInstance();
appSearchConsentWorker.setUx(ux);
verify(dao).setUx(ux.toString());
verify(dao).writeData(any(), any(), any());
@@ -1834,7 +1808,7 @@
AppSearchUxStatesDao.readEnrollmentChannel(
any(), any(), any(), any(), any()));
AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker.getInstance();
assertThat(appSearchConsentWorker.getEnrollmentChannel(ux)).isEqualTo(channel);
}
}
@@ -1860,7 +1834,7 @@
for (PrivacySandboxEnrollmentChannelCollection channel :
ux.getEnrollmentChannelCollection()) {
initFailureResponse();
- AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance();
RuntimeException e =
assertThrows(
RuntimeException.class,
@@ -1905,7 +1879,7 @@
.thenReturn(FluentFuture.from(Futures.immediateFuture(result)));
AppSearchConsentWorker appSearchConsentWorker =
- AppSearchConsentWorker.getInstance(mContext);
+ AppSearchConsentWorker.getInstance();
appSearchConsentWorker.setEnrollmentChannel(ux, channel);
verify(dao).setEnrollmentChannel(channel.toString());
verify(dao).writeData(any(), any(), any());