[Auto-Generated by Rb Toolbox] Add isU18Account bit to persistent datastores.

Test: atest
Bug: b/283694291
Change-Id: I973a0edab4e62171fba51d7dec6d4ed347c00312
diff --git a/adservices/framework/java/android/app/adservices/AdServicesManager.java b/adservices/framework/java/android/app/adservices/AdServicesManager.java
index bc531d2..17d7c32 100644
--- a/adservices/framework/java/android/app/adservices/AdServicesManager.java
+++ b/adservices/framework/java/android/app/adservices/AdServicesManager.java
@@ -493,6 +493,26 @@
         }
     }
 
+    /** Returns whether the isU18Account bit is true. */
+    @RequiresPermission(ACCESS_ADSERVICES_MANAGER)
+    public boolean isU18Account() {
+        try {
+            return mService.isU18Account();
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /** Saves the isU18Account bit. */
+    @RequiresPermission(ACCESS_ADSERVICES_MANAGER)
+    public void setU18Account(boolean isU18Account) {
+        try {
+            mService.setU18Account(isU18Account);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
     /** Returns whether the isEntryPointEnabled bit is true. */
     @RequiresPermission(ACCESS_ADSERVICES_MANAGER)
     public boolean isEntryPointEnabled() {
diff --git a/adservices/framework/java/android/app/adservices/IAdServicesManager.aidl b/adservices/framework/java/android/app/adservices/IAdServicesManager.aidl
index e5fd62f..b9aac08 100644
--- a/adservices/framework/java/android/app/adservices/IAdServicesManager.aidl
+++ b/adservices/framework/java/android/app/adservices/IAdServicesManager.aidl
@@ -194,6 +194,12 @@
 
     void clearConsentForUninstalledApp(in String packageName,in int packageUid);
 
+    /** Returns whether the isU18Account bit is true. */
+    boolean isU18Account();
+
+    /** Saves the isU18Account bit. */
+    void setU18Account(boolean isU18Account);
+
     /** Returns whether the isEntryPointEnabled bit is true. */
     boolean isEntryPointEnabled();
 
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 f24fbd1..8638431 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
@@ -507,6 +507,16 @@
                 .collect(Collectors.toSet());
     }
 
+    /** Save the isU18Account bit. */
+    public void setU18Account(boolean isU18Account) {
+        mAppSearchConsentWorker.setU18Account(isU18Account);
+    }
+
+    /** Returns whether the isU18Account bit is true. */
+    public Boolean isU18Account() {
+        return mAppSearchConsentWorker.isU18Account();
+    }
+
     /** Save the isEntryPointEnabled bit. */
     public void setEntryPointEnabled(boolean isEntryPointEnabled) {
         mAppSearchConsentWorker.setEntryPointEnabled(isEntryPointEnabled);
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 0c515bb..2d0d37e 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
@@ -597,6 +597,45 @@
         throw new RuntimeException(ConsentConstants.ERROR_MESSAGE_APPSEARCH_FAILURE);
     }
 
+    /** Returns whether isU18Account bit is true. */
+    boolean isU18Account() {
+        READ_WRITE_LOCK.readLock().lock();
+        try {
+            return AppSearchUxStatesDao.readIsU18Account(mGlobalSearchSession, mExecutor, mUid);
+        } finally {
+            READ_WRITE_LOCK.readLock().unlock();
+        }
+    }
+
+    /** Saves the isU18Account bit in app search. */
+    void setU18Account(boolean isU18Account) {
+        READ_WRITE_LOCK.writeLock().lock();
+        try {
+            AppSearchUxStatesDao dao =
+                    AppSearchUxStatesDao.readData(mGlobalSearchSession, mExecutor, mUid);
+            if (dao == null) {
+                dao =
+                        new AppSearchUxStatesDao(
+                                AppSearchUxStatesDao.getRowId(mUid),
+                                mUid,
+                                AppSearchUxStatesDao.NAMESPACE,
+                                false,
+                                false,
+                                false,
+                                false);
+            }
+            dao.setU18Account(isU18Account);
+            dao.writeData(mUxStatesSearchSession, mPackageIdentifiers, mExecutor)
+                    .get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
+            LogUtil.d("Wrote the isU18Account bit to AppSearch: " + dao);
+        } catch (InterruptedException | TimeoutException | ExecutionException e) {
+            LogUtil.e("Failed to write the isU18Account to AppSearch ", e);
+            throw new RuntimeException(ConsentConstants.ERROR_MESSAGE_APPSEARCH_FAILURE);
+        } finally {
+            READ_WRITE_LOCK.writeLock().unlock();
+        }
+    }
+
     /** Returns whether isEntryPointEnabled bit is true. */
     boolean isEntryPointEnabled() {
         READ_WRITE_LOCK.readLock().lock();
diff --git a/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchUxStatesDao.java b/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchUxStatesDao.java
index d0b6a67..ef2dd9b 100644
--- a/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchUxStatesDao.java
+++ b/adservices/service-core/java/com/android/adservices/service/appsearch/AppSearchUxStatesDao.java
@@ -216,6 +216,18 @@
                 && this.mIsAdIdEnabled == obj.mIsAdIdEnabled;
     }
 
+    /** Read the isU18Account bit from AppSearch. */
+    public static boolean readIsU18Account(
+            @NonNull ListenableFuture<GlobalSearchSession> searchSession,
+            @NonNull Executor executor,
+            @NonNull String userId) {
+        AppSearchUxStatesDao dao = readData(searchSession, executor, userId);
+        if (dao == null) {
+            return false;
+        }
+        return dao.isU18Account();
+    }
+
     /** Read the isEntryPointEnabled bit from AppSearch. */
     public static boolean readIsEntryPointEnabled(
             @NonNull ListenableFuture<GlobalSearchSession> searchSession,
diff --git a/adservices/service-core/java/com/android/adservices/service/consent/ConsentConstants.java b/adservices/service-core/java/com/android/adservices/service/consent/ConsentConstants.java
index 362454a..e53c878 100644
--- a/adservices/service-core/java/com/android/adservices/service/consent/ConsentConstants.java
+++ b/adservices/service-core/java/com/android/adservices/service/consent/ConsentConstants.java
@@ -83,6 +83,8 @@
     public static final String ERROR_MESSAGE_APPSEARCH_FAILURE =
             "Failed to persist data to AppSearch.";
 
+    public static final String IS_U18_ACCOUNT = "IS_U18_ACCOUNT";
+
     public static final String IS_ENTRY_POINT_ENABLED = "IS_ENTRY_POINT_ENABLED";
 
     public static final String IS_ADULT_ACCOUNT = "IS_ADULT_ACCOUNT";
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 ce31f92..875b3a3 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
@@ -2216,6 +2216,63 @@
                                 .build());
     }
 
+    /** Returns whether the isU18Account bit is true based on consent_source_of_truth. */
+    public Boolean isU18Account() {
+        synchronized (LOCK) {
+            try {
+                switch (mConsentSourceOfTruth) {
+                    case Flags.PPAPI_ONLY:
+                        return mDatastore.get(ConsentConstants.IS_U18_ACCOUNT);
+                    case Flags.SYSTEM_SERVER_ONLY:
+                        // Intentional fallthrough
+                    case Flags.PPAPI_AND_SYSTEM_SERVER:
+                        return mAdServicesManager.isU18Account();
+                    case Flags.APPSEARCH_ONLY:
+                        if (mFlags.getEnableAppsearchConsentData()) {
+                            return mAppSearchConsentManager.isU18Account();
+                        }
+                        break;
+                    default:
+                        LogUtil.e(ConsentConstants.ERROR_MESSAGE_INVALID_CONSENT_SOURCE_OF_TRUTH);
+                        return false;
+                }
+            } catch (RuntimeException e) {
+                LogUtil.e(e, "Get isU18Account bit failed. " + e.getMessage());
+            }
+            return false;
+        }
+    }
+
+    /** Set the U18Account bit to storage based on consent_source_of_truth. */
+    public void setU18Account(boolean isU18Account) {
+        synchronized (LOCK) {
+            try {
+                switch (mConsentSourceOfTruth) {
+                    case Flags.PPAPI_ONLY:
+                        mDatastore.put(ConsentConstants.IS_U18_ACCOUNT, isU18Account);
+                        break;
+                    case Flags.SYSTEM_SERVER_ONLY:
+                        mAdServicesManager.setU18Account(isU18Account);
+                        break;
+                    case Flags.PPAPI_AND_SYSTEM_SERVER:
+                        mDatastore.put(ConsentConstants.IS_U18_ACCOUNT, isU18Account);
+                        mAdServicesManager.setU18Account(isU18Account);
+                        break;
+                    case Flags.APPSEARCH_ONLY:
+                        if (mFlags.getEnableAppsearchConsentData()) {
+                            mAppSearchConsentManager.setU18Account(isU18Account);
+                        }
+                        break;
+                    default:
+                        throw new RuntimeException(
+                                ConsentConstants.ERROR_MESSAGE_INVALID_CONSENT_SOURCE_OF_TRUTH);
+                }
+            } catch (IOException | RuntimeException e) {
+                throw new RuntimeException("setisU18Account operation failed. " + e.getMessage());
+            }
+        }
+    }
+
     /** Returns whether the isEntryPointEnabled bit is true based on consent_source_of_truth. */
     public Boolean isEntryPointEnabled() {
         synchronized (LOCK) {
diff --git a/adservices/service/java/com/android/server/adservices/AdServicesManagerService.java b/adservices/service/java/com/android/server/adservices/AdServicesManagerService.java
index d6d5bbf..d40b250 100644
--- a/adservices/service/java/com/android/server/adservices/AdServicesManagerService.java
+++ b/adservices/service/java/com/android/server/adservices/AdServicesManagerService.java
@@ -1170,6 +1170,41 @@
 
     @Override
     @RequiresPermission(AdServicesPermissions.ACCESS_ADSERVICES_MANAGER)
+    public boolean isU18Account() {
+        enforceAdServicesManagerPermission();
+
+        final int userIdentifier = getUserIdentifierFromBinderCallingUid();
+        LogUtil.v("isU18Account() for User Identifier %d", userIdentifier);
+
+        try {
+            return mUserInstanceManager
+                    .getOrCreateUserConsentManagerInstance(userIdentifier)
+                    .isU18Account();
+        } catch (IOException e) {
+            LogUtil.e(e, "Failed to call isU18Account().");
+            return false;
+        }
+    }
+
+    @Override
+    @RequiresPermission(AdServicesPermissions.ACCESS_ADSERVICES_MANAGER)
+    public void setU18Account(boolean isU18Account) {
+        enforceAdServicesManagerPermission();
+
+        final int userIdentifier = getUserIdentifierFromBinderCallingUid();
+        LogUtil.v("setU18Account() for User Identifier %d", userIdentifier);
+
+        try {
+            mUserInstanceManager
+                    .getOrCreateUserConsentManagerInstance(userIdentifier)
+                    .setU18Account(isU18Account);
+        } catch (IOException e) {
+            LogUtil.e(e, "Failed to call setU18Account().");
+        }
+    }
+
+    @Override
+    @RequiresPermission(AdServicesPermissions.ACCESS_ADSERVICES_MANAGER)
     public boolean isEntryPointEnabled() {
         enforceAdServicesManagerPermission();
 
diff --git a/adservices/service/java/com/android/server/adservices/consent/ConsentManager.java b/adservices/service/java/com/android/server/adservices/consent/ConsentManager.java
index 2b968b9..4291228 100644
--- a/adservices/service/java/com/android/server/adservices/consent/ConsentManager.java
+++ b/adservices/service/java/com/android/server/adservices/consent/ConsentManager.java
@@ -464,6 +464,27 @@
         }
     }
 
+    @VisibleForTesting static final String IS_U18_ACCOUNT = "IS_U18_ACCOUNT";
+
+    /** Returns whether the isU18Account bit is true. */
+    public boolean isU18Account() {
+        synchronized (this) {
+            Boolean isU18Account = mDatastore.get(IS_U18_ACCOUNT);
+            return isU18Account != null ? isU18Account : false;
+        }
+    }
+
+    /** Set the U18Account bit in system server. */
+    public void setU18Account(boolean isU18Account) throws IOException {
+        synchronized (this) {
+            try {
+                mDatastore.put(IS_U18_ACCOUNT, isU18Account);
+            } catch (IOException e) {
+                LogUtil.e(e, "setU18Account operation failed: " + e.getMessage());
+            }
+        }
+    }
+
     @VisibleForTesting static final String IS_ENTRY_POINT_ENABLED = "IS_ENTRY_POINT_ENABLED";
 
     /** Returns whether the isEntryPointEnabled bit is true. */
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchConsentManagerTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchConsentManagerTest.java
index 32697c7..fdecc88 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchConsentManagerTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchConsentManagerTest.java
@@ -555,6 +555,30 @@
     }
 
     @Test
+    public void setU18AccountTest_trueBit() {
+        mAppSearchConsentManager.setU18Account(true);
+        verify(mAppSearchConsentWorker).setU18Account(true);
+    }
+
+    @Test
+    public void setU18AccountTest_falseBit() {
+        mAppSearchConsentManager.setU18Account(false);
+        verify(mAppSearchConsentWorker).setU18Account(false);
+    }
+
+    private void setU18AccountTest(boolean isU18Account) {
+        mAppSearchConsentManager.setU18Account(isU18Account);
+        verify(mAppSearchConsentWorker).setU18Account(isU18Account);
+    }
+
+    @Test
+    public void isU18AccountTest_defaultFalseBit() {
+        when(mAppSearchConsentWorker.isU18Account()).thenReturn(false);
+        assertThat(mAppSearchConsentManager.isU18Account()).isFalse();
+        verify(mAppSearchConsentWorker).isU18Account();
+    }
+
+    @Test
     public void setEntryPointEnabledTest_trueBit() {
         mAppSearchConsentManager.setEntryPointEnabled(true);
         verify(mAppSearchConsentWorker).setEntryPointEnabled(true);
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchConsentWorkerTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchConsentWorkerTest.java
index de812fc..50c4a73 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchConsentWorkerTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchConsentWorkerTest.java
@@ -1170,6 +1170,68 @@
     }
 
     @Test
+    public void isU18AccountTest_trueBit() {
+        isU18AccountTest(true);
+    }
+
+    @Test
+    public void isU18AccountTest_falseBit() {
+        isU18AccountTest(false);
+    }
+
+    private void isU18AccountTest(boolean isU18Account) {
+        MockitoSession staticMockSessionLocal = null;
+        try {
+            staticMockSessionLocal =
+                    ExtendedMockito.mockitoSession()
+                            .spyStatic(AppSearchUxStatesDao.class)
+                            .strictness(Strictness.WARN)
+                            .initMocks(this)
+                            .startMocking();
+            ExtendedMockito.doReturn(isU18Account)
+                    .when(() -> AppSearchUxStatesDao.readIsU18Account(any(), any(), any()));
+            AppSearchConsentWorker appSearchConsentWorker =
+                    AppSearchConsentWorker.getInstance(mContext);
+            assertThat(appSearchConsentWorker.isU18Account()).isEqualTo(isU18Account);
+        } finally {
+            if (staticMockSessionLocal != null) {
+                staticMockSessionLocal.finishMocking();
+            }
+        }
+    }
+
+    @Test
+    public void setU18AccountTest_trueBit() {
+        setU18AccountTest(true);
+    }
+
+    @Test
+    public void setU18AccountTest_falseBit() {
+        setU18AccountTest(false);
+    }
+
+    private void setU18AccountTest(boolean isU18Account) {
+        MockitoSession staticMockSessionLocal = null;
+        try {
+            staticMockSessionLocal =
+                    ExtendedMockito.mockitoSession()
+                            .spyStatic(PlatformStorage.class)
+                            .strictness(Strictness.WARN)
+                            .initMocks(this)
+                            .startMocking();
+            initFailureResponse();
+            AppSearchConsentWorker worker = AppSearchConsentWorker.getInstance(mContext);
+            RuntimeException e =
+                    assertThrows(RuntimeException.class, () -> worker.setU18Account(isU18Account));
+            assertThat(e.getMessage()).isEqualTo(ConsentConstants.ERROR_MESSAGE_APPSEARCH_FAILURE);
+        } finally {
+            if (staticMockSessionLocal != null) {
+                staticMockSessionLocal.finishMocking();
+            }
+        }
+    }
+
+    @Test
     public void isEntryPointEnabledTest_trueBit() {
         isEntryPointEnabledTest(true);
     }
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchUxStatesDaoTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchUxStatesDaoTest.java
index ef64a96..0d8f79c 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchUxStatesDaoTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/appsearch/AppSearchUxStatesDaoTest.java
@@ -175,4 +175,41 @@
                 AppSearchUxStatesDao.readIsAdultAccount(mockSearchSession, mockExecutor, ID2);
         assertThat(result2).isTrue();
     }
+
+    @Test
+    public void isU18AccountTest_nullDao() {
+        ListenableFuture mockSearchSession = Mockito.mock(ListenableFuture.class);
+        Executor mockExecutor = Mockito.mock(Executor.class);
+        ExtendedMockito.doReturn(null)
+                .when(() -> AppSearchDao.readConsentData(any(), any(), any(), any(), any()));
+        boolean result =
+                AppSearchUxStatesDao.readIsU18Account(mockSearchSession, mockExecutor, ID1);
+        assertThat(result).isFalse();
+    }
+
+    @Test
+    public void isU18AccountTest_trueBit() {
+        ListenableFuture mockSearchSession = Mockito.mock(ListenableFuture.class);
+        Executor mockExecutor = Mockito.mock(Executor.class);
+
+        String query = "userId:" + ID1;
+        AppSearchUxStatesDao dao = Mockito.mock(AppSearchUxStatesDao.class);
+        Mockito.when(dao.isU18Account()).thenReturn(false);
+        ExtendedMockito.doReturn(dao)
+                .when(() -> AppSearchDao.readConsentData(any(), any(), any(), any(), eq(query)));
+
+        boolean result =
+                AppSearchUxStatesDao.readIsU18Account(mockSearchSession, mockExecutor, ID1);
+        assertThat(result).isFalse();
+
+        // Confirm that the right value is returned even when it is true.
+        String query2 = "userId:" + ID2;
+        AppSearchUxStatesDao dao2 = Mockito.mock(AppSearchUxStatesDao.class);
+        Mockito.when(dao2.isU18Account()).thenReturn(true);
+        ExtendedMockito.doReturn(dao2)
+                .when(() -> AppSearchDao.readConsentData(any(), any(), any(), any(), eq(query2)));
+        boolean result2 =
+                AppSearchUxStatesDao.readIsU18Account(mockSearchSession, mockExecutor, ID2);
+        assertThat(result2).isTrue();
+    }
 }
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/consent/ConsentManagerTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/consent/ConsentManagerTest.java
index 45c105c..78f23e0 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/consent/ConsentManagerTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/consent/ConsentManagerTest.java
@@ -3613,6 +3613,69 @@
     }
 
     @Test
