Search in sources :

Example 51 with VolumeRecord

use of android.os.storage.VolumeRecord 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 52 with VolumeRecord

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

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

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

the class MountService method setVolumeUserFlags.

@Override
public void setVolumeUserFlags(String fsUuid, int flags, int mask) {
    enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();
    Preconditions.checkNotNull(fsUuid);
    synchronized (mLock) {
        final VolumeRecord rec = mRecords.get(fsUuid);
        if (rec == null)
            return;
        rec.userFlags = (rec.userFlags & ~mask) | (flags & mask);
        mCallbacks.notifyVolumeRecordChanged(rec);
        writeSettingsLocked();
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord)

Example 54 with VolumeRecord

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

the class MountService method readVolumeRecord.

public static VolumeRecord readVolumeRecord(XmlPullParser in) throws IOException {
    final int type = readIntAttribute(in, ATTR_TYPE);
    final String fsUuid = readStringAttribute(in, ATTR_FS_UUID);
    final VolumeRecord meta = new VolumeRecord(type, fsUuid);
    meta.partGuid = readStringAttribute(in, ATTR_PART_GUID);
    meta.nickname = readStringAttribute(in, ATTR_NICKNAME);
    meta.userFlags = readIntAttribute(in, ATTR_USER_FLAGS);
    meta.createdMillis = readLongAttribute(in, ATTR_CREATED_MILLIS);
    meta.lastTrimMillis = readLongAttribute(in, ATTR_LAST_TRIM_MILLIS);
    meta.lastBenchMillis = readLongAttribute(in, ATTR_LAST_BENCH_MILLIS);
    return meta;
}
Also used : VolumeRecord(android.os.storage.VolumeRecord)

Example 55 with VolumeRecord

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

the class MountService method shouldBenchmark.

private boolean shouldBenchmark() {
    final long benchInterval = Settings.Global.getLong(mContext.getContentResolver(), Settings.Global.STORAGE_BENCHMARK_INTERVAL, -1);
    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