diff options
author | Geoffrey Borggaard <geoffreyb@google.com> | 2013-08-02 18:16:27 -0400 |
---|---|---|
committer | Geoffrey Borggaard <geoffreyb@google.com> | 2013-08-06 17:24:37 -0400 |
commit | fe21d9aaa8a8c7f8a759805ba021b59dd821e4fe (patch) | |
tree | 6ff78c7c639f19c38e8e9af211b27155eea0f3b9 /src/com/android/settings/RestrictedSettingsFragment.java | |
parent | d98d2abda6ce097c6473bb40e36810fa13a66403 (diff) | |
download | packages_apps_Settings-fe21d9aaa8a8c7f8a759805ba021b59dd821e4fe.tar.gz packages_apps_Settings-fe21d9aaa8a8c7f8a759805ba021b59dd821e4fe.tar.bz2 packages_apps_Settings-fe21d9aaa8a8c7f8a759805ba021b59dd821e4fe.zip |
Pin protect more screens.
When these screens are locked down with user restrictions,
it should prompt the user for the restrictions pin before allowing
access to the settings screen.
Change-Id: Iadbb087da2d9470b855ea0bea89f2da1ffb9e854
Diffstat (limited to 'src/com/android/settings/RestrictedSettingsFragment.java')
-rw-r--r-- | src/com/android/settings/RestrictedSettingsFragment.java | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/src/com/android/settings/RestrictedSettingsFragment.java b/src/com/android/settings/RestrictedSettingsFragment.java index 55c264c3e..ebf2bcf34 100644 --- a/src/com/android/settings/RestrictedSettingsFragment.java +++ b/src/com/android/settings/RestrictedSettingsFragment.java @@ -25,11 +25,16 @@ import android.os.UserManager; /** * Base class for settings activities that should be pin protected when in restricted mode. * The constructor for this class will take the restriction key that this screen should be - * locked by. If {@link UserManager.hasRestrictionsPin()} and {@link UserManager.hasUserRestriction(String)} returns true for the - * restriction key, then the user will hav + * locked by. If {@link UserManager.hasRestrictionsPin()} and + * {@link UserManager.hasUserRestriction(String)} returns true for the restriction key, then + * the user will have to enter the restrictions pin before seeing the Settings screen. * + * If this settings screen should be pin protected whenever + * {@link UserManager.hasUserRestriction(String)} returns true, pass in + * {@link RESTRICTIONS_PIN_SET} to the constructor instead of a restrictions key. */ public class RestrictedSettingsFragment extends SettingsPreferenceFragment { + protected static final String RESTRICTIONS_PIN_SET = "restrictions_pin_set"; // Should be unique across all settings screens that use this. private static final int REQUEST_PIN_CHALLENGE = 12309; @@ -45,21 +50,22 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment { private final String mRestrictionKey; - public RestrictedSettingsFragment(String restrictedFlag) { - mRestrictionKey = restrictedFlag; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); + /** + * @param restrictionKey The restriction key to check before pin protecting + * this settings page. Pass in {@link RESTRICTIONS_PIN_SET} if it should + * be PIN protected whenever a restrictions pin is set. Pass in + * null if it should never be PIN protected. + */ + public RestrictedSettingsFragment(String restrictionKey) { + mRestrictionKey = restrictionKey; } @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); + mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); + if (icicle != null) { mChallengeSucceeded = icicle.getBoolean(KEY_CHALLENGE_SUCCEEDED, false); mChallengeRequested = icicle.getBoolean(KEY_CHALLENGE_REQUESTED, false); @@ -79,8 +85,7 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment { @Override public void onResume() { super.onResume(); - if (mUserManager.hasUserRestriction(mRestrictionKey) - && mUserManager.hasRestrictionsPin()) { + if (shouldBePinProtected(mRestrictionKey)) { ensurePin(); } } @@ -121,7 +126,40 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment { * Used to determine if the settings UI should disable UI. */ protected boolean isRestrictedAndNotPinProtected() { + if (mRestrictionKey == null || RESTRICTIONS_PIN_SET.equals(mRestrictionKey)) { + return false; + } return mUserManager.hasUserRestriction(mRestrictionKey) && !mUserManager.hasRestrictionsPin(); } + + /** + * Called to trigger the pin entry if the given restriction key is locked down. + * @param restrictionsKey The restriction key or {@link RESTRICTIONS_PIN_SET} if + * pin entry should get triggered if there is a pin set. + */ + protected boolean restrictionsPinCheck(String restrictionsKey) { + if (shouldBePinProtected(restrictionsKey) && !mChallengeSucceeded) { + ensurePin(); + return false; + } else { + return true; + } + } + + protected boolean hasChallengeSucceeded() { + return mChallengeSucceeded; + } + + /** + * Returns true if this restrictions key is locked down. + */ + protected boolean shouldBePinProtected(String restrictionKey) { + if (restrictionKey == null) { + return false; + } + boolean restricted = RESTRICTIONS_PIN_SET.equals(restrictionKey) + || mUserManager.hasUserRestriction(restrictionKey); + return restricted && mUserManager.hasRestrictionsPin(); + } } |