Settings: Add setting to clear adb public keys
Change-Id: I1d5ab7a83a3b7b23f0cd51305d965f45793eb853
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 419cb11..44d8170 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2987,6 +2987,8 @@
<string name="enable_adb">USB debugging</string>
<!-- Setting checkbox summary for Whether to enable USB debugging support on the phone -->
<string name="enable_adb_summary">Debug mode when USB is connected</string>
+ <!-- Setting title to revoke secure USB debugging authorizations -->
+ <string name="clear_adb_keys">Revoke USB debugging authorizations</string>
<!-- [CHAR LIMIT=NONE] Setting checkbox title for Whether to include bug report item in power menu. -->
<string name="bugreport_in_power">Power menu bug reports</string>
<!-- [CHAR LIMIT=NONE] Setting checkbox summary for Whether to include bug report item in power -->
@@ -3003,6 +3005,8 @@
<string name="adb_warning_title">Allow USB debugging?</string>
<!-- Warning text to user about the implications of enabling USB debugging -->
<string name="adb_warning_message">USB debugging is intended for development purposes only. Use it to copy data between your computer and your device, install apps on your device without notification, and read log data.</string>
+ <!-- Message of dialog confirming that user wants to revoke access to adb from all computers they have authorized -->
+ <string name="adb_keys_warning_message">Revoke access to USB debugging from all computers you\'ve previously authorized?</string>
<!-- Title of warning dialog about the implications of enabling developer settings -->
<string name="dev_settings_warning_title">Allow development settings?</string>
<!-- Warning text to user about the implications of enabling USB debugging -->
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 67473c2..c199b1d 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -57,6 +57,9 @@
android:title="@string/enable_adb"
android:summary="@string/enable_adb_summary"/>
+ <Preference android:key="clear_adb_keys"
+ android:title="@string/clear_adb_keys" />
+
<CheckBoxPreference
android:key="bugreport_in_power"
android:title="@string/bugreport_in_power"
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index d32307f..f37b5f8 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -35,6 +35,7 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.hardware.usb.IUsbManager;
import android.os.AsyncTask;
import android.os.BatteryManager;
import android.os.Build;
@@ -75,6 +76,7 @@
public class DevelopmentSettings extends PreferenceFragment
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
+ private static final String TAG = "DevelopmentSettings";
/**
* Preference file were development settings prefs are stored.
@@ -87,6 +89,7 @@
public static final String PREF_SHOW = "show";
private static final String ENABLE_ADB = "enable_adb";
+ private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
private static final String KEEP_SCREEN_ON = "keep_screen_on";
private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
private static final String HDCP_CHECKING_KEY = "hdcp_checking";
@@ -144,6 +147,7 @@
private boolean mDontPokeProperties;
private CheckBoxPreference mEnableAdb;
+ private Preference mClearAdbKeys;
private Preference mBugreport;
private CheckBoxPreference mBugreportInPower;
private CheckBoxPreference mKeepScreenOn;
@@ -190,6 +194,7 @@
private boolean mDialogClicked;
private Dialog mEnableDialog;
private Dialog mAdbDialog;
+ private Dialog mAdbKeysDialog;
@Override
public void onCreate(Bundle icicle) {
@@ -203,6 +208,15 @@
addPreferencesFromResource(R.xml.development_prefs);
mEnableAdb = findAndInitCheckboxPref(ENABLE_ADB);
+ mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
+ if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
+ PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
+ findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
+ if (debugDebuggingCategory != null) {
+ debugDebuggingCategory.removePreference(mClearAdbKeys);
+ }
+ }
+
mBugreport = findPreference(BUGREPORT);
mBugreportInPower = findAndInitCheckboxPref(BUGREPORT_IN_POWER_KEY);
mKeepScreenOn = findAndInitCheckboxPref(KEEP_SCREEN_ON);
@@ -213,6 +227,7 @@
if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) {
disableForUser(mEnableAdb);
+ disableForUser(mClearAdbKeys);
disableForUser(mPassword);
}
@@ -987,6 +1002,13 @@
mVerifyAppsOverUsb.setChecked(false);
updateBugreportOptions();
}
+ } else if (preference == mClearAdbKeys) {
+ if (mAdbKeysDialog != null) dismissDialogs();
+ mAdbKeysDialog = new AlertDialog.Builder(getActivity())
+ .setMessage(R.string.adb_keys_warning_message)
+ .setPositiveButton(android.R.string.ok, this)
+ .setNegativeButton(android.R.string.cancel, null)
+ .show();
} else if (preference == mBugreportInPower) {
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.BUGREPORT_IN_POWER_MENU,
@@ -1082,6 +1104,10 @@
mAdbDialog.dismiss();
mAdbDialog = null;
}
+ if (mAdbKeysDialog != null) {
+ mAdbKeysDialog.dismiss();
+ mAdbKeysDialog = null;
+ }
if (mEnableDialog != null) {
mEnableDialog.dismiss();
mEnableDialog = null;
@@ -1101,6 +1127,16 @@
// Reset the toggle
mEnableAdb.setChecked(false);
}
+ } else if (dialog == mAdbKeysDialog) {
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ try {
+ IBinder b = ServiceManager.getService(Context.USB_SERVICE);
+ IUsbManager service = IUsbManager.Stub.asInterface(b);
+ service.clearUsbDebuggingKeys();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Unable to clear adb keys", e);
+ }
+ }
} else if (dialog == mEnableDialog) {
if (which == DialogInterface.BUTTON_POSITIVE) {
mDialogClicked = true;
@@ -1160,7 +1196,7 @@
obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
} catch (RemoteException e) {
} catch (Exception e) {
- Log.i("DevSettings", "Somone wrote a bad service '" + service
+ Log.i(TAG, "Somone wrote a bad service '" + service
+ "' that doesn't like to be poked: " + e);
}
data.recycle();