Search in sources :

Example 11 with StorageVolume

use of android.os.storage.StorageVolume in project cw-omnibus by commonsguy.

the class VolumeHelper method onPreferenceChange.

@Override
public boolean onPreferenceChange(Preference pref, Object o) {
    StorageManager storage = pref.getContext().getSystemService(StorageManager.class);
    List<StorageVolume> volumes = storage.getStorageVolumes();
    String uuid = o.toString();
    for (StorageVolume volume : volumes) {
        if ((volume.getUuid() == null && uuid.equals(SettingsFragment.STORAGE_FAKE_UUID)) || (uuid.equals(volume.getUuid()))) {
            Intent i = volume.createAccessIntent(dirName);
            host.startActivityForHelper(i, this);
            break;
        }
    }
    return (true);
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager) Intent(android.content.Intent)

Example 12 with StorageVolume

use of android.os.storage.StorageVolume in project android_frameworks_base by ResurrectionRemix.

the class SharedStorageAgent method onFullBackup.

/**
     * Full backup of the shared-storage filesystem
     */
@Override
public void onFullBackup(FullBackupDataOutput output) throws IOException {
    // "primary" shared storage volume is first in the list.
    if (mVolumes != null) {
        if (DEBUG)
            Slog.i(TAG, "Backing up " + mVolumes.length + " shared volumes");
        // Ignore all apps' getExternalFilesDir() content; it is backed up as part of
        // each app-specific payload.
        ArraySet<String> externalFilesDirFilter = new ArraySet();
        final File externalAndroidRoot = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_ANDROID);
        externalFilesDirFilter.add(externalAndroidRoot.getCanonicalPath());
        for (int i = 0; i < mVolumes.length; i++) {
            StorageVolume v = mVolumes[i];
            // Express the contents of volume N this way in the tar stream:
            //     shared/N/path/to/file
            // The restore will then extract to the given volume
            String domain = FullBackup.SHARED_PREFIX + i;
            fullBackupFileTree(null, domain, v.getPath(), null, /* manifestExcludes */
            externalFilesDirFilter, /* systemExcludes */
            output);
        }
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) ArraySet(android.util.ArraySet) File(java.io.File)

Example 13 with StorageVolume

use of android.os.storage.StorageVolume in project android_frameworks_base by ResurrectionRemix.

the class OpenExternalDirectoryActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        if (DEBUG)
            Log.d(TAG, "activity.onCreateDialog(): reusing instance");
        return;
    }
    final Intent intent = getIntent();
    if (intent == null) {
        if (DEBUG)
            Log.d(TAG, "missing intent");
        logInvalidScopedAccessRequest(this, SCOPED_DIRECTORY_ACCESS_INVALID_ARGUMENTS);
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    final Parcelable storageVolume = intent.getParcelableExtra(EXTRA_STORAGE_VOLUME);
    if (!(storageVolume instanceof StorageVolume)) {
        if (DEBUG)
            Log.d(TAG, "extra " + EXTRA_STORAGE_VOLUME + " is not a StorageVolume: " + storageVolume);
        logInvalidScopedAccessRequest(this, SCOPED_DIRECTORY_ACCESS_INVALID_ARGUMENTS);
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    String directoryName = intent.getStringExtra(EXTRA_DIRECTORY_NAME);
    if (directoryName == null) {
        directoryName = DIRECTORY_ROOT;
    }
    final StorageVolume volume = (StorageVolume) storageVolume;
    if (getScopedAccessPermissionStatus(getApplicationContext(), getCallingPackage(), volume.getUuid(), directoryName) == PERMISSION_NEVER_ASK) {
        logValidScopedAccessRequest(this, directoryName, SCOPED_DIRECTORY_ACCESS_ALREADY_DENIED);
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    final int userId = UserHandle.myUserId();
    if (!showFragment(this, userId, volume, directoryName)) {
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) Intent(android.content.Intent) Parcelable(android.os.Parcelable) SuppressLint(android.annotation.SuppressLint)

Example 14 with StorageVolume

use of android.os.storage.StorageVolume in project android_frameworks_base by ResurrectionRemix.

the class PackageHelper method fitsOnExternal.

public static boolean fitsOnExternal(Context context, long sizeBytes) {
    final StorageManager storage = context.getSystemService(StorageManager.class);
    final StorageVolume primary = storage.getPrimaryVolume();
    return (sizeBytes > 0) && !primary.isEmulated() && Environment.MEDIA_MOUNTED.equals(primary.getState()) && sizeBytes <= storage.getStorageBytesUntilLow(primary.getPathFile());
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager)

Example 15 with StorageVolume

use of android.os.storage.StorageVolume in project android_frameworks_base by DirtyUnicorns.

the class MountService method onUnlockUser.

private void onUnlockUser(int userId) {
    Slog.d(TAG, "onUnlockUser " + userId);
    // bind mount against.
    try {
        mConnector.execute("volume", "user_started", userId);
    } catch (NativeDaemonConnectorException ignored) {
    }
    // correctly, then synthesize events for any already-mounted volumes.
    synchronized (mVolumes) {
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            if (vol.isVisibleForRead(userId) && vol.isMountedReadable()) {
                final StorageVolume userVol = vol.buildStorageVolume(mContext, userId, false);
                mHandler.obtainMessage(H_VOLUME_BROADCAST, userVol).sendToTarget();
                final String envState = VolumeInfo.getEnvironmentForState(vol.getState());
                mCallbacks.notifyStorageStateChanged(userVol.getPath(), envState, envState);
            }
        }
        mSystemUnlockedUsers = ArrayUtils.appendInt(mSystemUnlockedUsers, userId);
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) VolumeInfo(android.os.storage.VolumeInfo)

Aggregations

StorageVolume (android.os.storage.StorageVolume)53 StorageManager (android.os.storage.StorageManager)13 File (java.io.File)13 Intent (android.content.Intent)11 VolumeInfo (android.os.storage.VolumeInfo)10 UserHandle (android.os.UserHandle)6 ArrayList (java.util.ArrayList)6 SuppressLint (android.annotation.SuppressLint)5 Parcelable (android.os.Parcelable)5 VolumeRecord (android.os.storage.VolumeRecord)5 ArraySet (android.util.ArraySet)5 AtomicFile (android.util.AtomicFile)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IOException (java.io.IOException)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 HandlerThread (android.os.HandlerThread)2 RemoteException (android.os.RemoteException)2 IMountService (android.os.storage.IMountService)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2