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

Commit f61f11b8 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Removing unknown sources from security settings

The secure setting is deprecated starting from O. Removing it from the
settings UI so the user cannot change it. The unknown sources can be
managed at a more granular level by starting activity for intent
MANAGE_EXTERNAL_SOURCES

Test: Manually tested that the preference is removed and does not
disturb the other settings on the page.

Bug: 33947615

Change-Id: I8dc559d0e6aaaf5bad78fb6e04469d9ab647411d
parent 773a9a12
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -52,12 +52,6 @@
                android:persistent="false"
                android:fragment="com.android.settings.DeviceAdminSettings"/>

        <com.android.settingslib.RestrictedSwitchPreference android:key="toggle_install_applications"
                android:title="@string/install_applications"
                android:summaryOff="@string/install_unknown_applications"
                android:summaryOn="@string/install_unknown_applications"
                settings:useAdditionalSummary="true" />

    </PreferenceCategory>

    <PreferenceCategory android:key="credentials_management"
+2 −81
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 * Gesture lock pattern settings.
 */
public class SecuritySettings extends SettingsPreferenceFragment
        implements OnPreferenceChangeListener, DialogInterface.OnClickListener, Indexable,
        implements OnPreferenceChangeListener, Indexable,
        GearPreference.OnGearClickListener {

    private static final String TAG = "SecuritySettings";
@@ -120,7 +120,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
    private static final String KEY_USER_CREDENTIALS = "user_credentials";
    private static final String KEY_RESET_CREDENTIALS = "credentials_reset";
    private static final String KEY_CREDENTIALS_INSTALL = "credentials_install";
    private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
    private static final String KEY_CREDENTIALS_MANAGER = "credentials_management";
    private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
    private static final String KEY_TRUST_AGENT = "trust_agent";
@@ -137,8 +136,7 @@ public class SecuritySettings extends SettingsPreferenceFragment

    // These switch preferences need special handling since they're not all stored in Settings.
    private static final String SWITCH_PREFERENCE_KEYS[] = {
            KEY_SHOW_PASSWORD, KEY_TOGGLE_INSTALL_APPLICATIONS, KEY_UNIFICATION,
            KEY_VISIBLE_PATTERN_PROFILE
            KEY_SHOW_PASSWORD, KEY_UNIFICATION, KEY_VISIBLE_PATTERN_PROFILE
    };

    // Only allow one trust agent on the platform.
@@ -165,9 +163,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
    private KeyStore mKeyStore;
    private RestrictedPreference mResetCredentials;

    private RestrictedSwitchPreference mToggleAppInstallation;
    private DialogInterface mWarnInstallApps;

    private boolean mIsAdmin;

    private Intent mTrustAgentClickIntent;
@@ -397,26 +392,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
        // Application install
        PreferenceGroup deviceAdminCategory = (PreferenceGroup)
                root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
        mToggleAppInstallation = (RestrictedSwitchPreference) findPreference(
                KEY_TOGGLE_INSTALL_APPLICATIONS);
        mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
        // Side loading of apps.
        // Disable for restricted profiles. For others, check if policy disallows it.
        mToggleAppInstallation.setEnabled(!um.getUserInfo(MY_USER_ID).isRestricted());
        if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
                UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, MY_USER_ID)
                || RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
                        UserManager.DISALLOW_INSTALL_APPS, MY_USER_ID)) {
            mToggleAppInstallation.setEnabled(false);
        }
        if (mToggleAppInstallation.isEnabled()) {
            mToggleAppInstallation.checkRestrictionAndSetDisabled(
                    UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
            if (!mToggleAppInstallation.isDisabledByAdmin()) {
                mToggleAppInstallation.checkRestrictionAndSetDisabled(
                        UserManager.DISALLOW_INSTALL_APPS);
            }
        }

        // Advanced Security features
        PreferenceGroup advancedCategory =
@@ -600,43 +575,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
        return result;
    }

    private boolean isNonMarketAppsAllowed() {
        return Settings.Global.getInt(getContentResolver(),
                                      Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0;
    }

    private void setNonMarketAppsAllowed(boolean enabled) {
        final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
        if (um.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)) {
            return;
        }
        // Change the system setting
        Settings.Global.putInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS,
                                enabled ? 1 : 0);
    }

    private void warnAppInstallation() {
        // TODO: DialogFragment?
        mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle(
                getResources().getString(R.string.error_title))
                .setIcon(com.android.internal.R.drawable.ic_dialog_alert)
                .setMessage(getResources().getString(R.string.install_all_warning))
                .setPositiveButton(android.R.string.yes, this)
                .setNegativeButton(android.R.string.no, this)
                .show();
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        if (dialog == mWarnInstallApps) {
            boolean turnOn = which == DialogInterface.BUTTON_POSITIVE;
            setNonMarketAppsAllowed(turnOn);
            if (mToggleAppInstallation != null) {
                mToggleAppInstallation.setChecked(turnOn);
            }
        }
    }

    @Override
    public void onGearClick(GearPreference p) {
        if (KEY_UNLOCK_SET_OR_CHANGE.equals(p.getKey())) {
@@ -644,14 +582,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mWarnInstallApps != null) {
            mWarnInstallApps.dismiss();
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
@@ -857,15 +787,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
            Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
                    ((Boolean) value) ? 1 : 0);
            lockPatternUtils.setVisiblePasswordEnabled((Boolean) value, MY_USER_ID);
        } else if (KEY_TOGGLE_INSTALL_APPLICATIONS.equals(key)) {
            if ((Boolean) value) {
                mToggleAppInstallation.setChecked(false);
                warnAppInstallation();
                // Don't change Switch status until user makes choice in dialog, so return false.
                result = false;
            } else {
                setNonMarketAppsAllowed(false);
            }
        }
        return result;
    }