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 17 package com.android.settings.testutils; 18 19 import android.content.Intent; 20 import android.os.BatteryManager; 21 22 public class BatteryTestUtils { 23 getChargingIntent()24 public static Intent getChargingIntent() { 25 return getCustomBatteryIntent( 26 BatteryManager.BATTERY_PLUGGED_AC, 27 50 /* level */, 28 100 /* scale */, 29 BatteryManager.BATTERY_STATUS_CHARGING); 30 } 31 getDischargingIntent()32 public static Intent getDischargingIntent() { 33 return getCustomBatteryIntent( 34 0 /* plugged */, 35 10 /* level */, 36 100 /* scale */, 37 BatteryManager.BATTERY_STATUS_DISCHARGING); 38 } 39 getCustomBatteryIntent(int plugged, int level, int scale, int status)40 private static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) { 41 Intent intent = new Intent(); 42 intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged); 43 intent.putExtra(BatteryManager.EXTRA_LEVEL, level); 44 intent.putExtra(BatteryManager.EXTRA_SCALE, scale); 45 intent.putExtra(BatteryManager.EXTRA_STATUS, status); 46 47 return intent; 48 } 49 } 50