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);
}
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();
}
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);
}
}
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);
}
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;
}
Aggregations