Example usage for android.hardware.usb UsbManager ACTION_USB_STATE

List of usage examples for android.hardware.usb UsbManager ACTION_USB_STATE

Introduction

In this page you can find the example usage for android.hardware.usb UsbManager ACTION_USB_STATE.

Prototype

String ACTION_USB_STATE

To view the source code for android.hardware.usb UsbManager ACTION_USB_STATE.

Click Source Link

Document

Broadcast Action: A sticky broadcast for USB state change events when in device mode.

Usage

From source file:com.android.server.MountService.java

/**
 * Constructs a new MountService instance
 *
 * @param context  Binder context for this service
 *///from  ww  w . j  a v a2s .c om
public MountService(Context context) {
    sSelf = this;

    mContext = context;

    synchronized (mVolumesLock) {
        readStorageListLocked();
    }

    // XXX: This will go away soon in favor of IMountServiceObserver
    mPms = (PackageManagerService) ServiceManager.getService("package");

    HandlerThread hthread = new HandlerThread(TAG);
    hthread.start();
    mHandler = new MountServiceHandler(hthread.getLooper());

    // Watch for user changes
    final IntentFilter userFilter = new IntentFilter();
    userFilter.addAction(Intent.ACTION_USER_ADDED);
    userFilter.addAction(Intent.ACTION_USER_REMOVED);
    mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler);

    // Watch for USB changes on primary volume
    final StorageVolume primary = getPrimaryPhysicalVolume();
    if (primary != null && primary.allowMassStorage()) {
        mContext.registerReceiver(mUsbReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE), null, mHandler);
    }

    // Add OBB Action Handler to MountService thread.
    mObbActionHandler = new ObbActionHandler(IoThread.get().getLooper());

    // Initialize the last-fstrim tracking if necessary
    File dataDir = Environment.getDataDirectory();
    File systemDir = new File(dataDir, "system");
    mLastMaintenanceFile = new File(systemDir, LAST_FSTRIM_FILE);
    if (!mLastMaintenanceFile.exists()) {
        // Not setting mLastMaintenance here means that we will force an
        // fstrim during reboot following the OTA that installs this code.
        try {
            (new FileOutputStream(mLastMaintenanceFile)).close();
        } catch (IOException e) {
            Slog.e(TAG, "Unable to create fstrim record " + mLastMaintenanceFile.getPath());
        }
    } else {
        mLastMaintenance = mLastMaintenanceFile.lastModified();
    }

    /*
     * Create the connection to vold with a maximum queue of twice the
     * amount of containers we'd ever expect to have. This keeps an
     * "asec list" from blocking a thread repeatedly.
     */
    mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25, null);

    Thread thread = new Thread(mConnector, VOLD_TAG);
    thread.start();

    // Add ourself to the Watchdog monitors if enabled.
    if (WATCHDOG_ENABLE) {
        Watchdog.getInstance().addMonitor(this);
    }
}