Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 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.internal.os; |
| 18 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 19 | import java.util.ArrayList; |
| 20 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 21 | /** |
| 22 | * Mocks a BatteryStatsImpl object. |
| 23 | */ |
| 24 | public class MockBatteryStatsImpl extends BatteryStatsImpl { |
| 25 | public BatteryStatsImpl.Clocks clocks; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 26 | public boolean mForceOnBattery; |
| 27 | |
| 28 | MockBatteryStatsImpl(Clocks clocks) { |
| 29 | super(clocks); |
| 30 | this.clocks = mClocks; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 31 | mScreenOnTimer = new BatteryStatsImpl.StopwatchTimer(clocks, null, -1, null, |
| 32 | mOnBatteryTimeBase); |
| 33 | mScreenDozeTimer = new BatteryStatsImpl.StopwatchTimer(clocks, null, -1, null, |
| 34 | mOnBatteryTimeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 35 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 36 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 37 | |
| 38 | MockBatteryStatsImpl() { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 39 | this(new MockClocks()); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | public TimeBase getOnBatteryTimeBase() { |
| 43 | return mOnBatteryTimeBase; |
| 44 | } |
| 45 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 46 | public TimeBase getOnBatteryScreenOffTimeBase() { |
| 47 | return mOnBatteryScreenOffTimeBase; |
| 48 | } |
| 49 | |
| 50 | public int getScreenState() { |
| 51 | return mScreenState; |
| 52 | } |
| 53 | |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 54 | public boolean isOnBattery() { |
| 55 | return mForceOnBattery ? true : super.isOnBattery(); |
| 56 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 57 | |
| 58 | public TimeBase getOnBatteryBackgroundTimeBase(int uid) { |
| 59 | return getUidStatsLocked(uid).mOnBatteryBackgroundTimeBase; |
| 60 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 61 | |
| 62 | public TimeBase getOnBatteryScreenOffBackgroundTimeBase(int uid) { |
| 63 | return getUidStatsLocked(uid).mOnBatteryScreenOffBackgroundTimeBase; |
| 64 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 65 | |
| 66 | public MockBatteryStatsImpl setPowerProfile(PowerProfile powerProfile) { |
| 67 | mPowerProfile = powerProfile; |
| 68 | return this; |
| 69 | } |
| 70 | |
| 71 | public MockBatteryStatsImpl setKernelUidCpuFreqTimeReader(KernelUidCpuFreqTimeReader reader) { |
| 72 | mKernelUidCpuFreqTimeReader = reader; |
| 73 | return this; |
| 74 | } |
| 75 | |
| 76 | public MockBatteryStatsImpl setKernelUidCpuTimeReader(KernelUidCpuTimeReader reader) { |
| 77 | mKernelUidCpuTimeReader = reader; |
| 78 | return this; |
| 79 | } |
| 80 | |
| 81 | public MockBatteryStatsImpl setKernelCpuSpeedReaders(KernelCpuSpeedReader[] readers) { |
| 82 | mKernelCpuSpeedReaders = readers; |
| 83 | return this; |
| 84 | } |
| 85 | |
| 86 | public MockBatteryStatsImpl setUserInfoProvider(UserInfoProvider provider) { |
| 87 | mUserInfoProvider = provider; |
| 88 | return this; |
| 89 | } |
| 90 | |
| 91 | public MockBatteryStatsImpl setPartialTimers(ArrayList<StopwatchTimer> partialTimers) { |
| 92 | mPartialTimers = partialTimers; |
| 93 | return this; |
| 94 | } |
| 95 | |
| 96 | public MockBatteryStatsImpl setLastPartialTimers(ArrayList<StopwatchTimer> lastPartialTimers) { |
| 97 | mLastPartialTimers = lastPartialTimers; |
| 98 | return this; |
| 99 | } |
| 100 | |
| 101 | public MockBatteryStatsImpl setOnBatteryInternal(boolean onBatteryInternal) { |
| 102 | mOnBatteryInternal = onBatteryInternal; |
| 103 | return this; |
| 104 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 105 | } |
| 106 | |