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

Commit 3ad1355d authored by Nino Jagar's avatar Nino Jagar
Browse files

Postpone checking for content protection permissions

Bug: 275732576
Test: Added tests and manual end to end
Change-Id: I5eba46c8e75df4d2b27f919fdc061412c9873862
parent aaaf84c8
Loading
Loading
Loading
Loading
+10 −14
Original line number Diff line number Diff line
@@ -805,20 +805,7 @@ public class ContentCaptureManagerService extends
    @Nullable
    private ComponentName getContentProtectionServiceComponentName() {
        String flatComponentName = getContentProtectionServiceFlatComponentName();
        ComponentName componentName = ComponentName.unflattenFromString(flatComponentName);
        if (componentName == null) {
            return null;
        }

        // Check permissions by trying to construct {@link ContentCaptureServiceInfo}
        try {
            createContentProtectionServiceInfo(componentName);
        } catch (Exception ex) {
            // Swallow, exception was already logged
            return null;
        }

        return componentName;
        return ComponentName.unflattenFromString(flatComponentName);
    }

    /** @hide */
@@ -853,6 +840,15 @@ public class ContentCaptureManagerService extends
                return null;
            }
        }

        // Check permissions by trying to construct {@link ContentCaptureServiceInfo}
        try {
            createContentProtectionServiceInfo(mContentProtectionServiceComponentName);
        } catch (Exception ex) {
            // Swallow, exception was already logged
            return null;
        }

        return createRemoteContentProtectionService(mContentProtectionServiceComponentName);
    }

+16 −13
Original line number Diff line number Diff line
@@ -142,18 +142,6 @@ public class ContentCaptureManagerServiceTest {
        verifyZeroInteractions(mMockContentProtectionBlocklistManager);
    }

    @Test
    public void constructor_contentProtection_serviceInfoThrows_noBlocklistManager() {
        mDevCfgEnableContentProtectionReceiver = true;
        mContentProtectionServiceInfoConstructorShouldThrow = true;

        mContentCaptureManagerService = new TestContentCaptureManagerService();

        assertThat(mContentProtectionBlocklistManagersCreated).isEqualTo(0);
        assertThat(mContentProtectionServiceInfosCreated).isEqualTo(1);
        verifyZeroInteractions(mMockContentProtectionBlocklistManager);
    }

    @Test
    public void constructor_contentProtection_enabled_createsBlocklistManager() {
        mDevCfgEnableContentProtectionReceiver = true;
@@ -161,7 +149,7 @@ public class ContentCaptureManagerServiceTest {
        mContentCaptureManagerService = new TestContentCaptureManagerService();

        assertThat(mContentProtectionBlocklistManagersCreated).isEqualTo(1);
        assertThat(mContentProtectionServiceInfosCreated).isEqualTo(1);
        assertThat(mContentProtectionServiceInfosCreated).isEqualTo(0);
        verify(mMockContentProtectionBlocklistManager).updateBlocklist(anyInt());
    }

@@ -357,6 +345,21 @@ public class ContentCaptureManagerServiceTest {
        mContentCaptureManagerService = new TestContentCaptureManagerService();
        mContentCaptureManagerService.mDevCfgEnableContentProtectionReceiver = false;

        mContentCaptureManagerService
                .getContentCaptureManagerServiceStub()
                .onLoginDetected(PARCELED_EVENTS);

        assertThat(mContentProtectionServiceInfosCreated).isEqualTo(0);
        assertThat(mRemoteContentProtectionServicesCreated).isEqualTo(0);
        verifyZeroInteractions(mMockRemoteContentProtectionService);
    }

    @Test
    public void onLoginDetected_invalidPermissions() {
        mDevCfgEnableContentProtectionReceiver = true;
        mContentProtectionServiceInfoConstructorShouldThrow = true;
        mContentCaptureManagerService = new TestContentCaptureManagerService();

        mContentCaptureManagerService
                .getContentCaptureManagerServiceStub()
                .onLoginDetected(PARCELED_EVENTS);