android:persistent="false"
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:persistent="false">
<intent android:action="android.credentials.INSTALL"
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
-import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.provider.Settings;
= new ArrayList<CheckBoxPreference>();
private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
- private final HashSet<Preference> mProtectedByRestrictionsPrefs = new HashSet<Preference>();
// To track whether a confirmation dialog was clicked.
private boolean mDialogClicked;
}
}
- private void protectByRestrictions(Preference pref) {
- if (pref != null) {
- mProtectedByRestrictionsPrefs.add(pref);
- }
- }
-
private CheckBoxPreference findAndInitCheckboxPref(String key) {
CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
if (pref == null) {
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
- if (mProtectedByRestrictionsPrefs.contains(preference)
- && !restrictionsPinCheck(RESTRICTIONS_PIN_SET)) {
- return false;
+ if (super.onPreferenceTreeClick(preferenceScreen, preference)) {
+ return true;
}
-
if (Utils.isMonkeyRunning()) {
return false;
}
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.
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
|| 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);
+ }
}
import com.android.internal.widget.LockPatternUtils;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
/**
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_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_VERIFY_APPLICATIONS = "toggle_verify_applications";
private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks";
private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
- private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
-
private PackageManager mPM;
DevicePolicyManager mDPM;
// Show password
mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD);
+ mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
// Credential storage
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
: R.string.credential_storage_type_software;
credentialStorageType.setSummary(storageSummaryRes);
- mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
} else {
removePreference(KEY_CREDENTIALS_MANAGER);
}
if (shouldBePinProtected(RESTRICTIONS_PIN_SET)) {
protectByRestrictions(mToggleAppInstallation);
protectByRestrictions(mToggleVerifyApps);
+ protectByRestrictions(mResetCredentials);
+ protectByRestrictions(root.findPreference(KEY_CREDENTIALS_INSTALL));
}
return root;
}
- private void protectByRestrictions(Preference pref) {
- if (pref != null) {
- mProtectedByRestictionsPrefs.add(pref);
- }
- }
-
private int getNumEnabledNotificationListeners() {
final String flat = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
- if (mProtectedByRestictionsPrefs.contains(preference)
- && !restrictionsPinCheck(RESTRICTIONS_PIN_SET)) {
- return false;
+ if (ensurePinRestrictedPreference(preference)) {
+ return true;
}
-
final String key = preference.getKey();
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
mParentFragment = getFragmentManager().findFragmentById(mParentFragmentId);
if (!(mParentFragment instanceof DialogCreatable)) {
throw new IllegalArgumentException(
- (mParentFragment != null
+ (mParentFragment != null
? mParentFragment.getClass().getName()
: mParentFragmentId)
+ " must implement "
package com.android.settings;
+import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment;
+import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.net.http.SslCertificate;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.RemoteException;
+import android.os.UserManager;
import android.security.IKeyChainService;
import android.security.KeyChain;
import android.security.KeyChain.KeyChainConnection;
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 {
SYSTEM("system",
R.string.trusted_credentials_system_tab,
private TabHost mTabHost;
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
+ }
+
+
@Override public View onCreateView(
LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
mTabHost = (TabHost) inflater.inflate(R.layout.trusted_credentials, parent, false);
removeButton.setText(certHolder.mTab.getButtonLabel(certHolder));
removeButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
+ if (mUserManager.hasRestrictionsPin() && !mChallengeSucceeded) {
+ ensurePin();
+ return;
+ }
+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(certHolder.mTab.getButtonConfirmation(certHolder));
builder.setPositiveButton(
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 final CertHolder mCertHolder;
private AliasOperation(CertHolder certHolder) {
package com.android.settings;
-import java.util.HashSet;
import android.app.Activity;
import android.app.AlertDialog;
private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
- private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
public WirelessSettings() {
super(null);
*/
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
- if (mProtectedByRestictionsPrefs.contains(preference) && !hasChallengeSucceeded()) {
- restrictionsPinCheck(RESTRICTIONS_PIN_SET);
- return false;
+ if (ensurePinRestrictedPreference(preference)) {
+ return true;
}
log("onPreferenceTreeClick: preference=" + preference);
if (preference == mAirplaneModePreference && Boolean.parseBoolean(
}
}
- private void protectByRestrictions(String key) {
- Preference pref = findPreference(key);
- if (pref != null) {
- mProtectedByRestictionsPrefs.add(pref);
- }
- }
-
@Override
public Dialog onCreateDialog(int dialogId) {
log("onCreateDialog: dialogId=" + dialogId);