OSDN Git Service

Display a warning dialog when the user enables USB debugging.
authorMike Lockwood <lockwood@android.com>
Thu, 25 Jun 2009 17:36:00 +0000 (13:36 -0400)
committerMike Lockwood <lockwood@android.com>
Thu, 25 Jun 2009 17:36:00 +0000 (13:36 -0400)
Signed-off-by: Mike Lockwood <lockwood@android.com>
res/values/strings.xml
src/com/android/settings/DevelopmentSettings.java

index 63b343d..5df6cf5 100644 (file)
@@ -1457,7 +1457,7 @@ found in the list of installed applications.</string>
     <string name="quick_launch_no_shortcut">No shortcut</string>
     <!-- On the Quick launch settings screen, summary text under the item for each assigned letter.  -->
     <string name="quick_launch_shortcut">Search + <xliff:g id="shortcut_letter">%1$s</xliff:g></string>
-    <!-- On the Quick launch settings screen, title of "Clear shortcut" confirmation dialog. This is reached by longpressing an item for a shortcut letter.  This allows the user to clear the assigned applicatino for that shortcut letter. -->
+    <!-- On the Quick launch settings screen, title of "Clear shortcut" confirmation dialog. This is reached by longpressing an item for a shortcut letter.  This allows the user to clear the assigned application for that shortcut letter. -->
     <string name="quick_launch_clear_dialog_title">Clear</string>
     <!-- On the Quick launch settings screen, message in the "Clear shortcut" confirmation dialog.  See the title for this dialog for more info. -->
     <string name="quick_launch_clear_dialog_message">Your shortcut for <xliff:g id="shortcut_letter">%1$s</xliff:g> (<xliff:g id="application_name">%2$s</xliff:g>) will be cleared.</string>
@@ -1498,6 +1498,10 @@ found in the list of installed applications.</string>
     <string name="allow_mock_location">Allow mock locations</string>
     <!-- setting Checkbox summary whether to allow mock locations  -->
     <string name="allow_mock_location_summary">Allow mock locations</string>
+    <!-- Title of warning dialog about the implications of enabling USB debugging -->
+    <string name="adb_warning_title">Enable 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. It can be used to copy data between your computer and your device, install applications on your device without notification, and read log data.</string>
 
     <!-- Title for the screen that lets the user choose a gadget to add to the home screen
          (or other screens that can host gadgets).  Note to translators: we're still determining
index 155f085..c1da18a 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.android.settings;
 
+import android.app.AlertDialog;
+import android.content.DialogInterface;
 import android.os.BatteryManager;
 import android.os.Bundle;
 import android.os.SystemProperties;
@@ -29,7 +31,8 @@ import android.text.TextUtils;
 /*
  * Displays preferences for application developers.
  */
-public class DevelopmentSettings extends PreferenceActivity {
+public class DevelopmentSettings extends PreferenceActivity
+        implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
 
     private static final String ENABLE_ADB = "enable_adb";
     private static final String KEEP_SCREEN_ON = "keep_screen_on";
@@ -39,6 +42,9 @@ public class DevelopmentSettings extends PreferenceActivity {
     private CheckBoxPreference mKeepScreenOn;
     private CheckBoxPreference mAllowMockLocation;
 
+    // To track whether Yes was clicked in the adb warning dialog
+    private boolean mOkClicked;
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -72,8 +78,19 @@ public class DevelopmentSettings extends PreferenceActivity {
         }
 
         if (preference == mEnableAdb) {
-            Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 
-                    mEnableAdb.isChecked() ? 1 : 0);
+            if (mEnableAdb.isChecked()) {
+                mOkClicked = false;
+                new AlertDialog.Builder(this).setMessage(
+                        getResources().getString(R.string.adb_warning_message))
+                        .setTitle(R.string.adb_warning_title)
+                        .setIcon(android.R.drawable.ic_dialog_alert)
+                        .setPositiveButton(android.R.string.yes, this)
+                        .setNegativeButton(android.R.string.no, this)
+                        .show()
+                        .setOnDismissListener(this);
+            } else {
+                Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
+            }
         } else if (preference == mKeepScreenOn) {
             Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN, 
                     mKeepScreenOn.isChecked() ? 
@@ -85,4 +102,21 @@ public class DevelopmentSettings extends PreferenceActivity {
         
         return false;
     }
+
+    public void onClick(DialogInterface dialog, int which) {
+        if (which == DialogInterface.BUTTON_POSITIVE) {
+            mOkClicked = true;
+            Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1);
+        } else {
+            // Reset the toggle
+            mEnableAdb.setChecked(false);
+        }
+    }
+
+    public void onDismiss(DialogInterface dialog) {
+        // Assuming that onClick gets called first
+        if (!mOkClicked) {
+            mEnableAdb.setChecked(false);
+        }
+    }
 }