List of usage examples for android.os Environment MEDIA_SHARED
String MEDIA_SHARED
To view the source code for android.os Environment MEDIA_SHARED.
Click Source Link
From source file:com.android.server.MountService.java
private void notifyShareAvailabilityChange(final boolean avail) { synchronized (mListeners) { mUmsAvailable = avail;/*from ww w. j a va 2 s . c o m*/ for (int i = mListeners.size() - 1; i >= 0; i--) { MountServiceBinderListener bl = mListeners.get(i); try { bl.mListener.onUsbMassStorageConnectionChanged(avail); } catch (RemoteException rex) { Slog.e(TAG, "Listener dead"); mListeners.remove(i); } catch (Exception ex) { Slog.e(TAG, "Listener failed", ex); } } } if (mSystemReady == true) { sendUmsIntent(avail); } else { mSendUmsConnectedOnBoot = avail; } final StorageVolume primary = getPrimaryPhysicalVolume(); if (avail == false && primary != null && Environment.MEDIA_SHARED.equals(getVolumeState(primary.getPath()))) { final String path = primary.getPath(); /* * USB mass storage disconnected while enabled */ new Thread("MountService#AvailabilityChange") { @Override public void run() { try { int rc; Slog.w(TAG, "Disabling UMS after cable disconnect"); doShareUnshareVolume(path, "ums", false); if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) { Slog.e(TAG, String.format("Failed to remount {%s} on UMS enabled-disconnect (%d)", path, rc)); } } catch (Exception ex) { Slog.w(TAG, "Failed to mount media on UMS enabled-disconnect", ex); } } }.start(); } }
From source file:com.android.server.MountService.java
public void shutdown(final IMountShutdownObserver observer) { validatePermission(android.Manifest.permission.SHUTDOWN); Slog.i(TAG, "Shutting down"); synchronized (mVolumesLock) { // Get all volumes to be unmounted. MountShutdownLatch mountShutdownLatch = new MountShutdownLatch(observer, mVolumeStates.size()); for (String path : mVolumeStates.keySet()) { String state = mVolumeStates.get(path); if (state.equals(Environment.MEDIA_SHARED)) { /*/* ww w.j a v a2 s.co m*/ * If the media is currently shared, unshare it. * XXX: This is still dangerous!. We should not * be rebooting at *all* if UMS is enabled, since * the UMS host could have dirty FAT cache entries * yet to flush. */ setUsbMassStorageEnabled(false); } else if (state.equals(Environment.MEDIA_CHECKING)) { /* * If the media is being checked, then we need to wait for * it to complete before being able to proceed. */ // XXX: @hackbod - Should we disable the ANR timer here? int retries = 30; while (state.equals(Environment.MEDIA_CHECKING) && (retries-- >= 0)) { try { Thread.sleep(1000); } catch (InterruptedException iex) { Slog.e(TAG, "Interrupted while waiting for media", iex); break; } state = Environment.getExternalStorageState(); } if (retries == 0) { Slog.e(TAG, "Timed out waiting for media to check"); } } if (state.equals(Environment.MEDIA_MOUNTED)) { // Post a unmount message. ShutdownCallBack ucb = new ShutdownCallBack(path, mountShutdownLatch); mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb)); } else if (observer != null) { /* * Count down, since nothing will be done. The observer will be * notified when we are done so shutdown sequence can continue. */ mountShutdownLatch.countDown(); Slog.i(TAG, "Unmount completed: " + path + ", result code: " + StorageResultCode.OperationSucceeded); } } } }
From source file:com.android.server.MountService.java
public void unmountVolume(String path, boolean force, boolean removeEncryption) { validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); waitForReady();/*from w ww . java 2 s . co m*/ String volState = getVolumeState(path); if (DEBUG_UNMOUNT) { Slog.i(TAG, "Unmounting " + path + " force = " + force + " removeEncryption = " + removeEncryption); } if (Environment.MEDIA_UNMOUNTED.equals(volState) || Environment.MEDIA_REMOVED.equals(volState) || Environment.MEDIA_SHARED.equals(volState) || Environment.MEDIA_UNMOUNTABLE.equals(volState)) { // Media already unmounted or cannot be unmounted. // TODO return valid return code when adding observer call back. return; } UnmountCallBack ucb = new UnmountCallBack(path, force, removeEncryption); mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb)); }