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

Commit c39dcc1c authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Don't show developer options to secondary users

Show just a message that developer options are not available for the user.

Also fix silent exit of AddAccount operation by showing a toast that user
cannot add accounts.

Bug: 7409523
Bug: 8519646
Bug: 7304007

Change-Id: Id3f430d568d6b7151ac55f86dbc0ef91803fa10c
parent 34a62601
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3036,6 +3036,8 @@
    <!-- Development Settings summary.  The summary of the item to take the user to Development settings.  Development settings are settings meant for application developers. -->
    <string name="development_settings_summary">Set options for app development</string>
    <!-- Setting checkbox title for Whether to enable USB debugging support on the phone. -->
    <!-- Error message for users that aren't allowed to modify developer options [CHAR LIMIT=none] -->
    <string name="development_settings_not_available">Developer options are not available for this user</string>
    <string name="enable_adb">USB debugging</string>
    <!-- Setting checkbox summary for Whether to enable USB debugging support on the phone -->
    <string name="enable_adb_summary">Debug mode when USB is connected</string>
@@ -4369,6 +4371,8 @@
    <string name="user_cannot_manage_message" product="tablet">Only the tablet\'s owner can manage users.</string>
    <!-- Message to secondary users that only owner can manage users [CHAR LIMIT=none] -->
    <string name="user_cannot_manage_message" product="default">Only the phone\'s owner can manage users.</string>
    <!-- Message to limited users that they cannot add accounts [CHAR LIMIT=100] -->
    <string name="user_cannot_add_accounts_message">Limited users cannot add accounts</string>

    <!-- User details remove user menu [CHAR LIMIT=20] -->
    <string name="user_remove_user_menu">Delete <xliff:g id="user_name">%1$s</xliff:g> from this device</string>
+24 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.os.ServiceManager;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -64,6 +65,7 @@ import android.view.IWindowManager;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashSet;
@@ -202,6 +204,8 @@ public class DevelopmentSettings extends PreferenceFragment
    private Dialog mAdbDialog;
    private Dialog mAdbKeysDialog;

    private boolean mUnavailable;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
@@ -211,6 +215,12 @@ public class DevelopmentSettings extends PreferenceFragment
                ServiceManager.getService(Context.BACKUP_SERVICE));
        mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);

        if (android.os.Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER) {
            mUnavailable = true;
            setPreferenceScreen(new PreferenceScreen(getActivity(), null));
            return;
        }

        addPreferencesFromResource(R.xml.development_prefs);

        mEnableAdb = findAndInitCheckboxPref(ENABLE_ADB);
@@ -333,6 +343,10 @@ public class DevelopmentSettings extends PreferenceFragment
        final int padding = activity.getResources().getDimensionPixelSize(
                R.dimen.action_bar_switch_padding);
        mEnabledSwitch.setPaddingRelative(0, 0, padding, 0);
        if (mUnavailable) {
            mEnabledSwitch.setEnabled(false);
            return;
        }
        mEnabledSwitch.setOnCheckedChangeListener(this);
    }

@@ -379,6 +393,16 @@ public class DevelopmentSettings extends PreferenceFragment
    public void onResume() {
        super.onResume();

        if (mUnavailable) {
            // Show error message
            TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
            getListView().setEmptyView(emptyView);
            if (emptyView != null) {
                emptyView.setText(R.string.development_settings_not_available);
            }
            return;
        }

        if (mDpm.getMaximumTimeToLock(null) > 0) {
            // A DeviceAdmin has specified a maximum time until the device
            // will lock...  in this case we can't allow the user to turn
+10 −2
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.UserManager;
import android.util.Log;
import android.widget.Toast;

import com.android.settings.R;
import com.android.settings.Utils;

import java.io.IOException;
@@ -124,9 +126,15 @@ public class AddAccountSettings extends Activity {
        }

        final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
        if (mAddAccountCalled || um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
        if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
            // We aren't allowed to add an account.
            Toast.makeText(this, R.string.user_cannot_add_accounts_message, Toast.LENGTH_LONG)
                    .show();
            finish();
            return;
        }
        if (mAddAccountCalled) {
            // We already called add account - maybe the callback was lost.
            // Or we aren't allowed to add an account.
            finish();
            return;
        }
+1 −0
Original line number Diff line number Diff line
@@ -332,6 +332,7 @@ public class ManageAccountsSettings extends AccountPreferenceBase
                getPreferenceScreen().addPreference(preference);
                if (mFirstAccount == null) {
                    mFirstAccount = account;
                    getActivity().invalidateOptionsMenu();
                }
            }
        }