Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5359d270 authored by Nino Jagar's avatar Nino Jagar
Browse files

Use DeviceConfig flag instead of aconfig flag

Bug: 308610589
Test: Units
Flag: EXEMPT
Change-Id: I066549740051378acfdc3bd400b6afc6c7de2684
parent 24af7a43
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_OK;
import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_SECURITY_EXCEPTION;
import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_TRUE;
import static android.view.contentcapture.ContentCaptureSession.STATE_DISABLED;
import static android.view.contentprotection.flags.Flags.parseGroupsConfigEnabled;

import static com.android.internal.util.FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__ACCEPT_DATA_SHARE_REQUEST;
import static com.android.internal.util.FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__DATA_SHARE_ERROR_CLIENT_PIPE_FAIL;
@@ -1037,9 +1036,6 @@ public class ContentCaptureManagerService extends
        if (verbose) {
            Slog.v(TAG, "parseContentProtectionGroupsConfig: " + config);
        }
        if (!parseGroupsConfigEnabled()) {
            return Collections.emptyList();
        }
        if (config == null) {
            return Collections.emptyList();
        }
+0 −6
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.server.contentprotection;

import static android.view.contentprotection.flags.Flags.blocklistUpdateEnabled;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Handler;
@@ -130,10 +128,6 @@ public class ContentProtectionAllowlistManager {
    }

    private void handlePackagesChanged() {
        if (!blocklistUpdateEnabled()) {
            return;
        }

        /**
         * PackageMonitor callback can be invoked more than once in a matter of milliseconds on the
         * same monitor instance for the same package (eg: b/295969873). This check acts both as a
+6 −38
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.server.contentcapture;

import static android.view.contentprotection.flags.Flags.FLAG_PARSE_GROUPS_CONFIG_ENABLED;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.anyInt;
@@ -548,48 +546,21 @@ public class ContentCaptureManagerServiceTest {
    }

    @Test
    public void parseContentProtectionGroupsConfig_disabled_null() {
        mSetFlagsRule.disableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig(null)).isEmpty();
    }

    @Test
    public void parseContentProtectionGroupsConfig_disabled_empty() {
        mSetFlagsRule.disableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig("")).isEmpty();
    }

    @Test
    public void parseContentProtectionGroupsConfig_disabled_notEmpty() {
        mSetFlagsRule.disableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig("a")).isEmpty();
    }

    @Test
    public void parseContentProtectionGroupsConfig_enabled_null() {
        mSetFlagsRule.enableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
    public void parseContentProtectionGroupsConfig_null() {
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig(null)).isEmpty();
    }

    @Test
    public void parseContentProtectionGroupsConfig_enabled_empty() {
        mSetFlagsRule.enableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
    public void parseContentProtectionGroupsConfig_empty() {
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig("")).isEmpty();
    }

    @Test
    public void parseContentProtectionGroupsConfig_enabled_singleValue() {
        mSetFlagsRule.enableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
    public void parseContentProtectionGroupsConfig_singleValue() {
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig("a"))
@@ -597,8 +568,7 @@ public class ContentCaptureManagerServiceTest {
    }

    @Test
    public void parseContentProtectionGroupsConfig_enabled_multipleValues() {
        mSetFlagsRule.enableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
    public void parseContentProtectionGroupsConfig_multipleValues() {
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig("a,b"))
@@ -606,8 +576,7 @@ public class ContentCaptureManagerServiceTest {
    }

    @Test
    public void parseContentProtectionGroupsConfig_enabled_multipleGroups() {
        mSetFlagsRule.enableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
    public void parseContentProtectionGroupsConfig_multipleGroups() {
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig("a,b;c;d,e"))
@@ -615,8 +584,7 @@ public class ContentCaptureManagerServiceTest {
    }

    @Test
    public void parseContentProtectionGroupsConfig_enabled_emptyValues() {
        mSetFlagsRule.enableFlags(FLAG_PARSE_GROUPS_CONFIG_ENABLED);
    public void parseContentProtectionGroupsConfig_emptyValues() {
        ContentCaptureManagerService service = new ContentCaptureManagerService(sContext);

        assertThat(service.parseContentProtectionGroupsConfig("a;b;;;c;,d,,e,;,;"))
+9 −135
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.server.contentprotection;

import static android.view.contentprotection.flags.Flags.FLAG_BLOCKLIST_UPDATE_ENABLED;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.eq;
@@ -107,9 +105,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void start_updateEnabled_firstTime_beforeDelay() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);

    public void start_firstTime_beforeDelay() {
        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.dispatchAll();

@@ -121,9 +117,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void start_updateEnabled_firstTime_afterDelay() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);

    public void start_firstTime_afterDelay() {
        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.moveTimeForward(DELAY_MS);
        mTestLooper.dispatchNext();
@@ -137,8 +131,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void start_updateEnabled_secondTime() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
    public void start_secondTime() {
        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.moveTimeForward(DELAY_MS);
        mTestLooper.dispatchNext();
@@ -154,55 +147,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void start_updateDisabled_firstTime_beforeDelay() {
        mSetFlagsRule.disableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);

        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.dispatchAll();

        assertThat(mHandler.hasMessagesOrCallbacks()).isTrue();
        verifyZeroInteractions(mMockContentCaptureManagerService);
        verifyZeroInteractions(mMockPackageMonitor);
        verifyZeroInteractions(mMockRemoteContentProtectionService);
        verifyZeroInteractions(mMockAllowlistCallback);
    }

    @Test
    public void start_updateDisabled_firstTime_afterDelay() {
        mSetFlagsRule.disableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);

        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.moveTimeForward(DELAY_MS);
        mTestLooper.dispatchNext();

        assertThat(mHandler.hasMessagesOrCallbacks()).isFalse();
        verifyZeroInteractions(mMockContentCaptureManagerService);
        verify(mMockPackageMonitor).register(any(), eq(UserHandle.ALL), eq(mHandler));
        verify(mMockPackageMonitor, never()).unregister();
        verifyZeroInteractions(mMockRemoteContentProtectionService);
        verifyZeroInteractions(mMockAllowlistCallback);
    }

    @Test
    public void start_updateDisabled_secondTime() {
        mSetFlagsRule.disableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.moveTimeForward(DELAY_MS);
        mTestLooper.dispatchNext();

        mContentProtectionAllowlistManager.start(DELAY_MS);

        assertThat(mHandler.hasMessagesOrCallbacks()).isFalse();
        verifyZeroInteractions(mMockContentCaptureManagerService);
        verify(mMockPackageMonitor).register(any(), eq(UserHandle.ALL), eq(mHandler));
        verify(mMockPackageMonitor, never()).unregister();
        verifyZeroInteractions(mMockRemoteContentProtectionService);
        verifyZeroInteractions(mMockAllowlistCallback);
    }

    @Test
    public void stop_updateEnabled_notStarted() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
    public void stop_notStarted() {
        doThrow(new IllegalStateException("NOT REGISTERED")).when(mMockPackageMonitor).unregister();

        mContentProtectionAllowlistManager.stop();
@@ -216,8 +161,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void stop_updateEnabled_started_beforeDelay() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
    public void stop_started_beforeDelay() {
        doThrow(new IllegalStateException("NOT REGISTERED")).when(mMockPackageMonitor).unregister();
        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.dispatchAll();
@@ -233,8 +177,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void stop_updateEnabled_started_afterDelay() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
    public void stop_started_afterDelay() {
        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.moveTimeForward(DELAY_MS);
        mTestLooper.dispatchNext();
@@ -249,55 +192,6 @@ public class ContentProtectionAllowlistManagerTest {
        verifyZeroInteractions(mMockAllowlistCallback);
    }

    @Test
    public void stop_updateDisabled_notStarted() {
        mSetFlagsRule.disableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        doThrow(new IllegalStateException("NOT REGISTERED")).when(mMockPackageMonitor).unregister();

        mContentProtectionAllowlistManager.stop();

        assertThat(mHandler.hasMessagesOrCallbacks()).isFalse();
        verifyZeroInteractions(mMockContentCaptureManagerService);
        verify(mMockPackageMonitor, never()).register(any(), any(), any());
        verify(mMockPackageMonitor).unregister();
        verifyZeroInteractions(mMockRemoteContentProtectionService);
        verifyZeroInteractions(mMockAllowlistCallback);
    }

    @Test
    public void stop_updateDisabled_started_beforeDelay() {
        mSetFlagsRule.disableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        doThrow(new IllegalStateException("NOT REGISTERED")).when(mMockPackageMonitor).unregister();
        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.dispatchAll();

        mContentProtectionAllowlistManager.stop();

        assertThat(mHandler.hasMessagesOrCallbacks()).isFalse();
        verifyZeroInteractions(mMockContentCaptureManagerService);
        verify(mMockPackageMonitor, never()).register(any(), any(), any());
        verify(mMockPackageMonitor).unregister();
        verifyZeroInteractions(mMockRemoteContentProtectionService);
        verifyZeroInteractions(mMockAllowlistCallback);
    }

    @Test
    public void stop_updateDisabled_started_afterDelay() {
        mSetFlagsRule.disableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        mContentProtectionAllowlistManager.start(DELAY_MS);
        mTestLooper.moveTimeForward(DELAY_MS);
        mTestLooper.dispatchNext();

        mContentProtectionAllowlistManager.stop();

        assertThat(mHandler.hasMessagesOrCallbacks()).isFalse();
        verifyZeroInteractions(mMockContentCaptureManagerService);
        verify(mMockPackageMonitor).register(any(), eq(UserHandle.ALL), eq(mHandler));
        verify(mMockPackageMonitor).unregister();
        verifyZeroInteractions(mMockRemoteContentProtectionService);
        verifyZeroInteractions(mMockAllowlistCallback);
    }

    @Test
    public void start_afterStop_beforeDelay() {
        mContentProtectionAllowlistManager.start(DELAY_MS);
@@ -375,21 +269,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void handlePackagesChanged_updateDisabled() {
        mSetFlagsRule.disableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        mUseMockPackageMonitor = false;
        ContentProtectionAllowlistManager manager = new TestContentProtectionAllowlistManager();

        manager.mPackageMonitor.onSomePackagesChanged();

        verifyZeroInteractions(mMockContentCaptureManagerService);
        verifyZeroInteractions(mMockRemoteContentProtectionService);
        verifyZeroInteractions(mMockAllowlistCallback);
    }

    @Test
    public void handlePackagesChanged_updateEnabled_noService() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
    public void handlePackagesChanged_noService() {
        mUseMockPackageMonitor = false;
        ContentProtectionAllowlistManager manager = new TestContentProtectionAllowlistManager();

@@ -401,8 +281,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void handlePackagesChanged_updateEnabled_withService() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
    public void handlePackagesChanged_withService() {
        mUseMockPackageMonitor = false;
        ContentProtectionAllowlistManager manager = new TestContentProtectionAllowlistManager();
        when(mMockContentCaptureManagerService.createRemoteContentProtectionService())
@@ -416,8 +295,7 @@ public class ContentProtectionAllowlistManagerTest {
    }

    @Test
    public void handlePackagesChanged_updateEnabled_withServiceException() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
    public void handlePackagesChanged_withServiceException() {
        mUseMockPackageMonitor = false;
        ContentProtectionAllowlistManager manager = new TestContentProtectionAllowlistManager();
        when(mMockContentCaptureManagerService.createRemoteContentProtectionService())
@@ -436,7 +314,6 @@ public class ContentProtectionAllowlistManagerTest {

    @Test
    public void handlePackagesChanged_rateLimit_noService() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        mUseMockPackageMonitor = false;
        ContentProtectionAllowlistManager manager = new TestContentProtectionAllowlistManager();

@@ -450,7 +327,6 @@ public class ContentProtectionAllowlistManagerTest {

    @Test
    public void handlePackagesChanged_rateLimit_beforeTimeout() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        mUseMockPackageMonitor = false;
        ContentProtectionAllowlistManager manager = new TestContentProtectionAllowlistManager();
        when(mMockContentCaptureManagerService.createRemoteContentProtectionService())
@@ -467,7 +343,6 @@ public class ContentProtectionAllowlistManagerTest {

    @Test
    public void handlePackagesChanged_rateLimit_afterTimeout() {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        mUseMockPackageMonitor = false;
        ContentProtectionAllowlistManager manager =
                new TestContentProtectionAllowlistManager(/* timeoutMs= */ 0L);
@@ -485,7 +360,6 @@ public class ContentProtectionAllowlistManagerTest {

    @Test
    public void handlePackagesChanged_rateLimit_afterUpdate() throws Exception {
        mSetFlagsRule.enableFlags(FLAG_BLOCKLIST_UPDATE_ENABLED);
        mUseMockPackageMonitor = false;
        mUseMockAllowlistCallback = false;
        ContentProtectionAllowlistManager manager = new TestContentProtectionAllowlistManager();