Example usage for android.content Intent ACTION_MEDIA_CHECKING

List of usage examples for android.content Intent ACTION_MEDIA_CHECKING

Introduction

In this page you can find the example usage for android.content Intent ACTION_MEDIA_CHECKING.

Prototype

String ACTION_MEDIA_CHECKING

To view the source code for android.content Intent ACTION_MEDIA_CHECKING.

Click Source Link

Document

Broadcast Action: External media is present, and being disk-checked The path to the mount point for the checking media is contained in the Intent.mData field.

Usage

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

private void notifyVolumeStateChange(String label, String path, int oldState, int newState) {
    final StorageVolume volume;
    final String state;
    synchronized (mVolumesLock) {
        volume = mVolumesByPath.get(path);
        state = getVolumeState(path);/*from  w  ww .  jav a 2 s  .  co m*/
    }

    if (DEBUG_EVENTS)
        Slog.i(TAG, "notifyVolumeStateChange::" + state);

    String action = null;

    if (oldState == VolumeState.Shared && newState != oldState) {
        if (LOCAL_LOGD)
            Slog.d(TAG, "Sending ACTION_MEDIA_UNSHARED intent");
        sendStorageIntent(Intent.ACTION_MEDIA_UNSHARED, volume, UserHandle.ALL);
    }

    if (newState == VolumeState.Init) {
    } else if (newState == VolumeState.NoMedia) {
        // NoMedia is handled via Disk Remove events
    } else if (newState == VolumeState.Idle) {
        /*
         * Don't notify if we're in BAD_REMOVAL, NOFS, UNMOUNTABLE, or
         * if we're in the process of enabling UMS
         */
        if (!state.equals(Environment.MEDIA_BAD_REMOVAL) && !state.equals(Environment.MEDIA_NOFS)
                && !state.equals(Environment.MEDIA_UNMOUNTABLE) && !getUmsEnabling()) {
            if (DEBUG_EVENTS)
                Slog.i(TAG, "updating volume state for media bad removal nofs and unmountable");
            updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
            action = Intent.ACTION_MEDIA_UNMOUNTED;
        }
    } else if (newState == VolumeState.Pending) {
    } else if (newState == VolumeState.Checking) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "updating volume state checking");
        updatePublicVolumeState(volume, Environment.MEDIA_CHECKING);
        action = Intent.ACTION_MEDIA_CHECKING;
    } else if (newState == VolumeState.Mounted) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "updating volume state mounted");
        updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
        action = Intent.ACTION_MEDIA_MOUNTED;
    } else if (newState == VolumeState.Unmounting) {
        action = Intent.ACTION_MEDIA_EJECT;
    } else if (newState == VolumeState.Formatting) {
    } else if (newState == VolumeState.Shared) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "Updating volume state media mounted");
        /* Send the media unmounted event first */
        updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
        sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);

        if (DEBUG_EVENTS)
            Slog.i(TAG, "Updating media shared");
        updatePublicVolumeState(volume, Environment.MEDIA_SHARED);
        action = Intent.ACTION_MEDIA_SHARED;
        if (LOCAL_LOGD)
            Slog.d(TAG, "Sending ACTION_MEDIA_SHARED intent");
    } else if (newState == VolumeState.SharedMnt) {
        Slog.e(TAG, "Live shared mounts not supported yet!");
        return;
    } else {
        Slog.e(TAG, "Unhandled VolumeState {" + newState + "}");
    }

    if (action != null) {
        sendStorageIntent(action, volume, UserHandle.ALL);
    }
}