Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1980c9a8 authored by Felka Chang's avatar Felka Chang
Browse files

Disable storage crates functionalities

The Storage Crates functionalities is disabled by default. In order to
make the android system more secure, the crate function should throw
exception to tell the caller that the crate function is disabled until
it addes more tests such as benchmark and memory regression tests.

Bug: 148179319
Fixes: 149366046
Test: atest \
         CtsOsTestCases:android.os.storage.cts.StorageCrateTest \
         CtsOsTestCases:android.os.storage.cts.StorageStatsManagerTest \
         CtsOsTestCases:android.os.storage.cts.CrateInfoTest
Test: adb root ;\
      adb shell setprop fw.storage_crates 1 ;\
      atest \
        CtsOsTestCases:android.os.storage.cts.StorageCrateTest \
        CtsOsTestCases:android.os.storage.cts.StorageStatsManagerTest \
        CtsOsTestCases:android.os.storage.cts.CrateInfoTest
Change-Id: I7bfbdcbde5a90ecad7ef690a9d9a62e5ed0ad5eb
parent 8869427b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import java.util.function.Consumer;
public class StorageStatsService extends IStorageStatsManager.Stub {
    private static final String TAG = "StorageStatsService";

    private static final String PROP_STORAGE_CRATES = "fw.storage_crates";
    private static final String PROP_DISABLE_QUOTA = "fw.disable_quota";
    private static final String PROP_VERIFY_STORAGE = "fw.verify_storage";

@@ -595,6 +596,13 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
                Uri.parse("content://com.android.externalstorage.documents/"), null, false);
    }

    private static void checkCratesEnable() {
        final boolean enable = SystemProperties.getBoolean(PROP_STORAGE_CRATES, false);
        if (!enable) {
            throw new IllegalStateException("Storage Crate feature is disabled.");
        }
    }

    /**
     * To enforce the calling or self to have the {@link android.Manifest.permission#MANAGE_CRATES}
     * permission.
@@ -650,6 +658,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
    @Override
    public ParceledListSlice<CrateInfo> queryCratesForPackage(String volumeUuid,
            @NonNull String packageName, @UserIdInt int userId, @NonNull String callingPackage) {
        checkCratesEnable();
        if (userId != UserHandle.getCallingUserId()) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.INTERACT_ACROSS_USERS, TAG);
@@ -677,6 +686,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
    @Override
    public ParceledListSlice<CrateInfo> queryCratesForUid(String volumeUuid, int uid,
            @NonNull String callingPackage) {
        checkCratesEnable();
        final int userId = UserHandle.getUserId(uid);
        if (userId != UserHandle.getCallingUserId()) {
            mContext.enforceCallingOrSelfPermission(
@@ -718,6 +728,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
    @Override
    public ParceledListSlice<CrateInfo> queryCratesForUser(String volumeUuid, int userId,
            @NonNull String callingPackage) {
        checkCratesEnable();
        if (userId != UserHandle.getCallingUserId()) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.INTERACT_ACROSS_USERS, TAG);