int putStringFromNative(int nativeKey, String value) {
   String key = getKeyFromNativeKey(nativeKey);
   if (!METADATA_KEYS_TYPE.containsKey(key) || METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_TEXT) {
     return -1;
   }
   mBundle.putString(key, value);
   return 0;
 }
 /**
  * Put a {@link Bitmap} into the meta data. Custom keys may be used, but if the METADATA_KEYs
  * defined in this class are used they may only be one of the following:
  *
  * <ul>
  *   <li>{@link #METADATA_KEY_ICON}
  *   <li>{@link #METADATA_KEY_ART}
  * </ul>
  *
  * <p>
  *
  * @param key The key for referencing this value
  * @param value The Bitmap to store
  * @return the same Builder instance
  */
 public Builder putBitmap(String key, Bitmap value) {
   if (!METADATA_KEYS_TYPE.containsKey(key)
       || METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_BITMAP) {
     throw new IllegalArgumentException("The " + key + " key cannot be used to put a Bitmap");
   }
   mBundle.putParcelable(key, value);
   return this;
 }
 /**
  * Put an int value into the meta data. Custom keys may be used, but if the METADATA_KEYs
  * defined in this class are used they may only be one of the following:
  *
  * <ul>
  *   <li>{@link #METADATA_KEY_RDS_PTY}
  *   <li>{@link #METADATA_KEY_RBDS_PTY}
  * </ul>
  *
  * @param key The key for referencing this value
  * @param value The int value to store
  * @return the same Builder instance
  */
 public Builder putInt(String key, int value) {
   if (!METADATA_KEYS_TYPE.containsKey(key)
       || METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_INT) {
     throw new IllegalArgumentException("The " + key + " key cannot be used to put a long");
   }
   mBundle.putInt(key, value);
   return this;
 }
  public void addSimulatedPort(String portId, int supportedModes, IndentingPrintWriter pw) {
    synchronized (mLock) {
      if (mSimulatedPorts.containsKey(portId)) {
        pw.println("Port with same name already exists.  Please remove it first.");
        return;
      }

      pw.println(
          "Adding simulated port: portId="
              + portId
              + ", supportedModes="
              + UsbPort.modeToString(supportedModes));
      mSimulatedPorts.put(portId, new SimulatedPortInfo(portId, supportedModes));
      updatePortsLocked(pw);
    }
  }
 int putBitmapFromNative(int nativeKey, byte[] value) {
   String key = getKeyFromNativeKey(nativeKey);
   if (!METADATA_KEYS_TYPE.containsKey(key)
       || METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_BITMAP) {
     return -1;
   }
   Bitmap bmp = null;
   try {
     bmp = BitmapFactory.decodeByteArray(value, 0, value.length);
   } catch (Exception e) {
   } finally {
     if (bmp == null) {
       return -1;
     }
     mBundle.putParcelable(key, bmp);
     return 0;
   }
 }
  private void updateVolumesLocked() {
    mRoots.clear();

    final int userId = UserHandle.myUserId();
    final List<VolumeInfo> volumes = mStorageManager.getVolumes();
    for (VolumeInfo volume : volumes) {
      if (!volume.isMountedReadable()) continue;

      final String rootId;
      final String title;
      if (volume.getType() == VolumeInfo.TYPE_EMULATED) {
        // We currently only support a single emulated volume mounted at
        // a time, and it's always considered the primary
        rootId = ROOT_ID_PRIMARY_EMULATED;
        if (VolumeInfo.ID_EMULATED_INTERNAL.equals(volume.getId())) {
          title = getContext().getString(R.string.root_internal_storage);
        } else {
          final VolumeInfo privateVol = mStorageManager.findPrivateForEmulated(volume);
          title = mStorageManager.getBestVolumeDescription(privateVol);
        }
      } else if (volume.getType() == VolumeInfo.TYPE_PUBLIC) {
        rootId = volume.getFsUuid();
        title = mStorageManager.getBestVolumeDescription(volume);
      } else {
        // Unsupported volume; ignore
        continue;
      }

      if (TextUtils.isEmpty(rootId)) {
        Log.d(TAG, "Missing UUID for " + volume.getId() + "; skipping");
        continue;
      }
      if (mRoots.containsKey(rootId)) {
        Log.w(TAG, "Duplicate UUID " + rootId + " for " + volume.getId() + "; skipping");
        continue;
      }

      try {
        final RootInfo root = new RootInfo();
        mRoots.put(rootId, root);

        root.rootId = rootId;
        root.flags =
            Root.FLAG_SUPPORTS_CREATE
                | Root.FLAG_LOCAL_ONLY
                | Root.FLAG_ADVANCED
                | Root.FLAG_SUPPORTS_SEARCH
                | Root.FLAG_SUPPORTS_IS_CHILD;
        root.title = title;
        if (volume.getType() == VolumeInfo.TYPE_PUBLIC) {
          root.flags |= Root.FLAG_HAS_SETTINGS;
        }
        if (volume.isVisibleForRead(userId)) {
          root.visiblePath = volume.getPathForUser(userId);
        } else {
          root.visiblePath = null;
        }
        root.path = volume.getInternalPathForUser(userId);
        root.docId = getDocIdForFile(root.path);

      } catch (FileNotFoundException e) {
        throw new IllegalStateException(e);
      }
    }

    Log.d(TAG, "After updating volumes, found " + mRoots.size() + " active roots");

    // Note this affects content://com.android.externalstorage.documents/root/39BD-07C5
    // as well as content://com.android.externalstorage.documents/document/*/children,
    // so just notify on content://com.android.externalstorage.documents/.
    getContext().getContentResolver().notifyChange(BASE_URI, null, false);
  }