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

Commit e6689241 authored by tmfang's avatar tmfang
Browse files

Disallow Package Installer to be disabled

Test: visual, robotest
Fixes: 128950485
Change-Id: Id50a62fe3288761f68a3588b154db24573418068
parent dee673b0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -156,6 +156,11 @@
        com.android.settings.intelligence
    </string>

    <!-- Package Installer package name -->
    <string name="config_package_installer_package_name" translatable="false">
        com.android.packageinstaller
    </string>

    <!-- Settings intelligence interaction log intent action -->
    <string name="config_settingsintelligence_log_action" translatable="false"></string>

+16 −4
Original line number Diff line number Diff line
@@ -140,9 +140,9 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
        if (defaultSms != null) {
            keepEnabledPackages.add(defaultSms.getPackageName());
        }
        // Keep Settings intelligence enabled, otherwise search feature will be disabled.
        keepEnabledPackages.add(
                mContext.getString(R.string.config_settingsintelligence_package_name));

        keepEnabledPackages.addAll(getEnabledPackageWhitelist());

        final LocationManager locationManager =
                (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
        final String locationHistoryPackage = locationManager.getExtraLocationControllerPackage();
@@ -152,6 +152,19 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
        return keepEnabledPackages;
    }

    private Set<String> getEnabledPackageWhitelist() {
        final Set<String> keepEnabledPackages = new ArraySet<>();

        // Keep Settings intelligence enabled, otherwise search feature will be disabled.
        keepEnabledPackages.add(
                mContext.getString(R.string.config_settingsintelligence_package_name));

        // Keep Package Installer enabled.
        keepEnabledPackages.add(mContext.getString(R.string.config_package_installer_package_name));

        return keepEnabledPackages;
    }

    private static class CurrentUserAndManagedProfilePolicyInstalledAppCounter
            extends InstalledAppCounter {
        private NumberOfAppsCallback mCallback;
@@ -219,5 +232,4 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
            mCallback.onListOfAppsResult(list);
        }
    }

}
+46 −4
Original line number Diff line number Diff line
@@ -265,8 +265,6 @@ public final class ApplicationFeatureProviderImplTest {
        final String testSms = "com.android.test.defaultsms";
        final String testLocationHistory = "com.android.test.location.history";

        final String settingsIntelligence = RuntimeEnvironment.application.getString(
                R.string.config_settingsintelligence_package_name);
        ShadowSmsApplication.setDefaultSmsApplication(new ComponentName(testSms, "receiver"));
        ShadowDefaultDialerManager.setDefaultDialerApplication(testDialer);

@@ -280,8 +278,52 @@ public final class ApplicationFeatureProviderImplTest {
        final Set<String> keepEnabledPackages = mProvider.getKeepEnabledPackages();

        final List<String> expectedPackages = Arrays.asList(testDialer, testSms,
                settingsIntelligence, testLocationHistory);
        assertThat(keepEnabledPackages).containsExactlyElementsIn(expectedPackages);
                testLocationHistory);
        assertThat(keepEnabledPackages).containsAllIn(expectedPackages);
    }

    @Test
    @Config(shadows = {ShadowSmsApplication.class, ShadowDefaultDialerManager.class})
    public void getKeepEnabledPackages_shouldContainSettingsIntelligence() {
        final String testDialer = "com.android.test.defaultdialer";
        final String testSms = "com.android.test.defaultsms";
        final String testLocationHistory = "com.android.test.location.history";

        ShadowSmsApplication.setDefaultSmsApplication(new ComponentName(testSms, "receiver"));
        ShadowDefaultDialerManager.setDefaultDialerApplication(testDialer);

        // Spy the real context to mock LocationManager.
        Context spyContext = spy(RuntimeEnvironment.application);
        when(mLocationManager.getExtraLocationControllerPackage()).thenReturn(testLocationHistory);
        when(spyContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager);

        ReflectionHelpers.setField(mProvider, "mContext", spyContext);

        final Set<String> whitelist = mProvider.getKeepEnabledPackages();

        assertThat(whitelist).contains("com.android.settings.intelligence");
    }

    @Test
    @Config(shadows = {ShadowSmsApplication.class, ShadowDefaultDialerManager.class})
    public void getKeepEnabledPackages_shouldContainPackageInstaller() {
        final String testDialer = "com.android.test.defaultdialer";
        final String testSms = "com.android.test.defaultsms";
        final String testLocationHistory = "com.android.test.location.history";

        ShadowSmsApplication.setDefaultSmsApplication(new ComponentName(testSms, "receiver"));
        ShadowDefaultDialerManager.setDefaultDialerApplication(testDialer);

        // Spy the real context to mock LocationManager.
        Context spyContext = spy(RuntimeEnvironment.application);
        when(mLocationManager.getExtraLocationControllerPackage()).thenReturn(testLocationHistory);
        when(spyContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager);

        ReflectionHelpers.setField(mProvider, "mContext", spyContext);

        final Set<String> whitelist = mProvider.getKeepEnabledPackages();

        assertThat(whitelist).contains("com.android.packageinstaller");
    }

    private void setUpUsersAndInstalledApps() {