1 /* 2 * Copyright (C) 2016 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 17 package com.android.server.cts; 18 19 import android.service.battery.BatteryServiceDumpProto; 20 import com.android.tradefed.device.DeviceNotAvailableException; 21 22 /** Test to check that the battery manager properly outputs its dump state. */ 23 public class BatteryIncidentTest extends ProtoDumpTestCase { 24 private final String LEANBACK_FEATURE = "android.software.leanback"; 25 testBatteryServiceDump()26 public void testBatteryServiceDump() throws Exception { 27 final BatteryServiceDumpProto dump = 28 getDump(BatteryServiceDumpProto.parser(), "dumpsys battery --proto"); 29 30 if (!dump.getIsPresent()) { 31 /* If the battery isn't present, no need to run this test. */ 32 return; 33 } 34 35 if (isLeanback()) { 36 /* Android TV reports that it has a battery, but it doesn't really. */ 37 return; 38 } 39 40 assertTrue( 41 dump.getPlugged() 42 != BatteryServiceDumpProto.BatteryPlugged.BATTERY_PLUGGED_WIRELESS); 43 assertTrue(dump.getMaxChargingCurrent() > 0); 44 assertTrue(dump.getMaxChargingVoltage() > 0); 45 assertTrue(dump.getChargeCounter() > 0); 46 assertTrue( 47 dump.getStatus() != BatteryServiceDumpProto.BatteryStatus.BATTERY_STATUS_INVALID); 48 assertTrue( 49 dump.getHealth() != BatteryServiceDumpProto.BatteryHealth.BATTERY_HEALTH_INVALID); 50 int scale = dump.getScale(); 51 assertTrue(scale > 0); 52 int level = dump.getLevel(); 53 assertTrue(level >= 0 && level <= scale); 54 assertTrue(dump.getVoltage() > 0); 55 assertTrue(dump.getTemperature() > 0); 56 assertNotNull(dump.getTechnology()); 57 } 58 isLeanback()59 private boolean isLeanback() throws DeviceNotAvailableException { 60 final String commandOutput = getDevice().executeShellCommand("pm list features"); 61 return commandOutput.contains(LEANBACK_FEATURE); 62 } 63 } 64