+    public void isU18AccountTest_SystemServerOnly() throws RemoteException {
+        int consentSourceOfTruth = Flags.SYSTEM_SERVER_ONLY;
+        ConsentManager spyConsentManager =
+                getSpiedConsentManagerForMigrationTesting(
+                        /* isGiven */ false, consentSourceOfTruth);
+
+        assertThat(spyConsentManager.isU18Account()).isFalse();
+
+        verify(mMockIAdServicesManager).isU18Account();
+
+        doReturn(true).when(mMockIAdServicesManager).isU18Account();
+        spyConsentManager.setU18Account(true);
+
+        assertThat(spyConsentManager.isU18Account()).isTrue();
+
+        verify(mMockIAdServicesManager, times(2)).isU18Account();
+        verify(mMockIAdServicesManager).setU18Account(anyBoolean());
+    }
+
+    @Test
+    public void isU18AccountTest_PpApiAndSystemServer() throws RemoteException {
+        int consentSourceOfTruth = Flags.PPAPI_AND_SYSTEM_SERVER;
+        ConsentManager spyConsentManager =
+                getSpiedConsentManagerForMigrationTesting(
+                        /* isGiven */ false, consentSourceOfTruth);
+
+        Boolean isU18Account = spyConsentManager.isU18Account();
+
+        assertThat(isU18Account).isFalse();
+
+        verify(mMockIAdServicesManager).isU18Account();
+
+        doReturn(true).when(mMockIAdServicesManager).isU18Account();
+        spyConsentManager.setU18Account(true);
+
+        assertThat(spyConsentManager.isU18Account()).isTrue();
+
+        verify(mMockIAdServicesManager, times(2)).isU18Account();
+        verify(mMockIAdServicesManager).setU18Account(anyBoolean());
+    }
+
+    @Test
+    public void isU18AccountTest_appSearchOnly() throws RemoteException {
+        int consentSourceOfTruth = Flags.APPSEARCH_ONLY;
+        when(mMockFlags.getEnableAppsearchConsentData()).thenReturn(true);
+        ConsentManager spyConsentManager =
+                getSpiedConsentManagerForMigrationTesting(
+                        /* isGiven */ false, consentSourceOfTruth);
+
+        doReturn(false).when(mAppSearchConsentManager).isU18Account();
+        assertThat(spyConsentManager.isU18Account()).isFalse();
+        verify(mAppSearchConsentManager).isU18Account();
+
+        doReturn(true).when(mAppSearchConsentManager).isU18Account();
+        spyConsentManager.setU18Account(true);
+
+        assertThat(spyConsentManager.isU18Account()).isTrue();
+
+        verify(mAppSearchConsentManager, times(2)).isU18Account();
+        verify(mAppSearchConsentManager).setU18Account(anyBoolean());
+    }
+
+    @Test
     public void isEntryPointEnabledTest_SystemServerOnly() throws RemoteException {
         int consentSourceOfTruth = Flags.SYSTEM_SERVER_ONLY;
         ConsentManager spyConsentManager =
diff --git a/adservices/tests/unittest/system-service/src/com/android/server/adservices/AdServicesManagerServiceTest.java b/adservices/tests/unittest/system-service/src/com/android/server/adservices/AdServicesManagerServiceTest.java
index c70d34a..328900b 100644
--- a/adservices/tests/unittest/system-service/src/com/android/server/adservices/AdServicesManagerServiceTest.java
+++ b/adservices/tests/unittest/system-service/src/com/android/server/adservices/AdServicesManagerServiceTest.java
@@ -1048,6 +1048,18 @@
     }
 
     @Test
