diff --git a/core/java/com/android/internal/app/UsbStorageActivity.java b/core/java/com/android/internal/app/UsbStorageActivity.java
index b8a2136cc9d00..37ea3527841ae 100644
--- a/core/java/com/android/internal/app/UsbStorageActivity.java
+++ b/core/java/com/android/internal/app/UsbStorageActivity.java
@@ -16,7 +16,7 @@
package com.android.internal.app;
-import android.app.AlertDialog;
+import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -28,16 +28,23 @@ import android.os.IMountService;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.widget.ImageView;
+import android.widget.Button;
+import android.widget.TextView;
import android.widget.Toast;
+import android.view.View;
/**
* This activity is shown to the user for him/her to enable USB mass storage
* on-demand (that is, when the USB cable is connected). It uses the alert
* dialog style. It will be launched from a notification.
*/
-public class UsbStorageActivity extends AlertActivity implements DialogInterface.OnClickListener {
-
- private static final int POSITIVE_BUTTON = AlertDialog.BUTTON1;
+public class UsbStorageActivity extends Activity {
+ private Button mMountButton;
+ private Button mUnmountButton;
+ private TextView mBanner;
+ private TextView mMessage;
+ private ImageView mIcon;
/** Used to detect when the USB cable is unplugged, so we can call finish() */
private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
@@ -53,16 +60,49 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // Set up the "dialog"
- final AlertController.AlertParams p = mAlertParams;
- p.mIconId = com.android.internal.R.drawable.ic_dialog_usb;
- p.mTitle = getString(com.android.internal.R.string.usb_storage_title);
- p.mMessage = getString(com.android.internal.R.string.usb_storage_message);
- p.mPositiveButtonText = getString(com.android.internal.R.string.usb_storage_button_mount);
- p.mPositiveButtonListener = this;
- p.mNegativeButtonText = getString(com.android.internal.R.string.usb_storage_button_unmount);
- p.mNegativeButtonListener = this;
- setupAlert();
+ setTitle(getString(com.android.internal.R.string.usb_storage_activity_title));
+
+ setContentView(com.android.internal.R.layout.usb_storage_activity);
+
+ mIcon = (ImageView) findViewById(com.android.internal.R.id.icon);
+ mBanner = (TextView) findViewById(com.android.internal.R.id.banner);
+ mMessage = (TextView) findViewById(com.android.internal.R.id.message);
+
+ mMountButton = (Button) findViewById(com.android.internal.R.id.mount_button);
+ mMountButton.setOnClickListener(
+ new View.OnClickListener() {
+ public void onClick(View v) {
+ mountAsUsbStorage();
+ // TODO: replace with forthcoming MountService callbacks
+ switchDisplay(true);
+ }
+ });
+
+ mUnmountButton = (Button) findViewById(com.android.internal.R.id.unmount_button);
+ mUnmountButton.setOnClickListener(
+ new View.OnClickListener() {
+ public void onClick(View v) {
+ stopUsbStorage();
+ // TODO: replace with forthcoming MountService callbacks
+ switchDisplay(false);
+ }
+ });
+ }
+
+ private void switchDisplay(boolean usbStorageInUse) {
+ if (usbStorageInUse) {
+ mUnmountButton.setVisibility(View.VISIBLE);
+ mMountButton.setVisibility(View.GONE);
+ mIcon.setImageResource(com.android.internal.R.drawable.usb_android_connected);
+ mBanner.setText(com.android.internal.R.string.usb_storage_stop_title);
+ mMessage.setText(com.android.internal.R.string.usb_storage_stop_message);
+ } else {
+ mUnmountButton.setVisibility(View.GONE);
+ mMountButton.setVisibility(View.VISIBLE);
+ mIcon.setImageResource(com.android.internal.R.drawable.usb_android);
+ mBanner.setText(com.android.internal.R.string.usb_storage_title);
+ mMessage.setText(com.android.internal.R.string.usb_storage_message);
+ }
}
@Override
@@ -70,6 +110,18 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
super.onResume();
registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+
+ boolean umsOn = false;
+ try {
+ IMountService mountService = IMountService.Stub.asInterface(ServiceManager
+ .getService("mount"));
+ if (mountService != null) {
+ umsOn = mountService.getMassStorageEnabled();
+ }
+ } catch (android.os.RemoteException exc) {
+ // pass
+ }
+ switchDisplay(umsOn);
}
@Override
@@ -79,19 +131,6 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
unregisterReceiver(mBatteryReceiver);
}
- /**
- * {@inheritDoc}
- */
- public void onClick(DialogInterface dialog, int which) {
-
- if (which == POSITIVE_BUTTON) {
- mountAsUsbStorage();
- }
-
- // No matter what, finish the activity
- finish();
- }
-
private void mountAsUsbStorage() {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager
.getService("mount"));
@@ -108,6 +147,22 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
}
}
+ private void stopUsbStorage() {
+ IMountService mountService = IMountService.Stub.asInterface(ServiceManager
+ .getService("mount"));
+ if (mountService == null) {
+ showStoppingError();
+ return;
+ }
+
+ try {
+ mountService.setMassStorageEnabled(false);
+ } catch (RemoteException e) {
+ showStoppingError();
+ return;
+ }
+ }
+
private void handleBatteryChanged(Intent intent) {
int pluggedType = intent.getIntExtra("plugged", 0);
if (pluggedType == 0) {
@@ -120,5 +175,10 @@ public class UsbStorageActivity extends AlertActivity implements DialogInterface
Toast.makeText(this, com.android.internal.R.string.usb_storage_error_message,
Toast.LENGTH_LONG).show();
}
+
+ private void showStoppingError() {
+ Toast.makeText(this, com.android.internal.R.string.usb_storage_stop_error_message,
+ Toast.LENGTH_LONG).show();
+ }
}
diff --git a/core/java/com/android/internal/app/UsbStorageStopActivity.java b/core/java/com/android/internal/app/UsbStorageStopActivity.java
deleted file mode 100644
index 557a5232a6246..0000000000000
--- a/core/java/com/android/internal/app/UsbStorageStopActivity.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2007 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.app;
-
-import android.app.AlertDialog;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.IMountService;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.widget.Toast;
-
-/**
- * This activity is shown to the user for him/her to disable USB mass storage.
- * It uses the alert dialog style. It will be launched from a notification.
- */
-public class UsbStorageStopActivity extends AlertActivity implements DialogInterface.OnClickListener {
-
- private static final int POSITIVE_BUTTON = AlertDialog.BUTTON1;
-
- /** Used to detect when the USB cable is unplugged, so we can call finish() */
- private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction() == Intent.ACTION_BATTERY_CHANGED) {
- handleBatteryChanged(intent);
- }
- }
- };
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Set up the "dialog"
- final AlertController.AlertParams p = mAlertParams;
- p.mIconId = com.android.internal.R.drawable.ic_dialog_alert;
- p.mTitle = getString(com.android.internal.R.string.usb_storage_stop_title);
- p.mMessage = getString(com.android.internal.R.string.usb_storage_stop_message);
- p.mPositiveButtonText = getString(com.android.internal.R.string.usb_storage_stop_button_mount);
- p.mPositiveButtonListener = this;
- p.mNegativeButtonText = getString(com.android.internal.R.string.usb_storage_stop_button_unmount);
- p.mNegativeButtonListener = this;
- setupAlert();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
- }
-
- @Override
- protected void onPause() {
- super.onPause();
-
- unregisterReceiver(mBatteryReceiver);
- }
-
- /**
- * {@inheritDoc}
- */
- public void onClick(DialogInterface dialog, int which) {
-
- if (which == POSITIVE_BUTTON) {
- stopUsbStorage();
- }
-
- // No matter what, finish the activity
- finish();
- }
-
- private void stopUsbStorage() {
- IMountService mountService = IMountService.Stub.asInterface(ServiceManager
- .getService("mount"));
- if (mountService == null) {
- showStoppingError();
- return;
- }
-
- try {
- mountService.setMassStorageEnabled(false);
- } catch (RemoteException e) {
- showStoppingError();
- return;
- }
- }
-
- private void handleBatteryChanged(Intent intent) {
- int pluggedType = intent.getIntExtra("plugged", 0);
- if (pluggedType == 0) {
- // It was disconnected from the plug, so finish
- finish();
- }
- }
-
- private void showStoppingError() {
- Toast.makeText(this, com.android.internal.R.string.usb_storage_stop_error_message,
- Toast.LENGTH_LONG).show();
- }
-
-}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 54e15a598d54e..665088a4c5baf 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1240,7 +1240,6 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/res/res/layout/usb_storage_activity.xml b/core/res/res/layout/usb_storage_activity.xml
new file mode 100644
index 0000000000000..86bfadbccc785
--- /dev/null
+++ b/core/res/res/layout/usb_storage_activity.xml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 42553d4b138b9..8f97c13ea33b0 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2008,21 +2008,23 @@
Loading\u2026
-
+
+ USB Mass Storage
+
USB connected
- You have connected your phone to your computer via USB. Select \"Mount\" if you want to copy files between your computer and your phone\'s SD card.
+ You have connected your phone to your computer via USB. Select the button below if you want to copy files between your computer and your Android\u2018s SD card.
- Mount
-
- Don\'t mount
+ Turn on USB storage
There is a problem using your SD card for USB storage.
USB connected
Select to copy files to/from your computer.
+
+
Turn off USB storage
@@ -2031,15 +2033,13 @@
- Turn off USB storage
+ USB storage in use
- Before turning off USB storage, make sure you have unmounted on the USB host. Select \"Turn Off\" to turn off USB storage.
+ Before turning off USB storage, make sure you have unmounted (\u201cejected\u201d) your Android\u2018s SD card from your computer.
- Turn Off
-
- Cancel
+ Turn off USB storage
- We\'ve encountered a problem turning off USB storage. Check to make sure you have unmounted the USB host, then try again.
+ There was a problem turning off USB storage. Check to make sure you have unmounted the USB host, then try again.
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index 9a1f8a6b07e31..801c86fcd580e 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -866,7 +866,7 @@ class MountService extends IMountService.Stub
if (mUmsActiveNotify) {
Intent intent = new Intent();
- intent.setClass(mContext, com.android.internal.app.UsbStorageStopActivity.class);
+ intent.setClass(mContext, com.android.internal.app.UsbStorageActivity.class);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
setUsbStorageNotification(com.android.internal.R.string.usb_storage_stop_notification_title,
com.android.internal.R.string.usb_storage_stop_notification_message,