Merge "USB: Add dialog with instructions for installing AFT"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c45cdf1..b916a52 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1761,6 +1761,12 @@
     <string name="usb_label_installer_cd">Install Android File Transfer application for Mac</string>
     <!-- Storage setting.  Label for installer CD [CHAR LIMIT=30]-->
     <string name="usb_label_installer_cd_done">Done installing Android File Transfer application for Mac</string>
+    <!-- Installer CD dialog title [CHAR LIMIT=30] -->
+    <string name="dlg_installer_cd_title">Android File Transfer app for Mac</string>
+    <!-- Installer CD dialog text  [CHAR LIMIT=NONE] -->
+    <string name="dlg_installer_cd_text">Step 1:\nOn your Mac, double-click androidfiletransfer.msg\n\nStep 2:\nIn the Installer window, drag Android File Transfer to Applications.</string>
+    <!-- Installer CD dialog OK button text  [CHAR LIMIT=NONE] -->
+    <string name="dlg_installer_cd_ok">Done following these steps</string>
 
     <!-- Phone info screen, section titles: -->
     <string name="battery_status_title">Battery status</string>
diff --git a/src/com/android/settings/deviceinfo/UsbSettings.java b/src/com/android/settings/deviceinfo/UsbSettings.java
index ca6a0cc..4820234 100644
--- a/src/com/android/settings/deviceinfo/UsbSettings.java
+++ b/src/com/android/settings/deviceinfo/UsbSettings.java
@@ -16,10 +16,13 @@
 
 package com.android.settings.deviceinfo;
 
+import android.app.AlertDialog;
+import android.app.Dialog;
 import android.content.BroadcastReceiver;
 import android.content.ContentQueryMap;
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.hardware.usb.UsbManager;
@@ -52,6 +55,8 @@
     private static final String KEY_INSTALLER_CD = "usb_installer_cd";
     private static final int MENU_ID_INSTALLER_CD = Menu.FIRST;
 
+    private static final int DLG_INSTALLER_CD = 1;
+
     private UsbManager mUsbManager;
     private String mInstallerImagePath;
     private CheckBoxPreference mMtp;
@@ -60,6 +65,9 @@
 
     private final BroadcastReceiver mStateReceiver = new BroadcastReceiver() {
         public void onReceive(Context content, Intent intent) {
+            if (!intent.getBooleanExtra(UsbManager.USB_CONNECTED, false)) {
+                removeDialog(DLG_INSTALLER_CD);
+            }
             updateToggles();
         }
     };
@@ -108,6 +116,24 @@
                 new IntentFilter(UsbManager.ACTION_USB_STATE));
     }
 
+    @Override
+    public Dialog onCreateDialog(int id) {
+        switch (id) {
+        case DLG_INSTALLER_CD:
+                return new AlertDialog.Builder(getActivity())
+                    .setTitle(R.string.dlg_installer_cd_title)
+                    .setMessage(R.string.dlg_installer_cd_text)
+                    .setPositiveButton(R.string.dlg_installer_cd_ok,
+                        new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog, int which) {
+                               // Disable installer CD, return to default function.
+                                mUsbManager.setCurrentFunction(null, false);
+                            }})
+                    .create();
+        }
+        return null;
+    }
+
     private void updateToggles() {
         if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_MTP)) {
             mMtp.setChecked(true);
@@ -164,10 +190,12 @@
                 if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_MASS_STORAGE)) {
                     // Disable installer CD, return to default function.
                     mUsbManager.setCurrentFunction(null, false);
+                    removeDialog(DLG_INSTALLER_CD);
                 } else {
                     // Enable installer CD.  Don't set as default function.
                     mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MASS_STORAGE, false);
                     mUsbManager.setMassStorageBackingFile(mInstallerImagePath);
+                    showDialog(DLG_INSTALLER_CD);
                 }
                 updateToggles();
                 return true;