1 /* 2 * Copyright (C) 2024 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 package com.android.server.power.stats; 17 18 import android.annotation.NonNull; 19 import android.os.PersistableBundle; 20 21 import com.android.internal.os.PowerStats; 22 23 public class BluetoothPowerStatsLayout extends PowerStatsLayout { 24 private static final String EXTRA_DEVICE_RX_TIME_POSITION = "dt-rx"; 25 private static final String EXTRA_DEVICE_TX_TIME_POSITION = "dt-tx"; 26 private static final String EXTRA_DEVICE_IDLE_TIME_POSITION = "dt-idle"; 27 private static final String EXTRA_DEVICE_SCAN_TIME_POSITION = "dt-scan"; 28 private static final String EXTRA_UID_RX_BYTES_POSITION = "ub-rx"; 29 private static final String EXTRA_UID_TX_BYTES_POSITION = "ub-tx"; 30 private static final String EXTRA_UID_SCAN_TIME_POSITION = "ut-scan"; 31 32 private int mDeviceRxTimePosition; 33 private int mDeviceTxTimePosition; 34 private int mDeviceIdleTimePosition; 35 private int mDeviceScanTimePosition; 36 private int mUidRxBytesPosition; 37 private int mUidTxBytesPosition; 38 private int mUidScanTimePosition; 39 BluetoothPowerStatsLayout()40 BluetoothPowerStatsLayout() { 41 } 42 BluetoothPowerStatsLayout(@onNull PowerStats.Descriptor descriptor)43 BluetoothPowerStatsLayout(@NonNull PowerStats.Descriptor descriptor) { 44 super(descriptor); 45 } 46 addDeviceBluetoothControllerActivity()47 void addDeviceBluetoothControllerActivity() { 48 mDeviceRxTimePosition = addDeviceSection(1, "rx"); 49 mDeviceTxTimePosition = addDeviceSection(1, "tx"); 50 mDeviceIdleTimePosition = addDeviceSection(1, "idle"); 51 mDeviceScanTimePosition = addDeviceSection(1, "scan", FLAG_OPTIONAL); 52 } 53 addUidTrafficStats()54 void addUidTrafficStats() { 55 mUidRxBytesPosition = addUidSection(1, "rx-B"); 56 mUidTxBytesPosition = addUidSection(1, "tx-B"); 57 mUidScanTimePosition = addUidSection(1, "scan", FLAG_OPTIONAL); 58 } 59 setDeviceRxTime(long[] stats, long durationMillis)60 public void setDeviceRxTime(long[] stats, long durationMillis) { 61 stats[mDeviceRxTimePosition] = durationMillis; 62 } 63 getDeviceRxTime(long[] stats)64 public long getDeviceRxTime(long[] stats) { 65 return stats[mDeviceRxTimePosition]; 66 } 67 setDeviceTxTime(long[] stats, long durationMillis)68 public void setDeviceTxTime(long[] stats, long durationMillis) { 69 stats[mDeviceTxTimePosition] = durationMillis; 70 } 71 getDeviceTxTime(long[] stats)72 public long getDeviceTxTime(long[] stats) { 73 return stats[mDeviceTxTimePosition]; 74 } 75 setDeviceIdleTime(long[] stats, long durationMillis)76 public void setDeviceIdleTime(long[] stats, long durationMillis) { 77 stats[mDeviceIdleTimePosition] = durationMillis; 78 } 79 getDeviceIdleTime(long[] stats)80 public long getDeviceIdleTime(long[] stats) { 81 return stats[mDeviceIdleTimePosition]; 82 } 83 setDeviceScanTime(long[] stats, long durationMillis)84 public void setDeviceScanTime(long[] stats, long durationMillis) { 85 stats[mDeviceScanTimePosition] = durationMillis; 86 } 87 getDeviceScanTime(long[] stats)88 public long getDeviceScanTime(long[] stats) { 89 return stats[mDeviceScanTimePosition]; 90 } 91 setUidRxBytes(long[] stats, long count)92 public void setUidRxBytes(long[] stats, long count) { 93 stats[mUidRxBytesPosition] = count; 94 } 95 getUidRxBytes(long[] stats)96 public long getUidRxBytes(long[] stats) { 97 return stats[mUidRxBytesPosition]; 98 } 99 setUidTxBytes(long[] stats, long count)100 public void setUidTxBytes(long[] stats, long count) { 101 stats[mUidTxBytesPosition] = count; 102 } 103 getUidTxBytes(long[] stats)104 public long getUidTxBytes(long[] stats) { 105 return stats[mUidTxBytesPosition]; 106 } 107 setUidScanTime(long[] stats, long count)108 public void setUidScanTime(long[] stats, long count) { 109 stats[mUidScanTimePosition] = count; 110 } 111 getUidScanTime(long[] stats)112 public long getUidScanTime(long[] stats) { 113 return stats[mUidScanTimePosition]; 114 } 115 116 /** 117 * Copies the elements of the stats array layout into <code>extras</code> 118 */ toExtras(PersistableBundle extras)119 public void toExtras(PersistableBundle extras) { 120 super.toExtras(extras); 121 extras.putInt(EXTRA_DEVICE_RX_TIME_POSITION, mDeviceRxTimePosition); 122 extras.putInt(EXTRA_DEVICE_TX_TIME_POSITION, mDeviceTxTimePosition); 123 extras.putInt(EXTRA_DEVICE_IDLE_TIME_POSITION, mDeviceIdleTimePosition); 124 extras.putInt(EXTRA_DEVICE_SCAN_TIME_POSITION, mDeviceScanTimePosition); 125 extras.putInt(EXTRA_UID_RX_BYTES_POSITION, mUidRxBytesPosition); 126 extras.putInt(EXTRA_UID_TX_BYTES_POSITION, mUidTxBytesPosition); 127 extras.putInt(EXTRA_UID_SCAN_TIME_POSITION, mUidScanTimePosition); 128 } 129 130 /** 131 * Retrieves elements of the stats array layout from <code>extras</code> 132 */ fromExtras(PersistableBundle extras)133 public void fromExtras(PersistableBundle extras) { 134 super.fromExtras(extras); 135 mDeviceRxTimePosition = extras.getInt(EXTRA_DEVICE_RX_TIME_POSITION); 136 mDeviceTxTimePosition = extras.getInt(EXTRA_DEVICE_TX_TIME_POSITION); 137 mDeviceIdleTimePosition = extras.getInt(EXTRA_DEVICE_IDLE_TIME_POSITION); 138 mDeviceScanTimePosition = extras.getInt(EXTRA_DEVICE_SCAN_TIME_POSITION); 139 mUidRxBytesPosition = extras.getInt(EXTRA_UID_RX_BYTES_POSITION); 140 mUidTxBytesPosition = extras.getInt(EXTRA_UID_TX_BYTES_POSITION); 141 mUidScanTimePosition = extras.getInt(EXTRA_UID_SCAN_TIME_POSITION); 142 } 143 } 144