am 71decb7b: Merge "Restriction pin changes."

* commit '71decb7b072d69613083285cee6014d37b2e6ef8':
  Restriction pin changes.
This commit is contained in:
Jason Monk
2013-08-08 15:51:20 -07:00
committed by Android Git Automerger
7 changed files with 98 additions and 40 deletions

View File

@@ -80,7 +80,8 @@
android:persistent="false" android:persistent="false"
android:fragment="com.android.settings.TrustedCredentialsSettings"/> android:fragment="com.android.settings.TrustedCredentialsSettings"/>
<Preference android:title="@string/credentials_install" <Preference android:key="credentials_install"
android:title="@string/credentials_install"
android:summary="@string/credentials_install_summary" android:summary="@string/credentials_install_summary"
android:persistent="false"> android:persistent="false">
<intent android:action="android.credentials.INSTALL" <intent android:action="android.credentials.INSTALL"

View File

@@ -54,7 +54,6 @@ import android.preference.CheckBoxPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup; import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.provider.Settings; import android.provider.Settings;
@@ -210,7 +209,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
= new ArrayList<CheckBoxPreference>(); = new ArrayList<CheckBoxPreference>();
private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>(); private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
private final HashSet<Preference> mProtectedByRestrictionsPrefs = new HashSet<Preference>();
// To track whether a confirmation dialog was clicked. // To track whether a confirmation dialog was clicked.
private boolean mDialogClicked; private boolean mDialogClicked;
@@ -362,12 +360,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
} }
} }
private void protectByRestrictions(Preference pref) {
if (pref != null) {
mProtectedByRestrictionsPrefs.add(pref);
}
}
private CheckBoxPreference findAndInitCheckboxPref(String key) { private CheckBoxPreference findAndInitCheckboxPref(String key) {
CheckBoxPreference pref = (CheckBoxPreference) findPreference(key); CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
if (pref == null) { if (pref == null) {
@@ -1178,11 +1170,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (mProtectedByRestrictionsPrefs.contains(preference) if (super.onPreferenceTreeClick(preferenceScreen, preference)) {
&& !restrictionsPinCheck(RESTRICTIONS_PIN_SET)) { return true;
return false;
} }
if (Utils.isMonkeyRunning()) { if (Utils.isMonkeyRunning()) {
return false; return false;
} }

View File

@@ -16,11 +16,15 @@
package com.android.settings; package com.android.settings;
import java.util.HashSet;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserManager; 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. * 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 String mRestrictionKey;
private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
/** /**
* @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
@@ -162,4 +168,30 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|| mUserManager.hasUserRestriction(restrictionKey); || mUserManager.hasUserRestriction(restrictionKey);
return restricted && mUserManager.hasRestrictionsPin(); 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);
}
} }

View File

@@ -45,7 +45,6 @@ import android.util.Log;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
/** /**
@@ -75,6 +74,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
private static final String KEY_SHOW_PASSWORD = "show_password"; private static final String KEY_SHOW_PASSWORD = "show_password";
private static final String KEY_CREDENTIAL_STORAGE_TYPE = "credential_storage_type"; private static final String KEY_CREDENTIAL_STORAGE_TYPE = "credential_storage_type";
private static final String KEY_RESET_CREDENTIALS = "reset_credentials"; private static final String KEY_RESET_CREDENTIALS = "reset_credentials";
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_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
private static final String KEY_TOGGLE_VERIFY_APPLICATIONS = "toggle_verify_applications"; private static final String KEY_TOGGLE_VERIFY_APPLICATIONS = "toggle_verify_applications";
private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks"; private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks";
@@ -82,8 +82,6 @@ public class SecuritySettings extends RestrictedSettingsFragment
private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access"; private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive"; private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
private PackageManager mPM; private PackageManager mPM;
DevicePolicyManager mDPM; DevicePolicyManager mDPM;
@@ -245,6 +243,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
// Show password // Show password
mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD); mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD);
mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
// Credential storage // Credential storage
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
@@ -257,7 +256,6 @@ public class SecuritySettings extends RestrictedSettingsFragment
: R.string.credential_storage_type_software; : R.string.credential_storage_type_software;
credentialStorageType.setSummary(storageSummaryRes); credentialStorageType.setSummary(storageSummaryRes);
mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
} else { } else {
removePreference(KEY_CREDENTIALS_MANAGER); removePreference(KEY_CREDENTIALS_MANAGER);
} }
@@ -312,16 +310,12 @@ public class SecuritySettings extends RestrictedSettingsFragment
if (shouldBePinProtected(RESTRICTIONS_PIN_SET)) { if (shouldBePinProtected(RESTRICTIONS_PIN_SET)) {
protectByRestrictions(mToggleAppInstallation); protectByRestrictions(mToggleAppInstallation);
protectByRestrictions(mToggleVerifyApps); protectByRestrictions(mToggleVerifyApps);
protectByRestrictions(mResetCredentials);
protectByRestrictions(root.findPreference(KEY_CREDENTIALS_INSTALL));
} }
return root; return root;
} }
private void protectByRestrictions(Preference pref) {
if (pref != null) {
mProtectedByRestictionsPrefs.add(pref);
}
}
private int getNumEnabledNotificationListeners() { private int getNumEnabledNotificationListeners() {
final String flat = Settings.Secure.getString(getContentResolver(), final String flat = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ENABLED_NOTIFICATION_LISTENERS); Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
@@ -487,11 +481,9 @@ public class SecuritySettings extends RestrictedSettingsFragment
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (mProtectedByRestictionsPrefs.contains(preference) if (ensurePinRestrictedPreference(preference)) {
&& !restrictionsPinCheck(RESTRICTIONS_PIN_SET)) { return true;
return false;
} }
final String key = preference.getKey(); final String key = preference.getKey();
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();

View File

@@ -16,14 +16,18 @@
package com.android.settings; package com.android.settings;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.Fragment; import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.net.http.SslCertificate; import android.net.http.SslCertificate;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserManager;
import android.security.IKeyChainService; import android.security.IKeyChainService;
import android.security.KeyChain; import android.security.KeyChain;
import android.security.KeyChain.KeyChainConnection; import android.security.KeyChain.KeyChainConnection;
@@ -52,6 +56,14 @@ public class TrustedCredentialsSettings extends Fragment {
private static final String TAG = "TrustedCredentialsSettings"; private static final String TAG = "TrustedCredentialsSettings";
private UserManager mUserManager;
private static final int REQUEST_PIN_CHALLENGE = 12309;
// If the restriction PIN is entered correctly.
private boolean mChallengeSucceeded;
private boolean mChallengeRequested;
private enum Tab { private enum Tab {
SYSTEM("system", SYSTEM("system",
R.string.trusted_credentials_system_tab, R.string.trusted_credentials_system_tab,
@@ -142,6 +154,13 @@ public class TrustedCredentialsSettings extends Fragment {
private TabHost mTabHost; private TabHost mTabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
}
@Override public View onCreateView( @Override public View onCreateView(
LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
mTabHost = (TabHost) inflater.inflate(R.layout.trusted_credentials, parent, false); mTabHost = (TabHost) inflater.inflate(R.layout.trusted_credentials, parent, false);
@@ -355,6 +374,11 @@ public class TrustedCredentialsSettings extends Fragment {
removeButton.setText(certHolder.mTab.getButtonLabel(certHolder)); removeButton.setText(certHolder.mTab.getButtonLabel(certHolder));
removeButton.setOnClickListener(new View.OnClickListener() { removeButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) { @Override public void onClick(View v) {
if (mUserManager.hasRestrictionsPin() && !mChallengeSucceeded) {
ensurePin();
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(certHolder.mTab.getButtonConfirmation(certHolder)); builder.setMessage(certHolder.mTab.getButtonConfirmation(certHolder));
builder.setPositiveButton( builder.setPositiveButton(
@@ -379,6 +403,35 @@ public class TrustedCredentialsSettings extends Fragment {
certDialog.show(); certDialog.show();
} }
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_PIN_CHALLENGE) {
mChallengeRequested = false;
if (resultCode == Activity.RESULT_OK) {
mChallengeSucceeded = true;
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
private void ensurePin() {
if (!mChallengeSucceeded) {
final UserManager um = UserManager.get(getActivity());
if (!mChallengeRequested) {
if (um.hasRestrictionsPin()) {
Intent requestPin =
new Intent(Intent.ACTION_RESTRICTIONS_PIN_CHALLENGE);
startActivityForResult(requestPin, REQUEST_PIN_CHALLENGE);
mChallengeRequested = true;
}
}
}
mChallengeSucceeded = false;
}
private class AliasOperation extends AsyncTask<Void, Void, Boolean> { private class AliasOperation extends AsyncTask<Void, Void, Boolean> {
private final CertHolder mCertHolder; private final CertHolder mCertHolder;
private AliasOperation(CertHolder certHolder) { private AliasOperation(CertHolder certHolder) {

View File

@@ -16,7 +16,6 @@
package com.android.settings; package com.android.settings;
import java.util.HashSet;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@@ -75,7 +74,6 @@ public class WirelessSettings extends RestrictedSettingsFragment {
private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1; private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage"; private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
public WirelessSettings() { public WirelessSettings() {
super(null); super(null);
@@ -87,9 +85,8 @@ public class WirelessSettings extends RestrictedSettingsFragment {
*/ */
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (mProtectedByRestictionsPrefs.contains(preference) && !hasChallengeSucceeded()) { if (ensurePinRestrictedPreference(preference)) {
restrictionsPinCheck(RESTRICTIONS_PIN_SET); return true;
return false;
} }
log("onPreferenceTreeClick: preference=" + preference); log("onPreferenceTreeClick: preference=" + preference);
if (preference == mAirplaneModePreference && Boolean.parseBoolean( if (preference == mAirplaneModePreference && Boolean.parseBoolean(
@@ -155,13 +152,6 @@ public class WirelessSettings extends RestrictedSettingsFragment {
} }
} }
private void protectByRestrictions(String key) {
Preference pref = findPreference(key);
if (pref != null) {
mProtectedByRestictionsPrefs.add(pref);
}
}
@Override @Override
public Dialog onCreateDialog(int dialogId) { public Dialog onCreateDialog(int dialogId) {
log("onCreateDialog: dialogId=" + dialogId); log("onCreateDialog: dialogId=" + dialogId);