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