FileDocCategorySizeDatePackage
UsbStorageStopActivity.javaAPI DocAndroid 1.5 API3986Wed May 06 22:41:56 BST 2009com.android.internal.app

UsbStorageStopActivity

public class UsbStorageStopActivity extends AlertActivity implements DialogInterface.OnClickListener
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.

Fields Summary
private static final int
POSITIVE_BUTTON
private android.content.BroadcastReceiver
mBatteryReceiver
Used to detect when the USB cable is unplugged, so we can call finish()
Constructors Summary
Methods Summary
private voidhandleBatteryChanged(android.content.Intent intent)

        int pluggedType = intent.getIntExtra("plugged", 0);
        if (pluggedType == 0) {
            // It was disconnected from the plug, so finish
            finish();
        }
    
public voidonClick(android.content.DialogInterface dialog, int which)
{@inheritDoc}


        if (which == POSITIVE_BUTTON) {
            stopUsbStorage();
        }

        // No matter what, finish the activity
        finish();
    
protected voidonCreate(android.os.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();
    
protected voidonPause()

        super.onPause();
        
        unregisterReceiver(mBatteryReceiver);
    
protected voidonResume()

        super.onResume();

        registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    
private voidshowStoppingError()

        Toast.makeText(this, com.android.internal.R.string.usb_storage_stop_error_message,
                Toast.LENGTH_LONG).show();
    
private voidstopUsbStorage()

        IMountService mountService = IMountService.Stub.asInterface(ServiceManager
                .getService("mount"));
        if (mountService == null) {
            showStoppingError();
            return;
        }

        try {
            mountService.setMassStorageEnabled(false);
        } catch (RemoteException e) {
            showStoppingError();
            return;
        }