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

Commit b2852a41 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Disallow Package Installer to be disabled"

parents 95ba1ab6 e6689241
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() {