Search in sources :

Example 46 with StorageVolume

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

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 47 with StorageVolume

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

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 48 with StorageVolume

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

the class MountService method onVolumeStateChangedLocked.

private void onVolumeStateChangedLocked(VolumeInfo vol, int oldState, int newState) {
    // metadata, or so we can annoy them when a private volume is ejected
    if (vol.isMountedReadable() && !TextUtils.isEmpty(vol.fsUuid)) {
        VolumeRecord rec = mRecords.get(vol.fsUuid);
        if (rec == null) {
            rec = new VolumeRecord(vol.type, vol.fsUuid);
            rec.partGuid = vol.partGuid;
            rec.createdMillis = System.currentTimeMillis();
            if (vol.type == VolumeInfo.TYPE_PRIVATE) {
                rec.nickname = vol.disk.getDescription();
            }
            mRecords.put(rec.fsUuid, rec);
            writeSettingsLocked();
        } else {
            // Handle upgrade case where we didn't store partition GUID
            if (TextUtils.isEmpty(rec.partGuid)) {
                rec.partGuid = vol.partGuid;
                writeSettingsLocked();
            }
        }
    }
    mCallbacks.notifyVolumeStateChanged(vol, oldState, newState);
    // processes that receive the intent unnecessarily.
    if (mBootCompleted && isBroadcastWorthy(vol)) {
        final Intent intent = new Intent(VolumeInfo.ACTION_VOLUME_STATE_CHANGED);
        intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.id);
        intent.putExtra(VolumeInfo.EXTRA_VOLUME_STATE, newState);
        intent.putExtra(VolumeRecord.EXTRA_FS_UUID, vol.fsUuid);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        mHandler.obtainMessage(H_INTERNAL_BROADCAST, intent).sendToTarget();
    }
    final String oldStateEnv = VolumeInfo.getEnvironmentForState(oldState);
    final String newStateEnv = VolumeInfo.getEnvironmentForState(newState);
    if (!Objects.equals(oldStateEnv, newStateEnv)) {
        // user-specific broadcasts.
        for (int userId : mSystemUnlockedUsers) {
            if (vol.isVisibleForRead(userId)) {
                final StorageVolume userVol = vol.buildStorageVolume(mContext, userId, false);
                mHandler.obtainMessage(H_VOLUME_BROADCAST, userVol).sendToTarget();
                mCallbacks.notifyStorageStateChanged(userVol.getPath(), oldStateEnv, newStateEnv);
            }
        }
    }
    if (vol.type == VolumeInfo.TYPE_PUBLIC && vol.state == VolumeInfo.STATE_EJECTING) {
        // TODO: this should eventually be handled by new ObbVolume state changes
        /*
             * 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, vol.path));
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) StorageVolume(android.os.storage.StorageVolume) Intent(android.content.Intent)

Example 49 with StorageVolume

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

the class MountService method onVolumeStateChangedLocked.

private void onVolumeStateChangedLocked(VolumeInfo vol, int oldState, int newState) {
    // metadata, or so we can annoy them when a private volume is ejected
    if (vol.isMountedReadable() && !TextUtils.isEmpty(vol.fsUuid)) {
        VolumeRecord rec = mRecords.get(vol.fsUuid);
        if (rec == null) {
            rec = new VolumeRecord(vol.type, vol.fsUuid);
            rec.partGuid = vol.partGuid;
            rec.createdMillis = System.currentTimeMillis();
            if (vol.type == VolumeInfo.TYPE_PRIVATE) {
                rec.nickname = vol.disk.getDescription();
            }
            mRecords.put(rec.fsUuid, rec);
            writeSettingsLocked();
        } else {
            // Handle upgrade case where we didn't store partition GUID
            if (TextUtils.isEmpty(rec.partGuid)) {
                rec.partGuid = vol.partGuid;
                writeSettingsLocked();
            }
        }
    }
    mCallbacks.notifyVolumeStateChanged(vol, oldState, newState);
    // processes that receive the intent unnecessarily.
    if (mBootCompleted && isBroadcastWorthy(vol)) {
        final Intent intent = new Intent(VolumeInfo.ACTION_VOLUME_STATE_CHANGED);
        intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.id);
        intent.putExtra(VolumeInfo.EXTRA_VOLUME_STATE, newState);
        intent.putExtra(VolumeRecord.EXTRA_FS_UUID, vol.fsUuid);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        mHandler.obtainMessage(H_INTERNAL_BROADCAST, intent).sendToTarget();
    }
    final String oldStateEnv = VolumeInfo.getEnvironmentForState(oldState);
    final String newStateEnv = VolumeInfo.getEnvironmentForState(newState);
    if (!Objects.equals(oldStateEnv, newStateEnv)) {
        // user-specific broadcasts.
        for (int userId : mSystemUnlockedUsers) {
            if (vol.isVisibleForRead(userId)) {
                final StorageVolume userVol = vol.buildStorageVolume(mContext, userId, false);
                mHandler.obtainMessage(H_VOLUME_BROADCAST, userVol).sendToTarget();
                mCallbacks.notifyStorageStateChanged(userVol.getPath(), oldStateEnv, newStateEnv);
            }
        }
    }
    if (vol.type == VolumeInfo.TYPE_PUBLIC && vol.state == VolumeInfo.STATE_EJECTING) {
        // TODO: this should eventually be handled by new ObbVolume state changes
        /*
             * 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, vol.path));
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) StorageVolume(android.os.storage.StorageVolume) Intent(android.content.Intent)

Example 50 with StorageVolume

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

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)59 StorageManager (android.os.storage.StorageManager)18 File (java.io.File)16 Intent (android.content.Intent)14 VolumeInfo (android.os.storage.VolumeInfo)10 ArrayList (java.util.ArrayList)7 SuppressLint (android.annotation.SuppressLint)6 UserHandle (android.os.UserHandle)6 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