Add sm set-isolated-storage [true|false]

Bug: 119038726
Test: manual
Change-Id: I29eeec7872584f1173e9b6d31434b36487515d9e
This commit is contained in:
Sudheer Shanka
2018-11-07 18:24:37 -08:00
parent 5431cccea9
commit be0febe40a
6 changed files with 57 additions and 5 deletions

View File

@@ -101,6 +101,8 @@ public final class Sm {
runFstrim();
} else if ("set-virtual-disk".equals(op)) {
runSetVirtualDisk();
} else if ("set-isolated-storage".equals(op)) {
runIsolatedStorage();
} else {
throw new IllegalArgumentException();
}
@@ -278,6 +280,20 @@ public final class Sm {
StorageManager.DEBUG_VIRTUAL_DISK);
}
public void runIsolatedStorage() throws RemoteException {
final boolean enableIsolatedStorage = Boolean.parseBoolean(nextArg());
// Toggling isolated-storage state will result in a device reboot. So to avoid this command
// from erroring out (DeadSystemException), call setDebugFlags() in a separate thread.
new Thread(() -> {
try {
mSm.setDebugFlags(enableIsolatedStorage ? StorageManager.DEBUG_ISOLATED_STORAGE : 0,
StorageManager.DEBUG_ISOLATED_STORAGE);
} catch (RemoteException e) {
Log.e(TAG, "Encountered an error!", e);
}
}).start();
}
public void runIdleMaint() throws RemoteException {
final boolean im_run = "run".equals(nextArg());
if (im_run) {
@@ -316,6 +332,8 @@ public final class Sm {
System.err.println("");
System.err.println(" sm set-emulate-fbe [true|false]");
System.err.println("");
System.err.println(" sm set-isolated-storage [true|false]");
System.err.println("");
return 1;
}
}

View File

@@ -467,6 +467,14 @@ public class Environment {
return new File(getDataPreloadsDirectory(), "file_cache");
}
/**
* Returns location of packages cache directory.
* {@hide}
*/
public static File getPackageCacheDirectory() {
return new File(getDataSystemDirectory(), "package_cache");
}
/**
* Return the primary shared/external storage directory. This directory may
* not currently be accessible if it has been mounted by the user on their

View File

@@ -1156,11 +1156,16 @@ public class FileUtils {
public static @Nullable File createDir(File baseDir, String name) {
final File dir = new File(baseDir, name);
return createDir(dir) ? dir : null;
}
/** @hide */
public static boolean createDir(File dir) {
if (dir.exists()) {
return dir.isDirectory() ? dir : null;
return dir.isDirectory();
}
return dir.mkdir() ? dir : null;
return dir.mkdir();
}
/**

View File

@@ -225,6 +225,8 @@ public class StorageManager {
public static final int DEBUG_SDCARDFS_FORCE_OFF = 1 << 4;
/** {@hide} */
public static final int DEBUG_VIRTUAL_DISK = 1 << 5;
/** {@hide} */
public static final int DEBUG_ISOLATED_STORAGE = 1 << 6;
/** {@hide} */
public static final int FLAG_STORAGE_DE = IInstalld.FLAG_STORAGE_DE;

View File

@@ -2097,6 +2097,26 @@ class StorageManagerService extends IStorageManager.Stub
Binder.restoreCallingIdentity(token);
}
}
if ((mask & StorageManager.DEBUG_ISOLATED_STORAGE) != 0) {
final boolean enabled = (flags & StorageManager.DEBUG_ISOLATED_STORAGE) != 0;
final long token = Binder.clearCallingIdentity();
try {
SystemProperties.set(StorageManager.PROP_ISOLATED_STORAGE,
Boolean.toString(enabled));
// Some of the storage related permissions get fiddled with during
// package scanning. So, delete the package cache to force PackageManagerService
// to do package scanning.
FileUtils.deleteContents(Environment.getPackageCacheDirectory());
// Perform hard reboot to kick policy into place
mContext.getSystemService(PowerManager.class).reboot(null);
} finally {
Binder.restoreCallingIdentity(token);
}
}
}
@Override

View File

@@ -3257,9 +3257,8 @@ public class PackageManagerService extends IPackageManager.Stub
}
// The base directory for the package parser cache lives under /data/system/.
final File cacheBaseDir = FileUtils.createDir(Environment.getDataSystemDirectory(),
"package_cache");
if (cacheBaseDir == null) {
final File cacheBaseDir = Environment.getPackageCacheDirectory();
if (!FileUtils.createDir(cacheBaseDir)) {
return null;
}