Settings: Add setting to clear adb public keys

Change-Id: I1d5ab7a83a3b7b23f0cd51305d965f45793eb853
This commit is contained in:
Benoit Goby
2012-12-21 16:43:20 -08:00
parent 420b193069
commit 0761ffca60
3 changed files with 44 additions and 1 deletions

View File

@@ -2987,6 +2987,8 @@
<string name="enable_adb">USB debugging</string> <string name="enable_adb">USB debugging</string>
<!-- Setting checkbox summary for Whether to enable USB debugging support on the phone --> <!-- 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> <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. --> <!-- [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> <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 --> <!-- [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> <string name="adb_warning_title">Allow USB debugging?</string>
<!-- Warning text to user about the implications of enabling USB debugging --> <!-- 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> <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 --> <!-- Title of warning dialog about the implications of enabling developer settings -->
<string name="dev_settings_warning_title">Allow development settings?</string> <string name="dev_settings_warning_title">Allow development settings?</string>
<!-- Warning text to user about the implications of enabling USB debugging --> <!-- Warning text to user about the implications of enabling USB debugging -->

View File

@@ -57,6 +57,9 @@
android:title="@string/enable_adb" android:title="@string/enable_adb"
android:summary="@string/enable_adb_summary"/> android:summary="@string/enable_adb_summary"/>
<Preference android:key="clear_adb_keys"
android:title="@string/clear_adb_keys" />
<CheckBoxPreference <CheckBoxPreference
android:key="bugreport_in_power" android:key="bugreport_in_power"
android:title="@string/bugreport_in_power" android:title="@string/bugreport_in_power"

View File

@@ -35,6 +35,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.hardware.usb.IUsbManager;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.Build; import android.os.Build;
@@ -75,6 +76,7 @@ import java.util.List;
public class DevelopmentSettings extends PreferenceFragment public class DevelopmentSettings extends PreferenceFragment
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener { OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
private static final String TAG = "DevelopmentSettings";
/** /**
* Preference file were development settings prefs are stored. * Preference file were development settings prefs are stored.
@@ -87,6 +89,7 @@ public class DevelopmentSettings extends PreferenceFragment
public static final String PREF_SHOW = "show"; public static final String PREF_SHOW = "show";
private static final String ENABLE_ADB = "enable_adb"; 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 KEEP_SCREEN_ON = "keep_screen_on";
private static final String ALLOW_MOCK_LOCATION = "allow_mock_location"; private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
private static final String HDCP_CHECKING_KEY = "hdcp_checking"; private static final String HDCP_CHECKING_KEY = "hdcp_checking";
@@ -144,6 +147,7 @@ public class DevelopmentSettings extends PreferenceFragment
private boolean mDontPokeProperties; private boolean mDontPokeProperties;
private CheckBoxPreference mEnableAdb; private CheckBoxPreference mEnableAdb;
private Preference mClearAdbKeys;
private Preference mBugreport; private Preference mBugreport;
private CheckBoxPreference mBugreportInPower; private CheckBoxPreference mBugreportInPower;
private CheckBoxPreference mKeepScreenOn; private CheckBoxPreference mKeepScreenOn;
@@ -190,6 +194,7 @@ public class DevelopmentSettings extends PreferenceFragment
private boolean mDialogClicked; private boolean mDialogClicked;
private Dialog mEnableDialog; private Dialog mEnableDialog;
private Dialog mAdbDialog; private Dialog mAdbDialog;
private Dialog mAdbKeysDialog;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
@@ -203,6 +208,15 @@ public class DevelopmentSettings extends PreferenceFragment
addPreferencesFromResource(R.xml.development_prefs); addPreferencesFromResource(R.xml.development_prefs);
mEnableAdb = findAndInitCheckboxPref(ENABLE_ADB); 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); mBugreport = findPreference(BUGREPORT);
mBugreportInPower = findAndInitCheckboxPref(BUGREPORT_IN_POWER_KEY); mBugreportInPower = findAndInitCheckboxPref(BUGREPORT_IN_POWER_KEY);
mKeepScreenOn = findAndInitCheckboxPref(KEEP_SCREEN_ON); mKeepScreenOn = findAndInitCheckboxPref(KEEP_SCREEN_ON);
@@ -213,6 +227,7 @@ public class DevelopmentSettings extends PreferenceFragment
if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) { if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) {
disableForUser(mEnableAdb); disableForUser(mEnableAdb);
disableForUser(mClearAdbKeys);
disableForUser(mPassword); disableForUser(mPassword);
} }
@@ -987,6 +1002,13 @@ public class DevelopmentSettings extends PreferenceFragment
mVerifyAppsOverUsb.setChecked(false); mVerifyAppsOverUsb.setChecked(false);
updateBugreportOptions(); 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) { } else if (preference == mBugreportInPower) {
Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.BUGREPORT_IN_POWER_MENU, Settings.Secure.BUGREPORT_IN_POWER_MENU,
@@ -1082,6 +1104,10 @@ public class DevelopmentSettings extends PreferenceFragment
mAdbDialog.dismiss(); mAdbDialog.dismiss();
mAdbDialog = null; mAdbDialog = null;
} }
if (mAdbKeysDialog != null) {
mAdbKeysDialog.dismiss();
mAdbKeysDialog = null;
}
if (mEnableDialog != null) { if (mEnableDialog != null) {
mEnableDialog.dismiss(); mEnableDialog.dismiss();
mEnableDialog = null; mEnableDialog = null;
@@ -1101,6 +1127,16 @@ public class DevelopmentSettings extends PreferenceFragment
// Reset the toggle // Reset the toggle
mEnableAdb.setChecked(false); 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) { } else if (dialog == mEnableDialog) {
if (which == DialogInterface.BUTTON_POSITIVE) { if (which == DialogInterface.BUTTON_POSITIVE) {
mDialogClicked = true; mDialogClicked = true;
@@ -1160,7 +1196,7 @@ public class DevelopmentSettings extends PreferenceFragment
obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0); obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
} catch (RemoteException e) { } catch (RemoteException e) {
} catch (Exception 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); + "' that doesn't like to be poked: " + e);
} }
data.recycle(); data.recycle();