1 /* 2 * Copyright (C) 2015 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.loganalysis.rule; 18 19 import com.android.loganalysis.item.BatteryStatsDetailedInfoItem; 20 import com.android.loganalysis.item.BugreportItem; 21 import com.android.loganalysis.item.BatteryStatsSummaryInfoItem; 22 import com.android.loganalysis.item.DumpsysProcStatsItem; 23 import com.android.loganalysis.item.DumpsysWifiStatsItem; 24 25 import org.json.JSONObject; 26 27 /** 28 * Base class for all power rules 29 */ 30 public abstract class AbstractPowerRule implements IRule { 31 32 private BugreportItem mBugreportItem; 33 private BatteryStatsSummaryInfoItem mPowerSummaryAnalysisItem; 34 private BatteryStatsDetailedInfoItem mPowerDetailedAnalysisItem; 35 private DumpsysProcStatsItem mProcStatsItem; 36 private DumpsysWifiStatsItem mWifiStatsItem; 37 AbstractPowerRule(BugreportItem bugreportItem)38 public AbstractPowerRule(BugreportItem bugreportItem) { 39 mBugreportItem = bugreportItem; 40 mPowerSummaryAnalysisItem = mBugreportItem.getDumpsys().getBatteryStats(). 41 getBatteryStatsSummaryItem(); 42 mPowerDetailedAnalysisItem = mBugreportItem.getDumpsys().getBatteryStats(). 43 getDetailedBatteryStatsItem(); 44 mProcStatsItem = mBugreportItem.getDumpsys().getProcStats(); 45 mWifiStatsItem = mBugreportItem.getDumpsys().getWifiStats(); 46 } 47 getTimeOnBattery()48 protected long getTimeOnBattery() { 49 return mPowerDetailedAnalysisItem.getTimeOnBattery(); 50 } 51 getSummaryItem()52 protected BatteryStatsSummaryInfoItem getSummaryItem() { 53 return mPowerSummaryAnalysisItem; 54 } 55 getDetailedAnalysisItem()56 protected BatteryStatsDetailedInfoItem getDetailedAnalysisItem() { 57 return mPowerDetailedAnalysisItem; 58 } 59 getProcStatsItem()60 protected DumpsysProcStatsItem getProcStatsItem() { 61 return mProcStatsItem; 62 } 63 getWifiStatsItem()64 protected DumpsysWifiStatsItem getWifiStatsItem() { 65 return mWifiStatsItem; 66 } 67 68 @Override applyRule()69 public abstract void applyRule(); 70 71 @Override getAnalysis()72 public abstract JSONObject getAnalysis(); 73 74 } 75