Restriction pin changes.

Fixed bug in WirelessSettings where it was asking users for a PIN when
they weren't restricted.  Did this by refactoring the preference level
pin checking into the superclass, where it checks for the restricted mode first.
Also pin protected changes to certificates for restricted users.

Change-Id: I8310fd39f0862159668318fc1360ec6859cc00d5
This commit is contained in:
Geoffrey Borggaard
2013-08-07 14:57:43 -04:00
parent 8a181dd0d1
commit 6e1102d9fa
7 changed files with 98 additions and 40 deletions

View File

@@ -16,11 +16,15 @@
package com.android.settings;
import java.util.HashSet;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserManager;
import android.preference.Preference;
import android.preference.PreferenceScreen;
/**
* Base class for settings activities that should be pin protected when in restricted mode.
@@ -50,6 +54,8 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
private final String mRestrictionKey;
private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
/**
* @param restrictionKey The restriction key to check before pin protecting
* this settings page. Pass in {@link RESTRICTIONS_PIN_SET} if it should
@@ -162,4 +168,30 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|| mUserManager.hasUserRestriction(restrictionKey);
return restricted && mUserManager.hasRestrictionsPin();
}
/**
* If the preference is one that was added by protectByRestrictions(), then it will
* prompt the user for the restrictions pin if they haven't entered it already.
* Intended to be called at the top of onPreferenceTreeClick. If this function returns
* true, then onPreferenceTreeClick should return true.
*/
boolean ensurePinRestrictedPreference(Preference preference) {
return mProtectedByRestictionsPrefs.contains(preference)
&& !restrictionsPinCheck(RESTRICTIONS_PIN_SET);
}
/**
* Call this with any preferences that should require the PIN to be entered
* before they are accessible.
*/
protected void protectByRestrictions(Preference pref) {
if (pref != null) {
mProtectedByRestictionsPrefs.add(pref);
}
}
protected void protectByRestrictions(String key) {
Preference pref = findPreference(key);
protectByRestrictions(pref);
}
}