Revamp the battery usage details page.
This cl adds AdvancedPowerUsageDetail to show the usage details page. The AdvancedPowerUsageDetail contains all the needed ui components: 1. App Header 2. Two buttons 3. Usage breakdown preference category 4. Power management preference category This cl also adds preference controller for two buttons but the detail implementation will be added in the following cl. Following cl will also remove previous detail page. Bug: 35810915 Test: RunSettingsRoboTests Change-Id: I17f95d1288762094671c0f148fa73367e51f175e
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.settings.fuelgauge;
|
||||
|
||||
import android.os.BatteryStats;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static android.os.BatteryStats.Uid.PROCESS_STATE_BACKGROUND;
|
||||
import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND;
|
||||
import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE;
|
||||
import static android.os.BatteryStats.Uid.PROCESS_STATE_TOP;
|
||||
import static android.os.BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Matchers.eq;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BatteryUtilsTest {
|
||||
// unit that used to converted ms to us
|
||||
private static final long UNIT = 1000;
|
||||
private static final long TIME_STATE_TOP = 1500 * UNIT;
|
||||
private static final long TIME_STATE_FOREGROUND_SERVICE = 2000 * UNIT;
|
||||
private static final long TIME_STATE_TOP_SLEEPING = 2500 * UNIT;
|
||||
private static final long TIME_STATE_FOREGROUND = 3000 * UNIT;
|
||||
private static final long TIME_STATE_BACKGROUND = 6000 * UNIT;
|
||||
|
||||
private static final long TIME_EXPECTED_FOREGROUND = 9000;
|
||||
private static final long TIME_EXPECTED_BACKGROUND = 6000;
|
||||
private static final long TIME_EXPECTED_ALL = 15000;
|
||||
|
||||
@Mock
|
||||
BatteryStats.Uid mUid;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
doReturn(TIME_STATE_TOP).when(mUid).getProcessStateTime(eq(PROCESS_STATE_TOP), anyLong(),
|
||||
anyInt());
|
||||
doReturn(TIME_STATE_FOREGROUND_SERVICE).when(mUid).getProcessStateTime(
|
||||
eq(PROCESS_STATE_FOREGROUND_SERVICE), anyLong(), anyInt());
|
||||
doReturn(TIME_STATE_TOP_SLEEPING).when(mUid).getProcessStateTime(
|
||||
eq(PROCESS_STATE_TOP_SLEEPING), anyLong(), anyInt());
|
||||
doReturn(TIME_STATE_FOREGROUND).when(mUid).getProcessStateTime(eq(PROCESS_STATE_FOREGROUND),
|
||||
anyLong(), anyInt());
|
||||
doReturn(TIME_STATE_BACKGROUND).when(mUid).getProcessStateTime(eq(PROCESS_STATE_BACKGROUND),
|
||||
anyLong(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessTimeMs_typeForeground_timeCorrect() {
|
||||
final long time = BatteryUtils.getProcessTimeMs(BatteryUtils.StatusType.FOREGROUND, mUid,
|
||||
BatteryStats.STATS_SINCE_CHARGED);
|
||||
|
||||
assertThat(time).isEqualTo(TIME_EXPECTED_FOREGROUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessTimeMs_typeBackground_timeCorrect() {
|
||||
final long time = BatteryUtils.getProcessTimeMs(BatteryUtils.StatusType.BACKGROUND, mUid,
|
||||
BatteryStats.STATS_SINCE_CHARGED);
|
||||
|
||||
assertThat(time).isEqualTo(TIME_EXPECTED_BACKGROUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessTimeMs_typeAll_timeCorrect() {
|
||||
final long time = BatteryUtils.getProcessTimeMs(BatteryUtils.StatusType.ALL, mUid,
|
||||
BatteryStats.STATS_SINCE_CHARGED);
|
||||
|
||||
assertThat(time).isEqualTo(TIME_EXPECTED_ALL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessTimeMs_uidNull_returnZero() {
|
||||
final long time = BatteryUtils.getProcessTimeMs(BatteryUtils.StatusType.ALL, null,
|
||||
BatteryStats.STATS_SINCE_CHARGED);
|
||||
|
||||
assertThat(time).isEqualTo(0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user