}
public void runSetForceAdoptable() throws RemoteException {
- final boolean forceAdoptable = Boolean.parseBoolean(nextArg());
- mSm.setDebugFlags(forceAdoptable ? StorageManager.DEBUG_FORCE_ADOPTABLE : 0,
- StorageManager.DEBUG_FORCE_ADOPTABLE);
+ final int mask = StorageManager.DEBUG_ADOPTABLE_FORCE_ON
+ | StorageManager.DEBUG_ADOPTABLE_FORCE_OFF;
+ switch (nextArg()) {
+ case "on":
+ case "true":
+ mSm.setDebugFlags(StorageManager.DEBUG_ADOPTABLE_FORCE_ON, mask);
+ break;
+ case "off":
+ mSm.setDebugFlags(StorageManager.DEBUG_ADOPTABLE_FORCE_OFF, mask);
+ break;
+ case "default":
+ case "false":
+ mSm.setDebugFlags(0, mask);
+ break;
+ }
}
public void runSetSdcardfs() throws RemoteException {
System.err.println(" sm list-volumes [public|private|emulated|all]");
System.err.println(" sm has-adoptable");
System.err.println(" sm get-primary-storage-uuid");
- System.err.println(" sm set-force-adoptable [true|false]");
+ System.err.println(" sm set-force-adoptable [on|off|default]");
System.err.println(" sm set-virtual-disk [true|false]");
System.err.println("");
System.err.println(" sm partition DISK [public|private|mixed] [ratio]");
/** {@hide} */
public static final String PROP_HAS_RESERVED = "vold.has_reserved";
/** {@hide} */
- public static final String PROP_FORCE_ADOPTABLE = "persist.fw.force_adoptable";
+ public static final String PROP_ADOPTABLE = "persist.sys.adoptable";
/** {@hide} */
public static final String PROP_EMULATE_FBE = "persist.sys.emulate_fbe";
/** {@hide} */
public static final String EXTRA_REQUESTED_BYTES = "android.os.storage.extra.REQUESTED_BYTES";
/** {@hide} */
- public static final int DEBUG_FORCE_ADOPTABLE = 1 << 0;
+ public static final int DEBUG_ADOPTABLE_FORCE_ON = 1 << 0;
/** {@hide} */
- public static final int DEBUG_EMULATE_FBE = 1 << 1;
+ public static final int DEBUG_ADOPTABLE_FORCE_OFF = 1 << 1;
/** {@hide} */
- public static final int DEBUG_SDCARDFS_FORCE_ON = 1 << 2;
+ public static final int DEBUG_EMULATE_FBE = 1 << 2;
/** {@hide} */
- public static final int DEBUG_SDCARDFS_FORCE_OFF = 1 << 3;
+ public static final int DEBUG_SDCARDFS_FORCE_ON = 1 << 3;
/** {@hide} */
- public static final int DEBUG_VIRTUAL_DISK = 1 << 4;
+ public static final int DEBUG_SDCARDFS_FORCE_OFF = 1 << 4;
+ /** {@hide} */
+ public static final int DEBUG_VIRTUAL_DISK = 1 << 5;
// NOTE: keep in sync with installd
/** {@hide} */
import static android.os.storage.OnObbStateChangeListener.MOUNTED;
import static android.os.storage.OnObbStateChangeListener.UNMOUNTED;
-import static com.android.internal.util.XmlUtils.readBooleanAttribute;
import static com.android.internal.util.XmlUtils.readIntAttribute;
import static com.android.internal.util.XmlUtils.readLongAttribute;
import static com.android.internal.util.XmlUtils.readStringAttribute;
-import static com.android.internal.util.XmlUtils.writeBooleanAttribute;
import static com.android.internal.util.XmlUtils.writeIntAttribute;
import static com.android.internal.util.XmlUtils.writeLongAttribute;
import static com.android.internal.util.XmlUtils.writeStringAttribute;
private static final String TAG_VOLUMES = "volumes";
private static final String ATTR_VERSION = "version";
private static final String ATTR_PRIMARY_STORAGE_UUID = "primaryStorageUuid";
- private static final String ATTR_FORCE_ADOPTABLE = "forceAdoptable";
private static final String TAG_VOLUME = "volume";
private static final String ATTR_TYPE = "type";
private static final String ATTR_FS_UUID = "fsUuid";
private ArrayMap<String, VolumeRecord> mRecords = new ArrayMap<>();
@GuardedBy("mLock")
private String mPrimaryStorageUuid;
- @GuardedBy("mLock")
- private boolean mForceAdoptable;
/** Map from disk ID to latches */
@GuardedBy("mLock")
@Override
public void onDiskCreated(String diskId, int flags) {
synchronized (mLock) {
- if (SystemProperties.getBoolean(StorageManager.PROP_FORCE_ADOPTABLE, false)
- || mForceAdoptable) {
- flags |= DiskInfo.FLAG_ADOPTABLE;
+ final String value = SystemProperties.get(StorageManager.PROP_ADOPTABLE);
+ switch (value) {
+ case "force_on":
+ flags |= DiskInfo.FLAG_ADOPTABLE;
+ break;
+ case "force_off":
+ flags &= ~DiskInfo.FLAG_ADOPTABLE;
+ break;
}
mDisks.put(diskId, new DiskInfo(diskId, flags));
}
private void readSettingsLocked() {
mRecords.clear();
mPrimaryStorageUuid = getDefaultPrimaryStorageUuid();
- mForceAdoptable = false;
FileInputStream fis = null;
try {
mPrimaryStorageUuid = readStringAttribute(in,
ATTR_PRIMARY_STORAGE_UUID);
}
- mForceAdoptable = readBooleanAttribute(in, ATTR_FORCE_ADOPTABLE, false);
} else if (TAG_VOLUME.equals(tag)) {
final VolumeRecord rec = readVolumeRecord(in);
out.startTag(null, TAG_VOLUMES);
writeIntAttribute(out, ATTR_VERSION, VERSION_FIX_PRIMARY);
writeStringAttribute(out, ATTR_PRIMARY_STORAGE_UUID, mPrimaryStorageUuid);
- writeBooleanAttribute(out, ATTR_FORCE_ADOPTABLE, mForceAdoptable);
final int size = mRecords.size();
for (int i = 0; i < size; i++) {
final VolumeRecord rec = mRecords.valueAt(i);
}
}
- if ((mask & StorageManager.DEBUG_FORCE_ADOPTABLE) != 0) {
- synchronized (mLock) {
- mForceAdoptable = (flags & StorageManager.DEBUG_FORCE_ADOPTABLE) != 0;
+ if ((mask & (StorageManager.DEBUG_ADOPTABLE_FORCE_ON
+ | StorageManager.DEBUG_ADOPTABLE_FORCE_OFF)) != 0) {
+ final String value;
+ if ((flags & StorageManager.DEBUG_ADOPTABLE_FORCE_ON) != 0) {
+ value = "force_on";
+ } else if ((flags & StorageManager.DEBUG_ADOPTABLE_FORCE_OFF) != 0) {
+ value = "force_off";
+ } else {
+ value = "";
+ }
- writeSettingsLocked();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ SystemProperties.set(StorageManager.PROP_ADOPTABLE, value);
+
+ // Reset storage to kick new setting into place
mHandler.obtainMessage(H_RESET).sendToTarget();
+ } finally {
+ Binder.restoreCallingIdentity(token);
}
}
pw.print(DataUnit.MEBIBYTES.toBytes(pair.second));
pw.println(" MiB)");
}
- pw.println("Force adoptable: " + mForceAdoptable);
- pw.println();
pw.println("Local unlocked users: " + Arrays.toString(mLocalUnlockedUsers));
pw.println("System unlocked users: " + Arrays.toString(mSystemUnlockedUsers));
}