Fixes for pin-restricted settings.
- Reprompt for pin after screen has been locked and unlocked. - For protected preferences, store the Preference and continue if pin entry is successful. - Protect whole UserSettings and DevelopmentSettings pages. Bug: 10543207 Change-Id: If1d4b31ca94a8cfc103625b74385bcd0bdd3d88b
This commit is contained in:
@@ -74,7 +74,6 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Displays preferences for application developers.
|
* Displays preferences for application developers.
|
||||||
@@ -224,7 +223,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
private boolean mUnavailable;
|
private boolean mUnavailable;
|
||||||
|
|
||||||
public DevelopmentSettings() {
|
public DevelopmentSettings() {
|
||||||
super(null /* Don't ask for restrictions pin on creation. */);
|
super(RESTRICTIONS_PIN_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -276,13 +275,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
disableForUser(mPassword);
|
disableForUser(mPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldBePinProtected(RESTRICTIONS_PIN_SET)) {
|
|
||||||
protectByRestrictions(mEnableAdb);
|
|
||||||
protectByRestrictions(mClearAdbKeys);
|
|
||||||
protectByRestrictions(mEnableTerminal);
|
|
||||||
protectByRestrictions(mPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
mDebugAppPref = findPreference(DEBUG_APP_KEY);
|
mDebugAppPref = findPreference(DEBUG_APP_KEY);
|
||||||
mAllPrefs.add(mDebugAppPref);
|
mAllPrefs.add(mDebugAppPref);
|
||||||
mWaitForDebugger = findAndInitCheckboxPref(WAIT_FOR_DEBUGGER_KEY);
|
mWaitForDebugger = findAndInitCheckboxPref(WAIT_FOR_DEBUGGER_KEY);
|
||||||
@@ -1212,9 +1204,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||||
if (super.onPreferenceTreeClick(preferenceScreen, preference)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (Utils.isMonkeyRunning()) {
|
if (Utils.isMonkeyRunning()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -19,12 +19,14 @@ package com.android.settings;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for settings activities that should be pin protected when in restricted mode.
|
* Base class for settings activities that should be pin protected when in restricted mode.
|
||||||
@@ -38,17 +40,22 @@ import android.preference.PreferenceScreen;
|
|||||||
* {@link RESTRICTIONS_PIN_SET} to the constructor instead of a restrictions key.
|
* {@link RESTRICTIONS_PIN_SET} to the constructor instead of a restrictions key.
|
||||||
*/
|
*/
|
||||||
public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
||||||
|
|
||||||
protected static final String RESTRICTIONS_PIN_SET = "restrictions_pin_set";
|
protected static final String RESTRICTIONS_PIN_SET = "restrictions_pin_set";
|
||||||
|
|
||||||
|
private static final String EXTRA_PREFERENCE = "pref";
|
||||||
|
private static final String EXTRA_CHECKBOX_STATE = "isChecked";
|
||||||
// Should be unique across all settings screens that use this.
|
// Should be unique across all settings screens that use this.
|
||||||
private static final int REQUEST_PIN_CHALLENGE = 12309;
|
private static final int REQUEST_PIN_CHALLENGE = 12309;
|
||||||
|
|
||||||
private static final String KEY_CHALLENGE_SUCCEEDED = "chsc";
|
private static final String KEY_CHALLENGE_SUCCEEDED = "chsc";
|
||||||
private static final String KEY_CHALLENGE_REQUESTED = "chrq";
|
private static final String KEY_CHALLENGE_REQUESTED = "chrq";
|
||||||
|
private static final String KEY_RESUME_ACTION_BUNDLE = "rsmb";
|
||||||
|
|
||||||
// If the restriction PIN is entered correctly.
|
// If the restriction PIN is entered correctly.
|
||||||
private boolean mChallengeSucceeded;
|
private boolean mChallengeSucceeded;
|
||||||
private boolean mChallengeRequested;
|
private boolean mChallengeRequested;
|
||||||
|
private Bundle mResumeActionBundle;
|
||||||
|
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
|
|
||||||
@@ -56,6 +63,17 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
|
private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
|
||||||
|
|
||||||
|
// Receiver to clear pin status when the screen is turned off.
|
||||||
|
private BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
mChallengeSucceeded = false;
|
||||||
|
if (shouldBePinProtected(mRestrictionKey)) {
|
||||||
|
ensurePin(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param restrictionKey The restriction key to check before pin protecting
|
* @param restrictionKey The restriction key to check before pin protecting
|
||||||
* this settings page. Pass in {@link RESTRICTIONS_PIN_SET} if it should
|
* this settings page. Pass in {@link RESTRICTIONS_PIN_SET} if it should
|
||||||
@@ -75,6 +93,7 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
if (icicle != null) {
|
if (icicle != null) {
|
||||||
mChallengeSucceeded = icicle.getBoolean(KEY_CHALLENGE_SUCCEEDED, false);
|
mChallengeSucceeded = icicle.getBoolean(KEY_CHALLENGE_SUCCEEDED, false);
|
||||||
mChallengeRequested = icicle.getBoolean(KEY_CHALLENGE_REQUESTED, false);
|
mChallengeRequested = icicle.getBoolean(KEY_CHALLENGE_REQUESTED, false);
|
||||||
|
mResumeActionBundle = icicle.getBundle(KEY_RESUME_ACTION_BUNDLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +102,9 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
outState.putBoolean(KEY_CHALLENGE_REQUESTED, mChallengeRequested);
|
outState.putBoolean(KEY_CHALLENGE_REQUESTED, mChallengeRequested);
|
||||||
|
if (mResumeActionBundle != null) {
|
||||||
|
outState.putBundle(KEY_RESUME_ACTION_BUNDLE, mResumeActionBundle);
|
||||||
|
}
|
||||||
if (getActivity().isChangingConfigurations()) {
|
if (getActivity().isChangingConfigurations()) {
|
||||||
outState.putBoolean(KEY_CHALLENGE_SUCCEEDED, mChallengeSucceeded);
|
outState.putBoolean(KEY_CHALLENGE_SUCCEEDED, mChallengeSucceeded);
|
||||||
}
|
}
|
||||||
@@ -92,17 +114,52 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (shouldBePinProtected(mRestrictionKey)) {
|
if (shouldBePinProtected(mRestrictionKey)) {
|
||||||
ensurePin();
|
ensurePin(null);
|
||||||
|
} else {
|
||||||
|
// If the whole screen is not pin protected, reset mChallengeSucceeded so next
|
||||||
|
// time user uses a protected preference, they are prompted for pin again.
|
||||||
|
mChallengeSucceeded = false;
|
||||||
}
|
}
|
||||||
|
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
|
||||||
|
filter.addAction(Intent.ACTION_USER_PRESENT);
|
||||||
|
getActivity().registerReceiver(mScreenOffReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
getActivity().unregisterReceiver(mScreenOffReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == REQUEST_PIN_CHALLENGE) {
|
if (requestCode == REQUEST_PIN_CHALLENGE) {
|
||||||
|
Bundle resumeActionBundle = mResumeActionBundle;
|
||||||
|
mResumeActionBundle = null;
|
||||||
mChallengeRequested = false;
|
mChallengeRequested = false;
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
|
||||||
mChallengeSucceeded = true;
|
mChallengeSucceeded = true;
|
||||||
|
String prefKey = resumeActionBundle == null ?
|
||||||
|
null : resumeActionBundle.getString(EXTRA_PREFERENCE);
|
||||||
|
if (prefKey != null) {
|
||||||
|
Preference pref = findPreference(prefKey);
|
||||||
|
if (pref != null) {
|
||||||
|
// Make sure the checkbox state is the same as it was when we launched the
|
||||||
|
// pin challenge.
|
||||||
|
if (pref instanceof CheckBoxPreference
|
||||||
|
&& resumeActionBundle.containsKey(EXTRA_CHECKBOX_STATE)) {
|
||||||
|
boolean isChecked =
|
||||||
|
resumeActionBundle.getBoolean(EXTRA_CHECKBOX_STATE, false);
|
||||||
|
((CheckBoxPreference)pref).setChecked(isChecked);
|
||||||
|
}
|
||||||
|
if (!onPreferenceTreeClick(getPreferenceScreen(), pref)) {
|
||||||
|
Intent prefIntent = pref.getIntent();
|
||||||
|
if (prefIntent != null) {
|
||||||
|
pref.getContext().startActivity(prefIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (!isDetached()) {
|
} else if (!isDetached()) {
|
||||||
finishFragment();
|
finishFragment();
|
||||||
}
|
}
|
||||||
@@ -112,13 +169,20 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensurePin() {
|
private void ensurePin(Preference preference) {
|
||||||
if (!mChallengeSucceeded) {
|
if (!mChallengeSucceeded) {
|
||||||
final UserManager um = UserManager.get(getActivity());
|
final UserManager um = UserManager.get(getActivity());
|
||||||
if (!mChallengeRequested) {
|
if (!mChallengeRequested) {
|
||||||
if (um.hasRestrictionsPin()) {
|
if (um.hasRestrictionsPin()) {
|
||||||
Intent requestPin =
|
mResumeActionBundle = new Bundle();
|
||||||
new Intent(Intent.ACTION_RESTRICTIONS_PIN_CHALLENGE);
|
if (preference != null) {
|
||||||
|
mResumeActionBundle.putString(EXTRA_PREFERENCE, preference.getKey());
|
||||||
|
if (preference instanceof CheckBoxPreference) {
|
||||||
|
mResumeActionBundle.putBoolean(EXTRA_CHECKBOX_STATE,
|
||||||
|
((CheckBoxPreference)preference).isChecked());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Intent requestPin = new Intent(Intent.ACTION_RESTRICTIONS_PIN_CHALLENGE);
|
||||||
startActivityForResult(requestPin, REQUEST_PIN_CHALLENGE);
|
startActivityForResult(requestPin, REQUEST_PIN_CHALLENGE);
|
||||||
mChallengeRequested = true;
|
mChallengeRequested = true;
|
||||||
}
|
}
|
||||||
@@ -144,9 +208,9 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
* @param restrictionsKey The restriction key or {@link RESTRICTIONS_PIN_SET} if
|
* @param restrictionsKey The restriction key or {@link RESTRICTIONS_PIN_SET} if
|
||||||
* pin entry should get triggered if there is a pin set.
|
* pin entry should get triggered if there is a pin set.
|
||||||
*/
|
*/
|
||||||
protected boolean restrictionsPinCheck(String restrictionsKey) {
|
protected boolean restrictionsPinCheck(String restrictionsKey, Preference preference) {
|
||||||
if (shouldBePinProtected(restrictionsKey) && !mChallengeSucceeded) {
|
if (shouldBePinProtected(restrictionsKey) && !mChallengeSucceeded) {
|
||||||
ensurePin();
|
ensurePin(preference);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
@@ -177,7 +241,7 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
*/
|
*/
|
||||||
boolean ensurePinRestrictedPreference(Preference preference) {
|
boolean ensurePinRestrictedPreference(Preference preference) {
|
||||||
return mProtectedByRestictionsPrefs.contains(preference)
|
return mProtectedByRestictionsPrefs.contains(preference)
|
||||||
&& !restrictionsPinCheck(RESTRICTIONS_PIN_SET);
|
&& !restrictionsPinCheck(RESTRICTIONS_PIN_SET, preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -135,7 +135,7 @@ public class UserSettings extends RestrictedSettingsFragment
|
|||||||
private boolean mIsOwner = UserHandle.myUserId() == UserHandle.USER_OWNER;
|
private boolean mIsOwner = UserHandle.myUserId() == UserHandle.USER_OWNER;
|
||||||
|
|
||||||
public UserSettings() {
|
public UserSettings() {
|
||||||
super(null);
|
super(RestrictedSettingsFragment.RESTRICTIONS_PIN_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
@@ -718,9 +718,6 @@ public class UserSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference pref) {
|
public boolean onPreferenceClick(Preference pref) {
|
||||||
if (pref == mAddUser && !restrictionsPinCheck(RESTRICTIONS_PIN_SET)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (pref == mMePreference) {
|
if (pref == mMePreference) {
|
||||||
Intent editProfile;
|
Intent editProfile;
|
||||||
if (!mProfileExists) {
|
if (!mProfileExists) {
|
||||||
@@ -780,9 +777,7 @@ public class UserSettings extends RestrictedSettingsFragment
|
|||||||
int userId = ((UserPreference) v.getTag()).getUserId();
|
int userId = ((UserPreference) v.getTag()).getUserId();
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case UserPreference.DELETE_ID:
|
case UserPreference.DELETE_ID:
|
||||||
if (restrictionsPinCheck(RESTRICTIONS_PIN_SET)) {
|
onRemoveUserClicked(userId);
|
||||||
onRemoveUserClicked(userId);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case UserPreference.SETTINGS_ID:
|
case UserPreference.SETTINGS_ID:
|
||||||
onManageUserClicked(userId, false);
|
onManageUserClicked(userId, false);
|
||||||
|
Reference in New Issue
Block a user