Merge "b/2310373 Show pairing dialogs if the device has been scanning for bt devices recently."
diff --git a/res/layout/device_admin_add.xml b/res/layout/device_admin_add.xml
index 3ff190b..f560331 100644
--- a/res/layout/device_admin_add.xml
+++ b/res/layout/device_admin_add.xml
@@ -104,5 +104,14 @@
            android:layout_width="0dip"
            android:layout_height="0dip"
            android:layout_weight="1" />
+        <Button android:id="@+id/cancel_button"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:text="@string/cancel" />
+        <View
+           android:layout_width="0dip"
+           android:layout_height="0dip"
+           android:layout_weight="1" />
     </LinearLayout>
 </LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 67196e9..49231d1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1356,8 +1356,12 @@
     <string name="usb_tethering_available_subtext">USB connected, select to tether</string>
     <!-- USB tethered subtext - shown when USB is connected and being tethered -->
     <string name="usb_tethering_active_subtext">Connected, select to disconnect</string>
+    <!-- USB storage subtext - shown when tethering is disabled because USB storage is active -->
+    <string name="usb_tethering_storage_active_subtext">Tethering disabled (USB storage is in use)</string>
     <!-- USB unavailable subtext - shown when USB is not connected -->
     <string name="usb_tethering_unavailable_subtext">USB not connected</string>
+    <!-- USB errored subtext - shown when USB is broken for some reason -->
+    <string name="usb_tethering_errored_subtext">USB tethering has had a problem.</string>
 
     <!-- Wireless controls, item title to go into the network settings -->
     <string name="network_settings_title">Mobile networks</string>
@@ -2174,6 +2178,16 @@
     <string name="tts_engine_name_is_enabled_summary"><xliff:g id="tts_plugin_engine_name">%s</xliff:g> is enabled</string>
     <!-- On main TTS Settings screen, text preceded by the TTS engine name to indicate the engine cannot be used by the user -->
     <string name="tts_engine_name_is_disabled_summary"><xliff:g id="tts_plugin_engine_name">%s</xliff:g> is disabled</string>
+    <!-- On Pico TTS Settings screen, text to mark the section for the various languages and voices that are available -->
+    <string name="pico_languages_and_voices">Languages and Voices</string>
+    <!-- On Pico TTS Settings screen, text to mark a voice as installed -->
+    <string name="pico_installed">Installed</string>
+    <!-- On Pico TTS Settings screen, text to mark a voice as not installed -->
+    <string name="pico_not_installed">Not installed</string>
+    <!-- On Pico TTS Settings screen, summary text to indicate that a voice is female -->
+    <string name="pico_voice_summary_female">Female</string>
+    <!-- On Pico TTS Settings screen, summary text to indicate that a voice is male -->
+    <string name="pico_voice_summary_male">Male</string>
 
     <!-- Power Control Widget -->
     <string name="gadget_title">Power Control</string>
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index d953409..2653e81 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -64,6 +64,7 @@
     TextView mAdminWarning;
     ViewGroup mAdminPolicies;
     Button mActionButton;
+    Button mCancelButton;
     
     View mSelectLayout;
     
@@ -133,6 +134,12 @@
         mAddMsg = (TextView)findViewById(R.id.add_msg);
         mAdminWarning = (TextView)findViewById(R.id.admin_warning);
         mAdminPolicies = (ViewGroup)findViewById(R.id.admin_policies);
+        mCancelButton = (Button)findViewById(R.id.cancel_button);
+        mCancelButton.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                finish();
+            }
+        });
         mActionButton = (Button)findViewById(R.id.action_button);
         mActionButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
diff --git a/src/com/android/settings/InstalledAppDetails.java b/src/com/android/settings/InstalledAppDetails.java
index 67f2f8f..128d1cd 100644
--- a/src/com/android/settings/InstalledAppDetails.java
+++ b/src/com/android/settings/InstalledAppDetails.java
@@ -592,6 +592,7 @@
         @Override
         public void onReceive(Context context, Intent intent) {
             mForceStopButton.setEnabled(getResultCode() != RESULT_CANCELED);
+            mForceStopButton.setOnClickListener(InstalledAppDetails.this);
         }
     };
     