+    public void isU18AccountTest() throws IOException {
+        AdServicesManagerService service =
+                spy(new AdServicesManagerService(mSpyContext, mUserInstanceManager));
+
+        disableEnforceAdServicesManagerPermission(service);
+
+        assertThat(service.isU18Account()).isFalse();
+        service.setU18Account(true);
+        assertThat(service.isU18Account()).isTrue();
+    }
+
+    @Test
     public void isEntryPointEnabledTest() throws IOException {
         AdServicesManagerService service =
                 spy(new AdServicesManagerService(mSpyContext, mUserInstanceManager));
diff --git a/adservices/tests/unittest/system-service/src/com/android/server/adservices/consent/ConsentManagerTest.java b/adservices/tests/unittest/system-service/src/com/android/server/adservices/consent/ConsentManagerTest.java
index 40dc554..1fba9ce 100644
--- a/adservices/tests/unittest/system-service/src/com/android/server/adservices/consent/ConsentManagerTest.java
+++ b/adservices/tests/unittest/system-service/src/com/android/server/adservices/consent/ConsentManagerTest.java
@@ -417,6 +417,17 @@
     }
 
     @Test
+    public void isU18AccountTest() throws IOException {
+        ConsentManager consentManager =
+                ConsentManager.createConsentManager(BASE_DIR, /* userIdentifier */ 0);
+
+        assertThat(consentManager.isU18Account()).isFalse();
+        consentManager.setU18Account(true);
+
+        assertThat(consentManager.isU18Account()).isTrue();
+    }
+
+    @Test
     public void isEntryPointEnabledTest() throws IOException {
         ConsentManager consentManager =
                 ConsentManager.createConsentManager(BASE_DIR, /* userIdentifier */ 0);