Search in sources :

Example 46 with VolumeRecord

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

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)

Example 47 with VolumeRecord

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

the class MountService method setVolumeNickname.

@Override
public void setVolumeNickname(String fsUuid, String nickname) {
    enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();
    Preconditions.checkNotNull(fsUuid);
    synchronized (mLock) {
        final VolumeRecord rec = mRecords.get(fsUuid);
        rec.nickname = nickname;
        mCallbacks.notifyVolumeRecordChanged(rec);
        writeSettingsLocked();
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord)

Example 48 with VolumeRecord

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

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, SystemMessage.NOTE_STORAGE_PRIVATE, 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, SystemMessage.NOTE_STORAGE_PRIVATE, builder.build(), UserHandle.ALL);
        }
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) VolumeInfo(android.os.storage.VolumeInfo) Notification(android.app.Notification)

Example 49 with VolumeRecord

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

the class StorageNotification method onVolumeMounted.

private Notification onVolumeMounted(VolumeInfo vol) {
    final VolumeRecord rec = mStorageManager.findRecordByUuid(vol.getFsUuid());
    final DiskInfo disk = vol.getDisk();
    // used to allow snoozing non-adoptable disks too.)
    if (rec.isSnoozed() && disk.isAdoptable()) {
        return null;
    }
    if (disk.isAdoptable() && !rec.isInited()) {
        final CharSequence title = disk.getDescription();
        final CharSequence text = mContext.getString(R.string.ext_media_new_notification_message, disk.getDescription());
        final PendingIntent initIntent = buildInitPendingIntent(vol);
        return buildNotificationBuilder(vol, title, text).addAction(new Action(R.drawable.ic_settings_24dp, mContext.getString(R.string.ext_media_init_action), initIntent)).addAction(new Action(R.drawable.ic_eject_24dp, mContext.getString(R.string.ext_media_unmount_action), buildUnmountPendingIntent(vol))).setContentIntent(initIntent).setDeleteIntent(buildSnoozeIntent(vol.getFsUuid())).setCategory(Notification.CATEGORY_SYSTEM).build();
    } else {
        final CharSequence title = disk.getDescription();
        final CharSequence text = mContext.getString(R.string.ext_media_ready_notification_message, disk.getDescription());
        final PendingIntent browseIntent = buildBrowsePendingIntent(vol);
        final Notification.Builder builder = buildNotificationBuilder(vol, title, text).addAction(new Action(R.drawable.ic_folder_24dp, mContext.getString(R.string.ext_media_browse_action), browseIntent)).addAction(new Action(R.drawable.ic_eject_24dp, mContext.getString(R.string.ext_media_unmount_action), buildUnmountPendingIntent(vol))).setContentIntent(browseIntent).setCategory(Notification.CATEGORY_SYSTEM).setPriority(Notification.PRIORITY_LOW);
        // USB disks notification can be persistent
        if (disk.isUsb()) {
            builder.setOngoing(mContext.getResources().getBoolean(R.bool.config_persistUsbDriveNotification));
        }
        // Non-adoptable disks can't be snoozed.
        if (disk.isAdoptable()) {
            builder.setDeleteIntent(buildSnoozeIntent(vol.getFsUuid()));
        }
        return builder.build();
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) Action(android.app.Notification.Action) DiskInfo(android.os.storage.DiskInfo) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 50 with VolumeRecord

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

the class MountService method writeSettingsLocked.

private void writeSettingsLocked() {
    FileOutputStream fos = null;
    try {
        fos = mSettingsFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_VOLUMES);
        writeIntAttribute(out, ATTR_VERSION, VERSION_FIX_PRIMARY);
        writeStringAttribute(out, ATTR_PRIMARY_STORAGE_UUID, mPrimaryStorageUuid);
        writeBooleanAttribute(out, ATTR_FORCE_ADOPTABLE, mForceAdoptable);
        final int size = mRecords.size();
        for (int i = 0; i < size; i++) {
            final VolumeRecord rec = mRecords.valueAt(i);
            writeVolumeRecord(out, rec);
        }
        out.endTag(null, TAG_VOLUMES);
        out.endDocument();
        mSettingsFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mSettingsFile.failWrite(fos);
        }
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

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