Loading core/java/android/provider/Settings.java +7 −0 Original line number Diff line number Diff line Loading @@ -10207,6 +10207,13 @@ public final class Settings { * @hide */ public static final String ENABLE_DISKSTATS_LOGGING = "enable_diskstats_logging"; /** * Whether the cache quota calculation task is enabled/disabled. * @hide */ public static final String ENABLE_CACHE_QUOTA_CALCULATION = "enable_cache_quota_calculation"; } /** Loading core/tests/coretests/src/android/provider/SettingsBackupTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,7 @@ public class SettingsBackupTest { Settings.Global.DROPBOX_TAG_PREFIX, Settings.Global.EMERGENCY_AFFORDANCE_NEEDED, Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, Settings.Global.ENABLE_CELLULAR_ON_BOOT, Settings.Global.ENABLE_DISKSTATS_LOGGING, Settings.Global.ENABLE_EPHEMERAL_FEATURE, Loading services/tests/servicestests/src/com/android/server/usage/StorageStatsServiceTest.java 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.usage; import static com.google.common.truth.Truth.assertThat; import android.provider.Settings; import android.test.AndroidTestCase; import android.test.mock.MockContentResolver; import com.android.internal.util.test.FakeSettingsProvider; import org.junit.Before; import org.junit.Test; public class StorageStatsServiceTest extends AndroidTestCase { private MockContentResolver mContentResolver; @Before public void setUp() throws Exception { super.setUp(); mContentResolver = new MockContentResolver(); mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider()); } @Test public void testDontRunWhenDisabledFromSettingsGlobal() throws Exception { Settings.Global.putInt(mContentResolver, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, 0); assertThat(StorageStatsService.isCacheQuotaCalculationsEnabled(mContentResolver)).isFalse(); } @Test public void testCalculationTaskIsEnabledByDefault() throws Exception { // Put null to act as though there is no value here. Settings.Global.putString( mContentResolver, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, null); assertThat(StorageStatsService.isCacheQuotaCalculationsEnabled(mContentResolver)).isTrue(); } } services/usage/java/com/android/server/usage/StorageStatsService.java +14 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.app.usage.ExternalStorageStats; import android.app.usage.IStorageStatsManager; import android.app.usage.StorageStats; import android.app.usage.UsageStatsManagerInternal; import android.content.ContentResolver; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; Loading @@ -39,9 +40,11 @@ import android.os.UserManager; import android.os.storage.StorageEventListener; import android.os.storage.StorageManager; import android.os.storage.VolumeInfo; import android.provider.Settings; import android.text.format.DateUtils; import android.util.Slog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Preconditions; import com.android.server.IoThread; Loading Loading @@ -328,6 +331,11 @@ public class StorageStatsService extends IStorageStatsManager.Stub { if (DEBUG) { Slog.v(TAG, ">>> handling " + msg.what); } if (!isCacheQuotaCalculationsEnabled(mContext.getContentResolver())) { return; } switch (msg.what) { case MSG_CHECK_STORAGE_DELTA: { long bytesDelta = Math.abs(mPreviousBytes - mStats.getFreeBytes()); Loading Loading @@ -359,4 +367,10 @@ public class StorageStatsService extends IStorageStatsManager.Stub { strategy.recalculateQuotas(); } } @VisibleForTesting static boolean isCacheQuotaCalculationsEnabled(ContentResolver resolver) { return Settings.Global.getInt( resolver, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, 1) != 0; } } Loading
core/java/android/provider/Settings.java +7 −0 Original line number Diff line number Diff line Loading @@ -10207,6 +10207,13 @@ public final class Settings { * @hide */ public static final String ENABLE_DISKSTATS_LOGGING = "enable_diskstats_logging"; /** * Whether the cache quota calculation task is enabled/disabled. * @hide */ public static final String ENABLE_CACHE_QUOTA_CALCULATION = "enable_cache_quota_calculation"; } /** Loading
core/tests/coretests/src/android/provider/SettingsBackupTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,7 @@ public class SettingsBackupTest { Settings.Global.DROPBOX_TAG_PREFIX, Settings.Global.EMERGENCY_AFFORDANCE_NEEDED, Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, Settings.Global.ENABLE_CELLULAR_ON_BOOT, Settings.Global.ENABLE_DISKSTATS_LOGGING, Settings.Global.ENABLE_EPHEMERAL_FEATURE, Loading
services/tests/servicestests/src/com/android/server/usage/StorageStatsServiceTest.java 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.usage; import static com.google.common.truth.Truth.assertThat; import android.provider.Settings; import android.test.AndroidTestCase; import android.test.mock.MockContentResolver; import com.android.internal.util.test.FakeSettingsProvider; import org.junit.Before; import org.junit.Test; public class StorageStatsServiceTest extends AndroidTestCase { private MockContentResolver mContentResolver; @Before public void setUp() throws Exception { super.setUp(); mContentResolver = new MockContentResolver(); mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider()); } @Test public void testDontRunWhenDisabledFromSettingsGlobal() throws Exception { Settings.Global.putInt(mContentResolver, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, 0); assertThat(StorageStatsService.isCacheQuotaCalculationsEnabled(mContentResolver)).isFalse(); } @Test public void testCalculationTaskIsEnabledByDefault() throws Exception { // Put null to act as though there is no value here. Settings.Global.putString( mContentResolver, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, null); assertThat(StorageStatsService.isCacheQuotaCalculationsEnabled(mContentResolver)).isTrue(); } }
services/usage/java/com/android/server/usage/StorageStatsService.java +14 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.app.usage.ExternalStorageStats; import android.app.usage.IStorageStatsManager; import android.app.usage.StorageStats; import android.app.usage.UsageStatsManagerInternal; import android.content.ContentResolver; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; Loading @@ -39,9 +40,11 @@ import android.os.UserManager; import android.os.storage.StorageEventListener; import android.os.storage.StorageManager; import android.os.storage.VolumeInfo; import android.provider.Settings; import android.text.format.DateUtils; import android.util.Slog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Preconditions; import com.android.server.IoThread; Loading Loading @@ -328,6 +331,11 @@ public class StorageStatsService extends IStorageStatsManager.Stub { if (DEBUG) { Slog.v(TAG, ">>> handling " + msg.what); } if (!isCacheQuotaCalculationsEnabled(mContext.getContentResolver())) { return; } switch (msg.what) { case MSG_CHECK_STORAGE_DELTA: { long bytesDelta = Math.abs(mPreviousBytes - mStats.getFreeBytes()); Loading Loading @@ -359,4 +367,10 @@ public class StorageStatsService extends IStorageStatsManager.Stub { strategy.recalculateQuotas(); } } @VisibleForTesting static boolean isCacheQuotaCalculationsEnabled(ContentResolver resolver) { return Settings.Global.getInt( resolver, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, 1) != 0; } }