private void onStorageStateChangedAsync(String path, String oldState, String newState) {
    if (DEBUG)
      Log.i(
          TAG,
          String.format("Media {%s} state changed from {%s} -> {%s}", path, oldState, newState));
    if (newState.equals(Environment.MEDIA_SHARED)) {
      /*
       * Storage is now shared. Modify the UMS notification
       * for stopping UMS.
       */
      Intent intent = new Intent();
      intent.setClass(mContext, com.android.systemui.usb.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,
          com.android.internal.R.drawable.stat_sys_warning,
          false,
          true,
          pi);
    } else if (newState.equals(Environment.MEDIA_CHECKING)) {
      /*
       * Storage is now checking. Update media notification and disable
       * UMS notification.
       */
      setMediaStorageNotification(
          com.android.internal.R.string.ext_media_checking_notification_title,
          com.android.internal.R.string.ext_media_checking_notification_message,
          com.android.internal.R.drawable.stat_notify_sdcard_prepare,
          true,
          false,
          null);
      updateUsbMassStorageNotification(false);
    } else if (newState.equals(Environment.MEDIA_MOUNTED)) {
      /*
       * Storage is now mounted. Dismiss any media notifications,
       * and enable UMS notification if connected.
       */
      setMediaStorageNotification(0, 0, 0, false, false, null);
      updateUsbMassStorageNotification(mUmsAvailable);
    } else if (newState.equals(Environment.MEDIA_UNMOUNTED)) {
      /*
       * Storage is now unmounted. We may have been unmounted
       * because the user is enabling/disabling UMS, in which case we don't
       * want to display the 'safe to unmount' notification.
       */
      if (!mStorageManager.isUsbMassStorageEnabled()) {
        if (oldState.equals(Environment.MEDIA_SHARED)) {
          /*
           * The unmount was due to UMS being enabled. Dismiss any
           * media notifications, and enable UMS notification if connected
           */
          setMediaStorageNotification(0, 0, 0, false, false, null);
          updateUsbMassStorageNotification(mUmsAvailable);
        } else {
          /*
           * Show safe to unmount media notification, and enable UMS
           * notification if connected.
           */
          if (Environment.isExternalStorageRemovable()) {
            setMediaStorageNotification(
                com.android.internal.R.string.ext_media_safe_unmount_notification_title,
                com.android.internal.R.string.ext_media_safe_unmount_notification_message,
                com.android.internal.R.drawable.stat_notify_sdcard,
                true,
                true,
                null);
          } else {
            // This device does not have removable storage, so
            // don't tell the user they can remove it.
            setMediaStorageNotification(0, 0, 0, false, false, null);
          }
          updateUsbMassStorageNotification(mUmsAvailable);
        }
      } else {
        /*
         * The unmount was due to UMS being enabled. Dismiss any
         * media notifications, and disable the UMS notification
         */
        setMediaStorageNotification(0, 0, 0, false, false, null);
        updateUsbMassStorageNotification(false);
      }
    } else if (newState.equals(Environment.MEDIA_NOFS)) {
      /*
       * Storage has no filesystem. Show blank media notification,
       * and enable UMS notification if connected.
       */
      Intent intent = new Intent();
      intent.setClass(mContext, com.android.internal.app.ExternalMediaFormatActivity.class);
      PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);

      setMediaStorageNotification(
          com.android.internal.R.string.ext_media_nofs_notification_title,
          com.android.internal.R.string.ext_media_nofs_notification_message,
          com.android.internal.R.drawable.stat_notify_sdcard_usb,
          true,
          false,
          pi);
      updateUsbMassStorageNotification(mUmsAvailable);
    } else if (newState.equals(Environment.MEDIA_UNMOUNTABLE)) {
      /*
       * Storage is corrupt. Show corrupt media notification,
       * and enable UMS notification if connected.
       */
      Intent intent = new Intent();
      intent.setClass(mContext, com.android.internal.app.ExternalMediaFormatActivity.class);
      PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);

      setMediaStorageNotification(
          com.android.internal.R.string.ext_media_unmountable_notification_title,
          com.android.internal.R.string.ext_media_unmountable_notification_message,
          com.android.internal.R.drawable.stat_notify_sdcard_usb,
          true,
          false,
          pi);
      updateUsbMassStorageNotification(mUmsAvailable);
    } else if (newState.equals(Environment.MEDIA_REMOVED)) {
      /*
       * Storage has been removed. Show nomedia media notification,
       * and disable UMS notification regardless of connection state.
       */
      setMediaStorageNotification(
          com.android.internal.R.string.ext_media_nomedia_notification_title,
          com.android.internal.R.string.ext_media_nomedia_notification_message,
          com.android.internal.R.drawable.stat_notify_sdcard_usb,
          true,
          false,
          null);
      updateUsbMassStorageNotification(false);
    } else if (newState.equals(Environment.MEDIA_BAD_REMOVAL)) {
      /*
       * Storage has been removed unsafely. Show bad removal media notification,
       * and disable UMS notification regardless of connection state.
       */
      setMediaStorageNotification(
          com.android.internal.R.string.ext_media_badremoval_notification_title,
          com.android.internal.R.string.ext_media_badremoval_notification_message,
          com.android.internal.R.drawable.stat_sys_warning,
          true,
          true,
          null);
      updateUsbMassStorageNotification(false);
    } else {
      Log.w(TAG, String.format("Ignoring unknown state {%s}", newState));
    }
  }