Search in sources :

Example 36 with StorageVolume

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

the class UsbDeviceManager method systemReady.

public void systemReady() {
    if (DEBUG)
        Slog.d(TAG, "systemReady");
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    // We do not show the USB notification if the primary volume supports mass storage.
    // The legacy mass storage UI will be used instead.
    boolean massStorageSupported = false;
    final StorageManager storageManager = StorageManager.from(mContext);
    final StorageVolume primary = storageManager.getPrimaryVolume();
    massStorageSupported = primary != null && primary.allowMassStorage();
    mUseUsbNotification = !massStorageSupported;
    // make sure the ADB_ENABLED setting value matches the current state
    Settings.Global.putInt(mContentResolver, Settings.Global.ADB_ENABLED, mAdbEnabled ? 1 : 0);
    mHandler.sendEmptyMessage(MSG_SYSTEM_READY);
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager)

Example 37 with StorageVolume

use of android.os.storage.StorageVolume in project platform_frameworks_base by android.

the class MountService method getVolumeList.

@Override
public StorageVolume[] getVolumeList(int uid, String packageName, int flags) {
    final int userId = UserHandle.getUserId(uid);
    final boolean forWrite = (flags & StorageManager.FLAG_FOR_WRITE) != 0;
    final boolean realState = (flags & StorageManager.FLAG_REAL_STATE) != 0;
    final boolean includeInvisible = (flags & StorageManager.FLAG_INCLUDE_INVISIBLE) != 0;
    final boolean userKeyUnlocked;
    final boolean storagePermission;
    final long token = Binder.clearCallingIdentity();
    try {
        userKeyUnlocked = isUserKeyUnlocked(userId);
        storagePermission = mMountServiceInternal.hasExternalStorage(uid, packageName);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    boolean foundPrimary = false;
    final ArrayList<StorageVolume> res = new ArrayList<>();
    synchronized (mLock) {
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            switch(vol.getType()) {
                case VolumeInfo.TYPE_PUBLIC:
                case VolumeInfo.TYPE_EMULATED:
                    break;
                default:
                    continue;
            }
            boolean match = false;
            if (forWrite) {
                match = vol.isVisibleForWrite(userId);
            } else {
                match = vol.isVisibleForRead(userId) || (includeInvisible && vol.getPath() != null);
            }
            if (!match)
                continue;
            boolean reportUnmounted = false;
            if ((vol.getType() == VolumeInfo.TYPE_EMULATED) && !userKeyUnlocked) {
                reportUnmounted = true;
            } else if (!storagePermission && !realState) {
                reportUnmounted = true;
            }
            final StorageVolume userVol = vol.buildStorageVolume(mContext, userId, reportUnmounted);
            if (vol.isPrimary()) {
                res.add(0, userVol);
                foundPrimary = true;
            } else {
                res.add(userVol);
            }
        }
    }
    if (!foundPrimary) {
        Log.w(TAG, "No primary storage defined yet; hacking together a stub");
        final boolean primaryPhysical = SystemProperties.getBoolean(StorageManager.PROP_PRIMARY_PHYSICAL, false);
        final String id = "stub_primary";
        final File path = Environment.getLegacyExternalStorageDirectory();
        final String description = mContext.getString(android.R.string.unknownName);
        final boolean primary = true;
        final boolean removable = primaryPhysical;
        final boolean emulated = !primaryPhysical;
        final long mtpReserveSize = 0L;
        final boolean allowMassStorage = false;
        final long maxFileSize = 0L;
        final UserHandle owner = new UserHandle(userId);
        final String uuid = null;
        final String state = Environment.MEDIA_REMOVED;
        res.add(0, new StorageVolume(id, StorageVolume.STORAGE_ID_INVALID, path, description, primary, removable, emulated, mtpReserveSize, allowMassStorage, maxFileSize, owner, uuid, state));
    }
    return res.toArray(new StorageVolume[res.size()]);
}
Also used : StorageVolume(android.os.storage.StorageVolume) UserHandle(android.os.UserHandle) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) VolumeInfo(android.os.storage.VolumeInfo) File(java.io.File) AtomicFile(android.util.AtomicFile)

Example 38 with StorageVolume

use of android.os.storage.StorageVolume in project platform_frameworks_base by android.

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 (mLock) {
        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)

Example 39 with StorageVolume

use of android.os.storage.StorageVolume in project platform_frameworks_base by android.

