1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.server.usage; 18 19import static com.google.common.truth.Truth.assertThat; 20 21import android.provider.Settings; 22import android.test.AndroidTestCase; 23import android.test.mock.MockContentResolver; 24 25import com.android.internal.util.test.FakeSettingsProvider; 26 27import org.junit.Before; 28import org.junit.Test; 29 30public class StorageStatsServiceTest extends AndroidTestCase { 31 private MockContentResolver mContentResolver; 32 33 @Before 34 public void setUp() throws Exception { 35 super.setUp(); 36 mContentResolver = new MockContentResolver(); 37 mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider()); 38 } 39 40 @Test 41 public void testDontRunWhenDisabledFromSettingsGlobal() throws Exception { 42 Settings.Global.putInt(mContentResolver, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, 0); 43 44 assertThat(StorageStatsService.isCacheQuotaCalculationsEnabled(mContentResolver)).isFalse(); 45 } 46 47 @Test 48 public void testCalculationTaskIsEnabledByDefault() throws Exception { 49 // Put null to act as though there is no value here. 50 Settings.Global.putString( 51 mContentResolver, Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, null); 52 53 assertThat(StorageStatsService.isCacheQuotaCalculationsEnabled(mContentResolver)).isTrue(); 54 } 55} 56