blob: 73ee3e55f46acae66905315e2baaa7b1491fcb1a [file] [log] [blame]
Joe Onoratoabded112016-02-08 16:49:39 -08001/*
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
17package com.android.internal.os;
18
Sudheer Shanka38383232017-07-25 09:55:03 -070019import java.util.ArrayList;
20
Joe Onoratoabded112016-02-08 16:49:39 -080021/**
22 * Mocks a BatteryStatsImpl object.
23 */
24public class MockBatteryStatsImpl extends BatteryStatsImpl {
25 public BatteryStatsImpl.Clocks clocks;
Amith Yamasaniab9ad192016-12-06 12:46:59 -080026 public boolean mForceOnBattery;
27
28 MockBatteryStatsImpl(Clocks clocks) {
29 super(clocks);
30 this.clocks = mClocks;
Bookatz867c0d72017-03-07 18:23:42 -080031 mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase);
Amith Yamasaniab9ad192016-12-06 12:46:59 -080032 }
Joe Onoratoabded112016-02-08 16:49:39 -080033
34 MockBatteryStatsImpl() {
Amith Yamasaniab9ad192016-12-06 12:46:59 -080035 this(new MockClocks());
Joe Onoratoabded112016-02-08 16:49:39 -080036 }
37
38 public TimeBase getOnBatteryTimeBase() {
39 return mOnBatteryTimeBase;
40 }
41
Amith Yamasaniab9ad192016-12-06 12:46:59 -080042 public boolean isOnBattery() {
43 return mForceOnBattery ? true : super.isOnBattery();
44 }
Bookatz867c0d72017-03-07 18:23:42 -080045
46 public TimeBase getOnBatteryBackgroundTimeBase(int uid) {
47 return getUidStatsLocked(uid).mOnBatteryBackgroundTimeBase;
48 }
Bookatzc8c44962017-05-11 12:12:54 -070049
50 public TimeBase getOnBatteryScreenOffBackgroundTimeBase(int uid) {
51 return getUidStatsLocked(uid).mOnBatteryScreenOffBackgroundTimeBase;
52 }
Sudheer Shanka38383232017-07-25 09:55:03 -070053
54 public MockBatteryStatsImpl setPowerProfile(PowerProfile powerProfile) {
55 mPowerProfile = powerProfile;
56 return this;
57 }
58
59 public MockBatteryStatsImpl setKernelUidCpuFreqTimeReader(KernelUidCpuFreqTimeReader reader) {
60 mKernelUidCpuFreqTimeReader = reader;
61 return this;
62 }
63
64 public MockBatteryStatsImpl setKernelUidCpuTimeReader(KernelUidCpuTimeReader reader) {
65 mKernelUidCpuTimeReader = reader;
66 return this;
67 }
68
69 public MockBatteryStatsImpl setKernelCpuSpeedReaders(KernelCpuSpeedReader[] readers) {
70 mKernelCpuSpeedReaders = readers;
71 return this;
72 }
73
74 public MockBatteryStatsImpl setUserInfoProvider(UserInfoProvider provider) {
75 mUserInfoProvider = provider;
76 return this;
77 }
78
79 public MockBatteryStatsImpl setPartialTimers(ArrayList<StopwatchTimer> partialTimers) {
80 mPartialTimers = partialTimers;
81 return this;
82 }
83
84 public MockBatteryStatsImpl setLastPartialTimers(ArrayList<StopwatchTimer> lastPartialTimers) {
85 mLastPartialTimers = lastPartialTimers;
86 return this;
87 }
88
89 public MockBatteryStatsImpl setOnBatteryInternal(boolean onBatteryInternal) {
90 mOnBatteryInternal = onBatteryInternal;
91 return this;
92 }
Joe Onoratoabded112016-02-08 16:49:39 -080093}
94