@@ -634,13 +635,6 @@
             }
             mPm.deleteApplicationCacheFiles(packageName, mClearCacheObserver);
         } else if (v == mForceStopButton) {
-            // TODO Once framework supports a pre-broadcast to
-            // actually find out if an application will be restarted right
-            // after its killed, there is no way we can determine if
-            // a force stop will really kill the app. So just ignore
-            // the dialog for now and force stop the package. Please note
-            // that the button cannot be enabled or disabled since
-            // we do not have this info for now.
             forceStopPackage(mAppInfo.packageName);
         } else if (v == mMoveAppButton) {
             if (mPackageMoveObserver == null) {
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 1e9c4e2..ec552a5 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -23,6 +23,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.net.ConnectivityManager;
+import android.os.Environment;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
@@ -77,8 +78,10 @@
                     ConnectivityManager.EXTRA_AVAILABLE_TETHER);
             ArrayList<String> active = intent.getStringArrayListExtra(
                     ConnectivityManager.EXTRA_ACTIVE_TETHER);
+            ArrayList<String> errored = intent.getStringArrayListExtra(
+                    ConnectivityManager.EXTRA_ERRORED_TETHER);
 
-            updateState(available, active);
+            updateState(available, active, errored);
         }
     }
 
@@ -89,6 +92,8 @@
                 Settings.Secure.TETHER_NOTIFY, 0) != 0);
 
         IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
+        filter.addAction(Intent.ACTION_MEDIA_SHARED);
+        filter.addAction(Intent.ACTION_MEDIA_UNSHARED);
         mTetherChangeReceiver = new TetherChangeReceiver();
         Intent intent = registerReceiver(mTetherChangeReceiver, filter);
 
@@ -102,11 +107,16 @@
         mTetherChangeReceiver = null;
     }
 
-    private void updateState(ArrayList<String> available, ArrayList<String> tethered) {
+    private void updateState(ArrayList<String> available, ArrayList<String> tethered,
+            ArrayList<String> errored) {
         boolean usbTethered = false;
         boolean usbAvailable = false;
+        boolean usbErrored = false;
         boolean wifiTethered = false;
         boolean wifiAvailable = false;
+        boolean massStorageActive =
+                Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
+        boolean wifiErrored = false;
 
         for (String s : available) {
             for (String regex : mUsbRegexs) {
@@ -124,13 +134,27 @@
                 if (s.matches(regex)) wifiTethered = true;
             }
         }
+        for (String s: errored) {
+            for (String regex : mUsbRegexs) {
+                if (s.matches(regex)) usbErrored = true;
+            }
+            for (String regex : mWifiRegexs) {
+                if (s.matches(regex)) wifiErrored = true;
+            }
+        }
 
         if (usbTethered) {
             mUsbTether.setSummary(R.string.usb_tethering_active_subtext);
             mUsbTether.setEnabled(true);
+        } else if (massStorageActive) {
+            mUsbTether.setSummary(R.string.usb_tethering_storage_active_subtext);
+            mUsbTether.setEnabled(false);
         } else if (usbAvailable) {
             mUsbTether.setSummary(R.string.usb_tethering_available_subtext);
             mUsbTether.setEnabled(true);
+        } else if (usbErrored) {
+            mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
+            mUsbTether.setEnabled(false);
         } else {
             mUsbTether.setSummary(R.string.usb_tethering_unavailable_subtext);
             mUsbTether.setEnabled(false);
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 4f3205b..42e5832 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -35,7 +35,6 @@
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
 import android.view.ContextMenu;
-import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ContextMenu.ContextMenuInfo;
@@ -53,8 +52,6 @@
 
     private static final String TAG = "BluetoothSettings";
 
-    private static final int MENU_SCAN = Menu.FIRST;
-
     private static final String KEY_BT_CHECKBOX = "bt_checkbox";
     private static final String KEY_BT_DISCOVERABLE = "bt_discoverable";
     private static final String KEY_BT_DEVICE_LIST = "bt_device_list";
@@ -217,33 +214,6 @@
     }
 
     @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        menu.add(0, MENU_SCAN, 0, R.string.bluetooth_scan_for_devices)
-                .setIcon(com.android.internal.R.drawable.ic_menu_refresh)
-                .setAlphabeticShortcut('r');
-        return true;
-    }
-
-    @Override
-    public boolean onPrepareOptionsMenu(Menu menu) {
-        menu.findItem(MENU_SCAN).setEnabled(mLocalManager.getBluetoothAdapter().isEnabled());
-        return true;
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        switch (item.getItemId()) {
-
-            case MENU_SCAN:
-                mLocalManager.startScanning(true);
-                return true;
-
-            default:
-                return false;
-        }
-    }
-
-    @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
             Preference preference) {