1 /* 2 * Copyright (C) 2018 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.powermodel.component; 18 19 import com.android.powermodel.ActivityReport; 20 import com.android.powermodel.AttributionKey; 21 import com.android.powermodel.Component; 22 import com.android.powermodel.ComponentActivity; 23 import com.android.powermodel.PowerProfile; 24 import com.android.powermodel.util.Conversion; 25 26 /** 27 * Encapsulates the work done by the remaining 28 */ 29 public class ModemRemainderActivity extends ComponentActivity { 30 /** 31 * Construct a new ModemRemainderActivity. 32 */ ModemRemainderActivity(AttributionKey attribution)33 public ModemRemainderActivity(AttributionKey attribution) { 34 super(attribution); 35 } 36 37 /** 38 * Number of milliseconds spent at each of the signal strengths. 39 */ 40 public long[] strengthTimeMs; 41 42 /** 43 * Number of milliseconds spent scanning for a network. 44 */ 45 public long scanningTimeMs; 46 47 /** 48 * Number of milliseconds that the radio is active for reasons other 49 * than an app transmitting and receiving data. 50 */ 51 public long activeTimeMs; 52 53 @Override applyProfile(ActivityReport activityReport, PowerProfile profile)54 public ModemRemainderPower applyProfile(ActivityReport activityReport, PowerProfile profile) { 55 // Profile 56 final ModemProfile modemProfile = (ModemProfile)profile.getComponent(Component.MODEM); 57 if (modemProfile == null) { 58 return null; 59 } 60 61 // Activity 62 final ModemRemainderPower result = new ModemRemainderPower(); 63 result.attribution = this.attribution; 64 result.activity = this; 65 66 // strengthMah 67 // TODO: If the array lengths don't match... then? 68 result.strengthMah = new double[this.strengthTimeMs.length]; 69 for (int i=0; i<this.strengthTimeMs.length; i++) { 70 result.strengthMah[i] = Conversion.msToHr( 71 this.strengthTimeMs[i] * modemProfile.getTxMa()[i]); 72 result.powerMah += result.strengthMah[i]; 73 } 74 75 // scanningMah 76 result.scanningMah = Conversion.msToHr(this.scanningTimeMs * modemProfile.getScanningMa()); 77 result.powerMah += result.scanningMah; 78 79 // activeMah 80 result.activeMah = Conversion.msToHr( 81 this.activeTimeMs * ModemAppActivity.getAverageModemPowerMa(modemProfile)); 82 result.powerMah += result.activeMah; 83 84 return result; 85 } 86 } 87 88