Example usage for android.os.storage StorageVolume getPath

List of usage examples for android.os.storage StorageVolume getPath

Introduction

In this page you can find the example usage for android.os.storage StorageVolume getPath.

Prototype

@UnsupportedAppUsage
public String getPath() 

Source Link

Document

Returns the mount path for the volume.

Usage

From source file:com.mediatek.contacts.activities.ActivitiesUtils.java

private static int getAvailableStorageCount(Activity activity) {
    int storageCount = 0;
    final StorageManager storageManager = (StorageManager) activity.getApplicationContext()
            .getSystemService(activity.STORAGE_SERVICE);
    if (null == storageManager) {
        Log.w(TAG, "[getAvailableStorageCount]storageManager is null,return 0.");
        return 0;
    }//from w w  w.  j a  v  a2s  .  com
    StorageVolume[] volumes = storageManager.getVolumeList();
    for (StorageVolume volume : volumes) {
        String path = volume.getPath();
        if (!Environment.MEDIA_MOUNTED.equals(storageManager.getVolumeState(path))) {
            continue;
        }
        storageCount++;
    }
    Log.d(TAG, "[getAvailableStorageCount]storageCount = " + storageCount);
    return storageCount;
}

From source file:com.freeme.filemanager.view.FileViewFragment.java

private void initVolumeState(StorageVolume paramStorageVolume) {
    if (paramStorageVolume == null) {
        return;//from ww w  .jav a 2s .  c o  m
    }
    this.mVolumePath = paramStorageVolume.getPath();
    this.mVolumeDescription = paramStorageVolume.getDescription(this.mActivity);
    //*/ freeme.liuhaoran , 20160728 , adapter zhanxun M
    if (paramStorageVolume.getStorageId() == 0) {
        mVolumeDescription = getString(R.string.storage_phone);
    }
    //*/
    Log.i("liuhaoran",
            "mVolumeDescription = " + mVolumeDescription + "----" + paramStorageVolume.getStorageId());
    if (mFileViewInteractionHub == null) {
        mFileViewInteractionHub = new FileViewInteractionHub(this, 1);
    }
    mFileViewInteractionHub.setRootPath(this.mVolumePath);
}

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

private void updatePublicVolumeState(StorageVolume volume, String state) {
    final String path = volume.getPath();
    final String oldState;
    synchronized (mVolumesLock) {
        oldState = mVolumeStates.put(path, state);
        volume.setState(state);/*  w w w. j av  a  2s .c  om*/
    }

    if (state.equals(oldState)) {
        Slog.w(TAG, String.format("Duplicate state transition (%s -> %s) for %s", state, state, path));
        return;
    }

    Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")");

    // Tell PackageManager about changes to primary volume state, but only
    // when not emulated.
    if (volume.isPrimary() && !volume.isEmulated()) {
        if (Environment.MEDIA_UNMOUNTED.equals(state)) {
            mPms.updateExternalMediaStatus(false, false);

            /*
             * Some OBBs might have been unmounted when this volume was
             * unmounted, so send a message to the handler to let it know to
             * remove those from the list of mounted OBBS.
             */
            mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_FLUSH_MOUNT_STATE, path));
        } else if (Environment.MEDIA_MOUNTED.equals(state)) {
            mPms.updateExternalMediaStatus(true, false);
        }
    }

    synchronized (mListeners) {
        for (int i = mListeners.size() - 1; i >= 0; i--) {
            MountServiceBinderListener bl = mListeners.get(i);
            try {
                bl.mListener.onStorageStateChanged(path, oldState, state);
            } catch (RemoteException rex) {
                Slog.e(TAG, "Listener dead");
                mListeners.remove(i);
            } catch (Exception ex) {
                Slog.e(TAG, "Listener failed", ex);
            }
        }
    }
}

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

private void sendStorageIntent(String action, StorageVolume volume, UserHandle user) {
    final Intent intent = new Intent(action, Uri.parse("file://" + volume.getPath()));
    intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, volume);
    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
    Slog.d(TAG, "sendStorageIntent " + intent + " to " + user);
    mContext.sendBroadcastAsUser(intent, user);
}

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

public boolean isUsbMassStorageEnabled() {
    waitForReady();//from w  w w  . j  av a2 s .co  m

    final StorageVolume primary = getPrimaryPhysicalVolume();
    if (primary != null) {
        return doGetVolumeShared(primary.getPath(), "ums");
    } else {
        return false;
    }
}

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

private void removeVolumeLocked(StorageVolume volume) {
    Slog.d(TAG, "removeVolumeLocked() " + volume);
    mVolumes.remove(volume);/*from  w w w  .  j a  v a  2s . c  o m*/
    mVolumesByPath.remove(volume.getPath());
    mVolumeStates.remove(volume.getPath());
}

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

private void addVolumeLocked(StorageVolume volume) {
    Slog.d(TAG, "addVolumeLocked() " + volume);
    mVolumes.add(volume);//from  w w w .  ja  va 2 s.c o  m
    final StorageVolume existing = mVolumesByPath.put(volume.getPath(), volume);
    if (existing != null) {
        throw new IllegalStateException("Volume at " + volume.getPath() + " already exists: " + existing);
    }
}

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

private void notifyShareAvailabilityChange(final boolean avail) {
    synchronized (mListeners) {
        mUmsAvailable = avail;//  w  w  w.  java  2 s.co 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

private void warnOnNotMounted() {
    final StorageVolume primary = getPrimaryPhysicalVolume();
    if (primary != null) {
        boolean mounted = false;
        try {/*from   w  ww .j  a  va2s . c om*/
            mounted = Environment.MEDIA_MOUNTED.equals(getVolumeState(primary.getPath()));
        } catch (IllegalArgumentException e) {
        }

        if (!mounted) {
            Slog.w(TAG, "getSecureContainerList() called when storage not mounted");
        }
    }
}

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

@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);

    final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ", 160);

    synchronized (mObbMounts) {
        pw.println("mObbMounts:");
        pw.increaseIndent();/*from   w  ww  . j  a  va 2 s  .c  o m*/
        final Iterator<Entry<IBinder, List<ObbState>>> binders = mObbMounts.entrySet().iterator();
        while (binders.hasNext()) {
            Entry<IBinder, List<ObbState>> e = binders.next();
            pw.println(e.getKey() + ":");
            pw.increaseIndent();
            final List<ObbState> obbStates = e.getValue();
            for (final ObbState obbState : obbStates) {
                pw.println(obbState);
            }
            pw.decreaseIndent();
        }
        pw.decreaseIndent();

        pw.println();
        pw.println("mObbPathToStateMap:");
        pw.increaseIndent();
        final Iterator<Entry<String, ObbState>> maps = mObbPathToStateMap.entrySet().iterator();
        while (maps.hasNext()) {
            final Entry<String, ObbState> e = maps.next();
            pw.print(e.getKey());
            pw.print(" -> ");
            pw.println(e.getValue());
        }
        pw.decreaseIndent();
    }

    synchronized (mVolumesLock) {
        pw.println();
        pw.println("mVolumes:");
        pw.increaseIndent();
        for (StorageVolume volume : mVolumes) {
            pw.println(volume);
            pw.increaseIndent();
            pw.println("Current state: " + mVolumeStates.get(volume.getPath()));
            pw.decreaseIndent();
        }
        pw.decreaseIndent();
    }

    pw.println();
    pw.println("mConnection:");
    pw.increaseIndent();
    mConnector.dump(fd, pw, args);
    pw.decreaseIndent();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    pw.println();
    pw.print("Last maintenance: ");
    pw.println(sdf.format(new Date(mLastMaintenance)));
}