Loading cmds/statsd/src/external/KernelWakelockPuller.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ namespace android { namespace os { namespace statsd { const int KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS = 20; const int KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS = 1004; // The reading and parsing are implemented in Java. It is not difficult to port over. But for now // let StatsCompanionService handle that and send the data back. Loading cmds/statsd/src/stats_events.proto +107 −15 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ option java_outer_classname = "StatsEventProto"; * in the format defined here and in stats_log.proto. */ message StatsEvent { oneof event { // Pushed events start at 2. oneof pushed { // For StatsLog reasons, 1 is illegal and will not work. Must start at 2. BleScanStateChanged ble_scan_state_changed = 2; BleUnoptimizedScanStateChanged ble_unoptimized_scan_state_changed = 3; Loading Loading @@ -70,10 +71,18 @@ message StatsEvent { WifiScanStateChanged wifi_scan_state_changed = 39; PhoneSignalStrengthChanged phone_signal_strength_changed = 40; SettingChanged setting_changed = 41; KernelWakelockPulled kernel_wakelock_pulled = 42; ActivityForegroundStateChanged activity_foreground_state_changed = 43; ActivityForegroundStateChanged activity_foreground_state_changed = 42; // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15. } // Pulled events will start at field 1000. oneof pulled { WifiBytesTransferred wifi_bytes_transferred = 1000; WifiBytesTransferredByFgBg wifi_bytes_transferred_by_fg_bg = 1001; MobileBytesTransferred mobile_bytes_transferred = 1002; MobileBytesTransferredByFgBg mobile_bytes_transferred_by_fg_bg = 1003; KernelWakelocksReported kernel_wakelocks_reported = 1004; } } /** Loading Loading @@ -682,18 +691,6 @@ message SettingChanged { optional int32 user = 7; } /* * Pulls kernel wakelock changes. * * Pulled from: * frameworks/base/services/core/java/com/android/server/stats/StatsCompanionService.java */ message KernelWakelockPulled { optional int32 count = 1; optional int32 version = 2; optional int64 total_time = 3; optional string name = 4; } /* * Logs activity going to foreground or background Loading @@ -711,3 +708,98 @@ message ActivityForegroundStateChanged { optional string class_name = 3; optional Activity activity = 4; } /** * Pulls bytes transferred via wifi (Sum of foreground and background usage). * * Pulled from: * StatsCompanionService (using BatteryStats to get which interfaces are wifi) */ message WifiBytesTransferred { optional int32 uid = 1; optional int64 rx_bytes = 2; optional int64 rx_packets = 3; optional int64 tx_bytes = 4; optional int64 tx_packets = 5; } /** * Pulls bytes transferred via wifi (separated by foreground and background usage). * * Pulled from: * StatsCompanionService (using BatteryStats to get which interfaces are wifi) */ message WifiBytesTransferredByFgBg { optional int32 uid = 1; // 1 denotes foreground and 0 denotes background. This is called Set in NetworkStats. optional int32 is_foreground = 2; optional int64 rx_bytes = 3; optional int64 rx_packets = 4; optional int64 tx_bytes = 5; optional int64 tx_packets = 6; } /** * Pulls bytes transferred via mobile networks (Sum of foreground and background usage). * * Pulled from: * StatsCompanionService (using BatteryStats to get which interfaces are mobile data) */ message MobileBytesTransferred { optional int32 uid = 1; optional int64 rx_bytes = 2; optional int64 rx_packets = 3; optional int64 tx_bytes = 4; optional int64 tx_packets = 5; } /** * Pulls bytes transferred via mobile networks (separated by foreground and background usage). * * Pulled from: * StatsCompanionService (using BatteryStats to get which interfaces are mobile data) */ message MobileBytesTransferredByFgBg { optional int32 uid = 1; // 1 denotes foreground and 0 denotes background. This is called Set in NetworkStats. optional int32 is_foreground = 2; optional int64 rx_bytes = 3; optional int64 rx_packets = 4; optional int64 tx_bytes = 5; optional int64 tx_packets = 6; } /** * Pulls the kernel wakelock durations. This atom is adapted from * android/internal/os/KernelWakelockStats.java * * Pulled from: * StatsCompanionService using KernelWakelockReader. */ message KernelWakelocksReported { optional string name = 1; optional int32 count = 2; optional int32 version = 3; optional int64 time = 4; } core/java/android/os/BatteryStatsInternal.java 0 → 100644 +35 −0 Original line number Diff line number Diff line /* * Copyright 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; /** * Battery stats local system service interface. This is used to pass internal data out of * BatteryStatsImpl. * * @hide Only for use within Android OS. */ public abstract class BatteryStatsInternal { /** * Returns the wifi interfaces. */ public abstract String[] getWifiIfaces(); /** * Returns the mobile data interfaces. */ public abstract String[] getMobileIfaces(); } core/java/com/android/internal/os/BatteryStatsImpl.java +12 −0 Original line number Diff line number Diff line Loading @@ -5412,6 +5412,18 @@ public class BatteryStatsImpl extends BatteryStats { } } public String[] getWifiIfaces() { synchronized (mWifiNetworkLock) { return mWifiIfaces; } } public String[] getMobileIfaces() { synchronized (mModemNetworkLock) { return mModemIfaces; } } @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); } Loading services/core/java/com/android/server/am/BatteryStatsService.java +14 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.pm.PackageManager; import android.net.wifi.WifiActivityEnergyInfo; import android.os.PowerSaveState; import android.os.BatteryStats; import android.os.BatteryStatsInternal; import android.os.Binder; import android.os.Handler; import android.os.IBinder; Loading Loading @@ -177,9 +178,22 @@ public final class BatteryStatsService extends IBatteryStats.Stub } public void publish() { LocalServices.addService(BatteryStatsInternal.class, new LocalService()); ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder()); } private final class LocalService extends BatteryStatsInternal { @Override public String[] getWifiIfaces() { return mStats.getWifiIfaces().clone(); } @Override public String[] getMobileIfaces() { return mStats.getMobileIfaces().clone(); } } private static void awaitUninterruptibly(Future<?> future) { while (true) { try { Loading Loading
cmds/statsd/src/external/KernelWakelockPuller.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ namespace android { namespace os { namespace statsd { const int KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS = 20; const int KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS = 1004; // The reading and parsing are implemented in Java. It is not difficult to port over. But for now // let StatsCompanionService handle that and send the data back. Loading
cmds/statsd/src/stats_events.proto +107 −15 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ option java_outer_classname = "StatsEventProto"; * in the format defined here and in stats_log.proto. */ message StatsEvent { oneof event { // Pushed events start at 2. oneof pushed { // For StatsLog reasons, 1 is illegal and will not work. Must start at 2. BleScanStateChanged ble_scan_state_changed = 2; BleUnoptimizedScanStateChanged ble_unoptimized_scan_state_changed = 3; Loading Loading @@ -70,10 +71,18 @@ message StatsEvent { WifiScanStateChanged wifi_scan_state_changed = 39; PhoneSignalStrengthChanged phone_signal_strength_changed = 40; SettingChanged setting_changed = 41; KernelWakelockPulled kernel_wakelock_pulled = 42; ActivityForegroundStateChanged activity_foreground_state_changed = 43; ActivityForegroundStateChanged activity_foreground_state_changed = 42; // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15. } // Pulled events will start at field 1000. oneof pulled { WifiBytesTransferred wifi_bytes_transferred = 1000; WifiBytesTransferredByFgBg wifi_bytes_transferred_by_fg_bg = 1001; MobileBytesTransferred mobile_bytes_transferred = 1002; MobileBytesTransferredByFgBg mobile_bytes_transferred_by_fg_bg = 1003; KernelWakelocksReported kernel_wakelocks_reported = 1004; } } /** Loading Loading @@ -682,18 +691,6 @@ message SettingChanged { optional int32 user = 7; } /* * Pulls kernel wakelock changes. * * Pulled from: * frameworks/base/services/core/java/com/android/server/stats/StatsCompanionService.java */ message KernelWakelockPulled { optional int32 count = 1; optional int32 version = 2; optional int64 total_time = 3; optional string name = 4; } /* * Logs activity going to foreground or background Loading @@ -711,3 +708,98 @@ message ActivityForegroundStateChanged { optional string class_name = 3; optional Activity activity = 4; } /** * Pulls bytes transferred via wifi (Sum of foreground and background usage). * * Pulled from: * StatsCompanionService (using BatteryStats to get which interfaces are wifi) */ message WifiBytesTransferred { optional int32 uid = 1; optional int64 rx_bytes = 2; optional int64 rx_packets = 3; optional int64 tx_bytes = 4; optional int64 tx_packets = 5; } /** * Pulls bytes transferred via wifi (separated by foreground and background usage). * * Pulled from: * StatsCompanionService (using BatteryStats to get which interfaces are wifi) */ message WifiBytesTransferredByFgBg { optional int32 uid = 1; // 1 denotes foreground and 0 denotes background. This is called Set in NetworkStats. optional int32 is_foreground = 2; optional int64 rx_bytes = 3; optional int64 rx_packets = 4; optional int64 tx_bytes = 5; optional int64 tx_packets = 6; } /** * Pulls bytes transferred via mobile networks (Sum of foreground and background usage). * * Pulled from: * StatsCompanionService (using BatteryStats to get which interfaces are mobile data) */ message MobileBytesTransferred { optional int32 uid = 1; optional int64 rx_bytes = 2; optional int64 rx_packets = 3; optional int64 tx_bytes = 4; optional int64 tx_packets = 5; } /** * Pulls bytes transferred via mobile networks (separated by foreground and background usage). * * Pulled from: * StatsCompanionService (using BatteryStats to get which interfaces are mobile data) */ message MobileBytesTransferredByFgBg { optional int32 uid = 1; // 1 denotes foreground and 0 denotes background. This is called Set in NetworkStats. optional int32 is_foreground = 2; optional int64 rx_bytes = 3; optional int64 rx_packets = 4; optional int64 tx_bytes = 5; optional int64 tx_packets = 6; } /** * Pulls the kernel wakelock durations. This atom is adapted from * android/internal/os/KernelWakelockStats.java * * Pulled from: * StatsCompanionService using KernelWakelockReader. */ message KernelWakelocksReported { optional string name = 1; optional int32 count = 2; optional int32 version = 3; optional int64 time = 4; }
core/java/android/os/BatteryStatsInternal.java 0 → 100644 +35 −0 Original line number Diff line number Diff line /* * Copyright 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; /** * Battery stats local system service interface. This is used to pass internal data out of * BatteryStatsImpl. * * @hide Only for use within Android OS. */ public abstract class BatteryStatsInternal { /** * Returns the wifi interfaces. */ public abstract String[] getWifiIfaces(); /** * Returns the mobile data interfaces. */ public abstract String[] getMobileIfaces(); }
core/java/com/android/internal/os/BatteryStatsImpl.java +12 −0 Original line number Diff line number Diff line Loading @@ -5412,6 +5412,18 @@ public class BatteryStatsImpl extends BatteryStats { } } public String[] getWifiIfaces() { synchronized (mWifiNetworkLock) { return mWifiIfaces; } } public String[] getMobileIfaces() { synchronized (mModemNetworkLock) { return mModemIfaces; } } @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); } Loading
services/core/java/com/android/server/am/BatteryStatsService.java +14 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.pm.PackageManager; import android.net.wifi.WifiActivityEnergyInfo; import android.os.PowerSaveState; import android.os.BatteryStats; import android.os.BatteryStatsInternal; import android.os.Binder; import android.os.Handler; import android.os.IBinder; Loading Loading @@ -177,9 +178,22 @@ public final class BatteryStatsService extends IBatteryStats.Stub } public void publish() { LocalServices.addService(BatteryStatsInternal.class, new LocalService()); ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder()); } private final class LocalService extends BatteryStatsInternal { @Override public String[] getWifiIfaces() { return mStats.getWifiIfaces().clone(); } @Override public String[] getMobileIfaces() { return mStats.getMobileIfaces().clone(); } } private static void awaitUninterruptibly(Future<?> future) { while (true) { try { Loading