The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Joe Onorato | fe4f3ae | 2010-06-04 11:25:26 -0700 | [diff] [blame] | 17 | package com.android.systemui.usb; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 19 | import android.app.Activity; |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 21 | import android.app.AlertDialog; |
| 22 | import android.app.Dialog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
| 24 | import android.content.Context; |
| 25 | import android.content.DialogInterface; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 26 | import android.content.DialogInterface.OnCancelListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 29 | import android.content.pm.ApplicationInfo; |
Mike Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 30 | import android.hardware.usb.UsbManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.os.Bundle; |
San Mehat | ec7f7e6 | 2010-01-29 05:34:01 -0800 | [diff] [blame] | 32 | import android.os.Environment; |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 33 | import android.os.Handler; |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 34 | import android.os.HandlerThread; |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 35 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.RemoteException; |
| 37 | import android.os.ServiceManager; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 38 | import android.os.storage.IMountService; |
| 39 | import android.os.storage.StorageEventListener; |
| 40 | import android.os.storage.StorageManager; |
| 41 | import android.util.Log; |
| 42 | import android.view.View; |
| 43 | import android.view.WindowManager; |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 44 | import android.widget.Button; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 45 | import android.widget.ImageView; |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 46 | import android.widget.ProgressBar; |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 47 | import android.widget.TextView; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 48 | |
| 49 | import com.android.internal.R; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 51 | import java.util.List; |
| 52 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | /** |
| 54 | * This activity is shown to the user for him/her to enable USB mass storage |
| 55 | * on-demand (that is, when the USB cable is connected). It uses the alert |
| 56 | * dialog style. It will be launched from a notification. |
| 57 | */ |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 58 | public class UsbStorageActivity extends Activity |
| 59 | implements View.OnClickListener, OnCancelListener { |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 60 | private static final String TAG = "UsbStorageActivity"; |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 61 | |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 62 | private Button mMountButton; |
| 63 | private Button mUnmountButton; |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 64 | private ProgressBar mProgressBar; |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 65 | private TextView mBanner; |
| 66 | private TextView mMessage; |
| 67 | private ImageView mIcon; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 68 | private StorageManager mStorageManager = null; |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 69 | private static final int DLG_CONFIRM_KILL_STORAGE_USERS = 1; |
| 70 | private static final int DLG_ERROR_SHARING = 2; |
| 71 | static final boolean localLOGV = false; |
Joe Onorato | c7f8b6f | 2011-02-03 17:44:47 -0800 | [diff] [blame] | 72 | private boolean mDestroyed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 74 | // UI thread |
| 75 | private Handler mUIHandler; |
| 76 | |
| 77 | // thread for working with the storage services, which can be slow |
| 78 | private Handler mAsyncStorageHandler; |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | /** Used to detect when the USB cable is unplugged, so we can call finish() */ |
Mike Lockwood | 77bc30d | 2010-09-21 11:17:27 -0400 | [diff] [blame] | 81 | private BroadcastReceiver mUsbStateReceiver = new BroadcastReceiver() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | @Override |
| 83 | public void onReceive(Context context, Intent intent) { |
Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 84 | if (intent.getAction().equals(UsbManager.ACTION_USB_STATE)) { |
Mike Lockwood | 77bc30d | 2010-09-21 11:17:27 -0400 | [diff] [blame] | 85 | handleUsbStateChanged(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | }; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 89 | |
| 90 | private StorageEventListener mStorageListener = new StorageEventListener() { |
| 91 | @Override |
| 92 | public void onStorageStateChanged(String path, String oldState, String newState) { |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 93 | final boolean on = newState.equals(Environment.MEDIA_SHARED); |
| 94 | switchDisplay(on); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 95 | } |
| 96 | }; |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 97 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | @Override |
| 99 | protected void onCreate(Bundle savedInstanceState) { |
| 100 | super.onCreate(savedInstanceState); |
| 101 | |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 102 | if (mStorageManager == null) { |
| 103 | mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE); |
| 104 | if (mStorageManager == null) { |
| 105 | Log.w(TAG, "Failed to get StorageManager"); |
| 106 | } |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 107 | } |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 108 | |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 109 | mUIHandler = new Handler(); |
| 110 | |
| 111 | HandlerThread thr = new HandlerThread("SystemUI UsbStorageActivity"); |
| 112 | thr.start(); |
| 113 | mAsyncStorageHandler = new Handler(thr.getLooper()); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 114 | |
Dianne Hackborn | 2075464 | 2010-10-03 14:56:54 -0700 | [diff] [blame] | 115 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); |
| 116 | if (Environment.isExternalStorageRemovable()) { |
| 117 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); |
| 118 | } |
| 119 | |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 120 | setContentView(com.android.internal.R.layout.usb_storage_activity); |
| 121 | |
| 122 | mIcon = (ImageView) findViewById(com.android.internal.R.id.icon); |
| 123 | mBanner = (TextView) findViewById(com.android.internal.R.id.banner); |
| 124 | mMessage = (TextView) findViewById(com.android.internal.R.id.message); |
| 125 | |
| 126 | mMountButton = (Button) findViewById(com.android.internal.R.id.mount_button); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 127 | mMountButton.setOnClickListener(this); |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 128 | mUnmountButton = (Button) findViewById(com.android.internal.R.id.unmount_button); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 129 | mUnmountButton.setOnClickListener(this); |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 130 | mProgressBar = (ProgressBar) findViewById(com.android.internal.R.id.progress); |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Joe Onorato | c7f8b6f | 2011-02-03 17:44:47 -0800 | [diff] [blame] | 133 | @Override |
| 134 | protected void onDestroy() { |
| 135 | super.onDestroy(); |
| 136 | mDestroyed = true; |
| 137 | } |
| 138 | |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 139 | private void switchDisplay(final boolean usbStorageInUse) { |
| 140 | mUIHandler.post(new Runnable() { |
| 141 | @Override |
| 142 | public void run() { |
| 143 | switchDisplayAsync(usbStorageInUse); |
| 144 | } |
| 145 | }); |
| 146 | } |
| 147 | |
| 148 | private void switchDisplayAsync(boolean usbStorageInUse) { |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 149 | if (usbStorageInUse) { |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 150 | mProgressBar.setVisibility(View.GONE); |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 151 | mUnmountButton.setVisibility(View.VISIBLE); |
| 152 | mMountButton.setVisibility(View.GONE); |
| 153 | mIcon.setImageResource(com.android.internal.R.drawable.usb_android_connected); |
| 154 | mBanner.setText(com.android.internal.R.string.usb_storage_stop_title); |
| 155 | mMessage.setText(com.android.internal.R.string.usb_storage_stop_message); |
| 156 | } else { |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 157 | mProgressBar.setVisibility(View.GONE); |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 158 | mUnmountButton.setVisibility(View.GONE); |
| 159 | mMountButton.setVisibility(View.VISIBLE); |
| 160 | mIcon.setImageResource(com.android.internal.R.drawable.usb_android); |
| 161 | mBanner.setText(com.android.internal.R.string.usb_storage_title); |
| 162 | mMessage.setText(com.android.internal.R.string.usb_storage_message); |
| 163 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Override |
| 167 | protected void onResume() { |
| 168 | super.onResume(); |
| 169 | |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 170 | mStorageManager.registerListener(mStorageListener); |
Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 171 | registerReceiver(mUsbStateReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE)); |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 172 | try { |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 173 | mAsyncStorageHandler.post(new Runnable() { |
| 174 | @Override |
| 175 | public void run() { |
| 176 | switchDisplay(mStorageManager.isUsbMassStorageEnabled()); |
| 177 | } |
| 178 | }); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 179 | } catch (Exception ex) { |
| 180 | Log.e(TAG, "Failed to read UMS enable state", ex); |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 181 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | @Override |
| 185 | protected void onPause() { |
| 186 | super.onPause(); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 187 | |
Mike Lockwood | 77bc30d | 2010-09-21 11:17:27 -0400 | [diff] [blame] | 188 | unregisterReceiver(mUsbStateReceiver); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 189 | if (mStorageManager == null && mStorageListener != null) { |
| 190 | mStorageManager.unregisterListener(mStorageListener); |
| 191 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Mike Lockwood | 77bc30d | 2010-09-21 11:17:27 -0400 | [diff] [blame] | 194 | private void handleUsbStateChanged(Intent intent) { |
Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 195 | boolean connected = intent.getExtras().getBoolean(UsbManager.USB_CONNECTED); |
Mike Lockwood | 77bc30d | 2010-09-21 11:17:27 -0400 | [diff] [blame] | 196 | if (!connected) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | // It was disconnected from the plug, so finish |
| 198 | finish(); |
| 199 | } |
| 200 | } |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 201 | |
| 202 | private IMountService getMountService() { |
| 203 | IBinder service = ServiceManager.getService("mount"); |
| 204 | if (service != null) { |
| 205 | return IMountService.Stub.asInterface(service); |
| 206 | } |
| 207 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | } |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 209 | |
| 210 | @Override |
| 211 | public Dialog onCreateDialog(int id, Bundle args) { |
| 212 | switch (id) { |
| 213 | case DLG_CONFIRM_KILL_STORAGE_USERS: |
| 214 | return new AlertDialog.Builder(this) |
| 215 | .setTitle(R.string.dlg_confirm_kill_storage_users_title) |
| 216 | .setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() { |
| 217 | public void onClick(DialogInterface dialog, int which) { |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 218 | switchUsbMassStorage(true); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 219 | }}) |
| 220 | .setNegativeButton(R.string.cancel, null) |
| 221 | .setMessage(R.string.dlg_confirm_kill_storage_users_text) |
| 222 | .setOnCancelListener(this) |
| 223 | .create(); |
| 224 | case DLG_ERROR_SHARING: |
| 225 | return new AlertDialog.Builder(this) |
| 226 | .setTitle(R.string.dlg_error_title) |
| 227 | .setNeutralButton(R.string.dlg_ok, null) |
| 228 | .setMessage(R.string.usb_storage_error_message) |
| 229 | .setOnCancelListener(this) |
| 230 | .create(); |
| 231 | } |
| 232 | return null; |
| 233 | } |
| 234 | |
Joe Onorato | c7f8b6f | 2011-02-03 17:44:47 -0800 | [diff] [blame] | 235 | private void scheduleShowDialog(final int id) { |
| 236 | mUIHandler.post(new Runnable() { |
| 237 | @Override |
| 238 | public void run() { |
| 239 | if (!mDestroyed) { |
| 240 | removeDialog(id); |
| 241 | showDialog(id); |
| 242 | } |
| 243 | } |
| 244 | }); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 247 | private void switchUsbMassStorage(final boolean on) { |
| 248 | // things to do on the UI thread |
| 249 | mUIHandler.post(new Runnable() { |
| 250 | @Override |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 251 | public void run() { |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 252 | mUnmountButton.setVisibility(View.GONE); |
| 253 | mMountButton.setVisibility(View.GONE); |
| 254 | |
| 255 | mProgressBar.setVisibility(View.VISIBLE); |
| 256 | // will be hidden once USB mass storage kicks in (or fails) |
| 257 | } |
| 258 | }); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 259 | |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 260 | // things to do elsewhere |
| 261 | mAsyncStorageHandler.post(new Runnable() { |
| 262 | @Override |
| 263 | public void run() { |
| 264 | if (on) { |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 265 | mStorageManager.enableUsbMassStorage(); |
| 266 | } else { |
| 267 | mStorageManager.disableUsbMassStorage(); |
| 268 | } |
| 269 | } |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 270 | }); |
Daniel Sandler | c8b7b9f | 2010-03-16 16:01:29 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 273 | private void checkStorageUsers() { |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 274 | mAsyncStorageHandler.post(new Runnable() { |
| 275 | @Override |
| 276 | public void run() { |
| 277 | checkStorageUsersAsync(); |
| 278 | } |
| 279 | }); |
| 280 | } |
| 281 | |
| 282 | private void checkStorageUsersAsync() { |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 283 | IMountService ims = getMountService(); |
| 284 | if (ims == null) { |
| 285 | // Display error dialog |
Joe Onorato | c7f8b6f | 2011-02-03 17:44:47 -0800 | [diff] [blame] | 286 | scheduleShowDialog(DLG_ERROR_SHARING); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 287 | } |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 288 | String extStoragePath = Environment.getExternalStorageDirectory().toString(); |
| 289 | boolean showDialog = false; |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 290 | try { |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 291 | int[] stUsers = ims.getStorageUsers(extStoragePath); |
| 292 | if (stUsers != null && stUsers.length > 0) { |
| 293 | showDialog = true; |
| 294 | } else { |
| 295 | // List of applications on sdcard. |
| 296 | ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); |
| 297 | List<ApplicationInfo> infoList = am.getRunningExternalApplications(); |
| 298 | if (infoList != null && infoList.size() > 0) { |
| 299 | showDialog = true; |
| 300 | } |
| 301 | } |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 302 | } catch (RemoteException e) { |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 303 | // Display error dialog |
Joe Onorato | c7f8b6f | 2011-02-03 17:44:47 -0800 | [diff] [blame] | 304 | scheduleShowDialog(DLG_ERROR_SHARING); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 305 | } |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 306 | if (showDialog) { |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 307 | // Display dialog to user |
Joe Onorato | c7f8b6f | 2011-02-03 17:44:47 -0800 | [diff] [blame] | 308 | scheduleShowDialog(DLG_CONFIRM_KILL_STORAGE_USERS); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 309 | } else { |
| 310 | if (localLOGV) Log.i(TAG, "Enabling UMS"); |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 311 | switchUsbMassStorage(true); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | public void onClick(View v) { |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 316 | if (v == mMountButton) { |
| 317 | // Check for list of storage users and display dialog if needed. |
| 318 | checkStorageUsers(); |
| 319 | } else if (v == mUnmountButton) { |
| 320 | if (localLOGV) Log.i(TAG, "Disabling UMS"); |
Daniel Sandler | 3a4940f | 2010-11-03 15:25:52 -0400 | [diff] [blame] | 321 | switchUsbMassStorage(false); |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | public void onCancel(DialogInterface dialog) { |
| 326 | finish(); |
Daniel Sandler | b94f795 | 2010-01-28 15:12:04 -0500 | [diff] [blame] | 327 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | |
| 329 | } |