the class UsbDeviceManager method systemReady.

public void systemReady() {
    if (DEBUG)
        Slog.d(TAG, "systemReady");
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    // We do not show the USB notification if the primary volume supports mass storage.
    // The legacy mass storage UI will be used instead.
    boolean massStorageSupported = false;
    final StorageManager storageManager = StorageManager.from(mContext);
    final StorageVolume primary = storageManager.getPrimaryVolume();
    massStorageSupported = primary != null && primary.allowMassStorage();
    mUseUsbNotification = !massStorageSupported && mContext.getResources().getBoolean(com.android.internal.R.bool.config_usbChargingMessage);
    // make sure the ADB_ENABLED setting value matches the current state
    try {
        Settings.Global.putInt(mContentResolver, Settings.Global.ADB_ENABLED, mAdbEnabled ? 1 : 0);
    } catch (SecurityException e) {
        // If UserManager.DISALLOW_DEBUGGING_FEATURES is on, that this setting can't be changed.
        Slog.d(TAG, "ADB_ENABLED is restricted.");
    }
    mHandler.sendEmptyMessage(MSG_SYSTEM_READY);
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager)

Example 40 with StorageVolume

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

the class MountService method getVolumeList.

@Override
public StorageVolume[] getVolumeList(int uid, String packageName, int flags) {
    final int userId = UserHandle.getUserId(uid);
    final boolean forWrite = (flags & StorageManager.FLAG_FOR_WRITE) != 0;
    final boolean realState = (flags & StorageManager.FLAG_REAL_STATE) != 0;
    final boolean includeInvisible = (flags & StorageManager.FLAG_INCLUDE_INVISIBLE) != 0;
    final boolean userKeyUnlocked;
    final boolean storagePermission;
    final long token = Binder.clearCallingIdentity();
    try {
        userKeyUnlocked = isUserKeyUnlocked(userId);
        storagePermission = mMountServiceInternal.hasExternalStorage(uid, packageName);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    boolean foundPrimary = false;
    final ArrayList<StorageVolume> res = new ArrayList<>();
    synchronized (mLock) {
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            switch(vol.getType()) {
                case VolumeInfo.TYPE_PUBLIC:
                case VolumeInfo.TYPE_EMULATED:
                    break;
                default:
                    continue;
            }
            boolean match = false;
            if (forWrite) {
                match = vol.isVisibleForWrite(userId);
            } else {
                match = vol.isVisibleForRead(userId) || (includeInvisible && vol.getPath() != null);
            }
            if (!match)
                continue;
            boolean reportUnmounted = false;
            if ((vol.getType() == VolumeInfo.TYPE_EMULATED) && !userKeyUnlocked) {
                reportUnmounted = true;
            } else if (!storagePermission && !realState) {
                reportUnmounted = true;
            }
            final StorageVolume userVol = vol.buildStorageVolume(mContext, userId, reportUnmounted);
            if (vol.isPrimary()) {
                res.add(0, userVol);
                foundPrimary = true;
            } else {
                res.add(userVol);
            }
        }
    }
    if (!foundPrimary) {
        Log.w(TAG, "No primary storage defined yet; hacking together a stub");
        final boolean primaryPhysical = SystemProperties.getBoolean(StorageManager.PROP_PRIMARY_PHYSICAL, false);
        final String id = "stub_primary";
        final File path = Environment.getLegacyExternalStorageDirectory();
        final String description = mContext.getString(android.R.string.unknownName);
        final boolean primary = true;
        final boolean removable = primaryPhysical;
        final boolean emulated = !primaryPhysical;
        final long mtpReserveSize = 0L;
        final boolean allowMassStorage = false;
        final long maxFileSize = 0L;
        final UserHandle owner = new UserHandle(userId);
        final String uuid = null;
        final String state = Environment.MEDIA_REMOVED;
        res.add(0, new StorageVolume(id, StorageVolume.STORAGE_ID_INVALID, path, description, primary, removable, emulated, mtpReserveSize, allowMassStorage, maxFileSize, owner, uuid, state));
    }
    return res.toArray(new StorageVolume[res.size()]);
}
Also used : StorageVolume(android.os.storage.StorageVolume) UserHandle(android.os.UserHandle) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) VolumeInfo(android.os.storage.VolumeInfo) File(java.io.File) AtomicFile(android.util.AtomicFile)

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