Search in sources :

Example 1 with VolumeRecord

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

the class StorageNotification method updateMissingPrivateVolumes.

private void updateMissingPrivateVolumes() {
    final List<VolumeRecord> recs = mStorageManager.getVolumeRecords();
    for (VolumeRecord rec : recs) {
        if (rec.getType() != VolumeInfo.TYPE_PRIVATE)
            continue;
        final String fsUuid = rec.getFsUuid();
        final VolumeInfo info = mStorageManager.findVolumeByUuid(fsUuid);
        if ((info != null && info.isMountedWritable()) || rec.isSnoozed()) {
            // Yay, private volume is here, or user snoozed
            mNotificationManager.cancelAsUser(fsUuid, PRIVATE_ID, UserHandle.ALL);
        } else {
            // Boo, annoy the user to reinsert the private volume
            final CharSequence title = mContext.getString(R.string.ext_media_missing_title, rec.getNickname());
            final CharSequence text = mContext.getString(R.string.ext_media_missing_message);
            Notification.Builder builder = new Notification.Builder(mContext).setSmallIcon(R.drawable.ic_sd_card_48dp).setColor(mContext.getColor(R.color.system_notification_accent_color)).setContentTitle(title).setContentText(text).setContentIntent(buildForgetPendingIntent(rec)).setStyle(new Notification.BigTextStyle().bigText(text)).setVisibility(Notification.VISIBILITY_PUBLIC).setLocalOnly(true).setCategory(Notification.CATEGORY_SYSTEM).setDeleteIntent(buildSnoozeIntent(fsUuid));
            SystemUI.overrideNotificationAppName(mContext, builder);
            mNotificationManager.notifyAsUser(fsUuid, PRIVATE_ID, builder.build(), UserHandle.ALL);
        }
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) VolumeInfo(android.os.storage.VolumeInfo) Notification(android.app.Notification)

Example 2 with VolumeRecord

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

the class MountService method forgetVolume.

@Override
public void forgetVolume(String fsUuid) {
    enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();
    Preconditions.checkNotNull(fsUuid);
    synchronized (mLock) {
        final VolumeRecord rec = mRecords.remove(fsUuid);
        if (rec != null && !TextUtils.isEmpty(rec.partGuid)) {
            mHandler.obtainMessage(H_PARTITION_FORGET, rec.partGuid).sendToTarget();
        }
        mCallbacks.notifyVolumeForgotten(fsUuid);
        // reset vold so we bind into new volume into place.
        if (Objects.equals(mPrimaryStorageUuid, fsUuid)) {
            mPrimaryStorageUuid = getDefaultPrimaryStorageUuid();
            mHandler.obtainMessage(H_RESET).sendToTarget();
        }
        writeSettingsLocked();
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord)

Example 3 with VolumeRecord

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

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 4 with VolumeRecord

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

the class MountService method forgetAllVolumes.

@Override
public void forgetAllVolumes() {
    enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();
    synchronized (mLock) {
        for (int i = 0; i < mRecords.size(); i++) {
            final String fsUuid = mRecords.keyAt(i);
            final VolumeRecord rec = mRecords.valueAt(i);
            if (!TextUtils.isEmpty(rec.partGuid)) {
                mHandler.obtainMessage(H_PARTITION_FORGET, rec.partGuid).sendToTarget();
            }
            mCallbacks.notifyVolumeForgotten(fsUuid);
        }
        mRecords.clear();
        if (!Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, mPrimaryStorageUuid)) {
            mPrimaryStorageUuid = getDefaultPrimaryStorageUuid();
        }
        writeSettingsLocked();
        mHandler.obtainMessage(H_RESET).sendToTarget();
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord)

Example 5 with VolumeRecord

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

the class MountService method shouldBenchmark.

private boolean shouldBenchmark() {
    final long benchInterval = Settings.Global.getLong(mContext.getContentResolver(), Settings.Global.STORAGE_BENCHMARK_INTERVAL, DateUtils.WEEK_IN_MILLIS);
    if (benchInterval == -1) {
        return false;
    } else if (benchInterval == 0) {
        return true;
    }
    synchronized (mLock) {
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            final VolumeRecord rec = mRecords.get(vol.fsUuid);
            if (vol.isMountedWritable() && rec != null) {
                final long benchAge = System.currentTimeMillis() - rec.lastBenchMillis;
                if (benchAge >= benchInterval) {
                    return true;
                }
            }
        }
        return false;
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) VolumeInfo(android.os.storage.VolumeInfo)

Aggregations

VolumeRecord (android.os.storage.VolumeRecord)61 VolumeInfo (android.os.storage.VolumeInfo)16 DiskInfo (android.os.storage.DiskInfo)11 Notification (android.app.Notification)10 IOException (java.io.IOException)10 Intent (android.content.Intent)6 Action (android.app.Notification.Action)5 PendingIntent (android.app.PendingIntent)5 IBinder (android.os.IBinder)5 RemoteCallbackList (android.os.RemoteCallbackList)5 StorageVolume (android.os.storage.StorageVolume)5 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)5 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)5 FileInputStream (java.io.FileInputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 FileOutputStream (java.io.FileOutputStream)5 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 Entry (java.util.Map.Entry)5