Search in sources :

Example 66 with StorageManager

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

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 67 with StorageManager

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

the class AppFuseTest method testWriteFile.

public void testWriteFile() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int INODE = 10;
    final byte[] resultBytes = new byte[5];
    final AppFuse appFuse = new AppFuse("test", new TestCallback() {

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

        @Override
        public int writeObjectBytes(long fileHandle, int inode, long offset, int size, byte[] bytes) {
            for (int i = 0; i < size; i++) {
                resultBytes[(int) (offset + i)] = bytes[i];
            }
            return size;
        }
    });
    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');
        stream.write('b');
        stream.write('c');
        stream.write('d');
        stream.write('e');
    }
    final byte[] BYTES = new byte[] { 'a', 'b', 'c', 'd', 'e' };
    assertTrue(Arrays.equals(BYTES, resultBytes));
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException) ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 68 with StorageManager

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

the class DevicePolicyManagerService method wipeDataLocked.

private void wipeDataLocked(boolean wipeExtRequested, String reason) {
    if (wipeExtRequested) {
        StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
        sm.wipeAdoptableDisks();
    }
    try {
        RecoverySystem.rebootWipeUserData(mContext, reason);
    } catch (IOException | SecurityException e) {
        Slog.w(LOG_TAG, "Failed requesting data wipe", e);
    }
}
Also used : StorageManager(android.os.storage.StorageManager) IOException(java.io.IOException)

Example 69 with StorageManager

use of android.os.storage.StorageManager in project cw-omnibus by commonsguy.

the class SettingsFragment method populateVolumes.

@TargetApi(Build.VERSION_CODES.N)
private void populateVolumes() {
    StorageManager storage = (StorageManager) getActivity().getSystemService(Context.STORAGE_SERVICE);
    List<StorageVolume> volumes = storage.getStorageVolumes();
    Collections.sort(volumes, new Comparator<StorageVolume>() {

        @Override
        public int compare(StorageVolume lhs, StorageVolume rhs) {
            return (lhs.getDescription(getActivity()).compareTo(rhs.getDescription(getActivity())));
        }
    });
    String[] displayNames = new String[volumes.size()];
    String[] uuids = new String[volumes.size()];
    for (int i = 0; i < volumes.size(); i++) {
        displayNames[i] = volumes.get(i).getDescription(getActivity());
        uuids[i] = volumes.get(i).getUuid();
        if (uuids[i] == null) {
            uuids[i] = STORAGE_FAKE_UUID;
        }
    }
    prefVolumes.setEntries(displayNames);
    prefVolumes.setEntryValues(uuids);
}
Also used : StorageVolume(android.os.storage.StorageVolume) StorageManager(android.os.storage.StorageManager) TargetApi(android.annotation.TargetApi)

Example 70 with StorageManager

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

the class ApplicationPackageManager method getPackageCandidateVolumes.

@Override
@NonNull
public List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    final VolumeInfo currentVol = getPackageCurrentVolume(app);
    final List<VolumeInfo> vols = storage.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    for (VolumeInfo vol : vols) {
        if (Objects.equals(vol, currentVol) || isPackageCandidateVolume(mContext, app, vol)) {
            candidates.add(vol);
        }
    }
    return candidates;
}
Also used : StorageManager(android.os.storage.StorageManager) ArrayList(java.util.ArrayList) VolumeInfo(android.os.storage.VolumeInfo) NonNull(android.annotation.NonNull)

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