Search in sources :

Example 61 with StorageManager

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

the class AppFuseTest method testOpenFile_illegalMode.

public void testOpenFile_illegalMode() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int INODE = 10;
    final AppFuse appFuse = new AppFuse("test", new TestCallback());
    appFuse.mount(storageManager);
    try {
        appFuse.openFile(INODE, ParcelFileDescriptor.MODE_READ_WRITE);
        fail();
    } catch (IllegalArgumentException exp) {
    }
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager)

Example 62 with StorageManager

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

the class AppFuseTest method testWriteFile_flushError.

public void testWriteFile_flushError() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int INODE = 10;
    final AppFuse appFuse = new AppFuse("test", new TestCallback() {

        @Override
        public long getFileSize(int inode) throws FileNotFoundException {
            if (inode != INODE) {
                throw new FileNotFoundException();
            }
            return 5;
        }

        @Override
        public int writeObjectBytes(long fileHandle, int inode, long offset, int size, byte[] bytes) {
            return size;
        }

        @Override
        public void flushFileHandle(long fileHandle) throws IOException {
            throw new IOException();
        }
    });
    appFuse.mount(storageManager);
    final ParcelFileDescriptor fd = appFuse.openFile(INODE, ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE);
    try (final ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd)) {
        stream.write('a');
        try {
            IoUtils.close(fd.getFileDescriptor());
            fail();
        } catch (IOException e) {
        }
    }
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Example 63 with StorageManager

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

the class AppFuseTest method testWriteFile_writeError.

public void testWriteFile_writeError() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int INODE = 10;
    final AppFuse appFuse = new AppFuse("test", new TestCallback() {

        @Override
        public long getFileSize(int inode) throws FileNotFoundException {
            if (inode != INODE) {
                throw new FileNotFoundException();
            }
            return 5;
        }
    });
    appFuse.mount(storageManager);
    final ParcelFileDescriptor fd = appFuse.openFile(INODE, ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE);
    try (final ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd)) {
        stream.write('a');
        fail();
    } catch (IOException e) {
    }
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Example 64 with StorageManager

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

the class MountService method onVolumeCreatedLocked.

private void onVolumeCreatedLocked(VolumeInfo vol) {
    // power off alarm need the access to external storage for audio files.
    // So in power off alarm mode, primary storage need to be mounted.
    boolean isAlarmBoot = SystemProperties.getBoolean("ro.alarm_boot", false);
    if (mPms.isOnlyCoreApps() && !isAlarmBoot) {
        Slog.d(TAG, "System booted in core-only mode; ignoring volume " + vol.getId());
        return;
    }
    if (vol.type == VolumeInfo.TYPE_EMULATED) {
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        final VolumeInfo privateVol = storage.findPrivateForEmulated(vol);
        if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, mPrimaryStorageUuid) && VolumeInfo.ID_PRIVATE_INTERNAL.equals(privateVol.id)) {
            Slog.v(TAG, "Found primary storage at " + vol);
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
            mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
        } else if (Objects.equals(privateVol.fsUuid, mPrimaryStorageUuid)) {
            Slog.v(TAG, "Found primary storage at " + vol);
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
            mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
        }
    } else if (vol.type == VolumeInfo.TYPE_PUBLIC) {
        // TODO: only look at first public partition
        if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, mPrimaryStorageUuid) && vol.disk.isDefaultPrimary()) {
            Slog.v(TAG, "Found primary storage at " + vol);
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
        }
        // make sdcard visible.
        if (vol.disk.isAdoptable() || vol.disk.isSd()) {
            vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
        }
        vol.mountUserId = mCurrentUserId;
        mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
    } else if (vol.type == VolumeInfo.TYPE_PRIVATE) {
        mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
    } else {
        Slog.d(TAG, "Skipping automatic mounting of " + vol);
    }
}
Also used : StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo)

Example 65 with StorageManager

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

the class DeviceStorageMonitorService method onStart.

/**
    * Initializes the disk space threshold value and posts an empty message to
    * kickstart the process.
    */
@Override
public void onStart() {
    // cache storage thresholds
    final StorageManager sm = StorageManager.from(getContext());
    mMemLowThreshold = sm.getStorageLowBytes(DATA_PATH);
    mMemFullThreshold = sm.getStorageFullBytes(DATA_PATH);
    mMemCacheStartTrimThreshold = ((mMemLowThreshold * 3) + mMemFullThreshold) / 4;
    mMemCacheTrimToThreshold = mMemLowThreshold + ((mMemLowThreshold - mMemCacheStartTrimThreshold) * 2);
    mFreeMemAfterLastCacheClear = mTotalMemory;
    checkMemory(true);
    mCacheFileDeletedObserver = new CacheFileDeletedObserver();
    mCacheFileDeletedObserver.startWatching();
    publishBinderService(SERVICE, mRemoteService);
    publishLocalService(DeviceStorageMonitorInternal.class, mLocalService);
}
Also used : StorageManager(android.os.storage.StorageManager)

Aggregations

StorageManager (android.os.storage.StorageManager)161 File (java.io.File)43 IOException (java.io.IOException)42 VolumeInfo (android.os.storage.VolumeInfo)38 FileNotFoundException (java.io.FileNotFoundException)32 ParcelFileDescriptor (android.os.ParcelFileDescriptor)25 LargeTest (android.test.suitebuilder.annotation.LargeTest)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)17 RemoteException (android.os.RemoteException)14 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 StorageVolume (android.os.storage.StorageVolume)13 PackageParserException (android.content.pm.PackageParser.PackageParserException)12 NotFoundException (android.content.res.Resources.NotFoundException)12 StorageListener (android.os.storage.StorageListener)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ErrnoException (android.system.ErrnoException)12 NonNull (android.annotation.NonNull)10 ZipFile (java.util.zip.ZipFile)10