Migrate pullWifiActivityInfo
Test: atest HostAtomTests#testWifiActivityInfo Test: adb shell cmd stats pull-source 10011 Change-Id: I6c4e80df4121504cdcfb49c9f5b84916ae2adef3
This commit is contained in:
@@ -744,54 +744,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void pullWifiActivityInfo(
|
||||
int tagId, long elapsedNanos, long wallClockNanos,
|
||||
List<StatsLogEventWrapper> pulledData) {
|
||||
WifiManager wifiManager;
|
||||
synchronized (this) {
|
||||
if (mWifiManager == null) {
|
||||
mWifiManager = mContext.getSystemService(WifiManager.class);
|
||||
}
|
||||
wifiManager = mWifiManager;
|
||||
}
|
||||
if (wifiManager == null) {
|
||||
return;
|
||||
}
|
||||
long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
SynchronousResultReceiver wifiReceiver = new SynchronousResultReceiver("wifi");
|
||||
wifiManager.getWifiActivityEnergyInfoAsync(
|
||||
new Executor() {
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
// run the listener on the binder thread, if it was run on the main
|
||||
// thread it would deadlock since we would be waiting on ourselves
|
||||
runnable.run();
|
||||
}
|
||||
},
|
||||
info -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, info);
|
||||
wifiReceiver.send(0, bundle);
|
||||
}
|
||||
);
|
||||
final WifiActivityEnergyInfo wifiInfo = awaitControllerInfo(wifiReceiver);
|
||||
if (wifiInfo == null) {
|
||||
return;
|
||||
}
|
||||
StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
|
||||
e.writeLong(wifiInfo.getTimeSinceBootMillis());
|
||||
e.writeInt(wifiInfo.getStackState());
|
||||
e.writeLong(wifiInfo.getControllerTxDurationMillis());
|
||||
e.writeLong(wifiInfo.getControllerRxDurationMillis());
|
||||
e.writeLong(wifiInfo.getControllerIdleDurationMillis());
|
||||
e.writeLong(wifiInfo.getControllerEnergyUsedMicroJoules());
|
||||
pulledData.add(e);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
}
|
||||
|
||||
private void pullModemActivityInfo(
|
||||
int tagId, long elapsedNanos, long wallClockNanos,
|
||||
List<StatsLogEventWrapper> pulledData) {
|
||||
@@ -2010,11 +1962,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
||||
long wallClockNanos = SystemClock.currentTimeMicro() * 1000L;
|
||||
switch (tagId) {
|
||||
|
||||
case StatsLog.WIFI_ACTIVITY_INFO: {
|
||||
pullWifiActivityInfo(tagId, elapsedNanos, wallClockNanos, ret);
|
||||
break;
|
||||
}
|
||||
|
||||
case StatsLog.MODEM_ACTIVITY_INFO: {
|
||||
pullModemActivityInfo(tagId, elapsedNanos, wallClockNanos, ret);
|
||||
break;
|
||||
|
||||
@@ -68,10 +68,6 @@ std::map<PullerKey, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
|
||||
{{.atomTag = android::util::ON_DEVICE_POWER_MEASUREMENT},
|
||||
{.puller = new PowerStatsPuller()}},
|
||||
|
||||
// wifi_activity_energy_info
|
||||
{{.atomTag = android::util::WIFI_ACTIVITY_INFO},
|
||||
{.puller = new StatsCompanionServicePuller(android::util::WIFI_ACTIVITY_INFO)}},
|
||||
|
||||
// modem_activity_info
|
||||
{{.atomTag = android::util::MODEM_ACTIVITY_INFO},
|
||||
{.puller = new StatsCompanionServicePuller(android::util::MODEM_ACTIVITY_INFO)}},
|
||||
|
||||
@@ -210,6 +210,7 @@ public class StatsPullAtomService extends SystemService {
|
||||
@Override
|
||||
public void onStart() {
|
||||
mStatsManager = (StatsManager) mContext.getSystemService(Context.STATS_MANAGER);
|
||||
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
// Used to initialize the CPU Frequency atom.
|
||||
PowerProfile powerProfile = new PowerProfile(mContext);
|
||||
@@ -812,11 +813,57 @@ public class StatsPullAtomService extends SystemService {
|
||||
}
|
||||
|
||||
private void registerWifiActivityInfo() {
|
||||
// No op.
|
||||
int tagId = StatsLog.WIFI_ACTIVITY_INFO;
|
||||
mStatsManager.registerPullAtomCallback(
|
||||
tagId,
|
||||
null, // use default PullAtomMetadata values
|
||||
(atomTag, data) -> pullWifiActivityInfo(atomTag, data),
|
||||
BackgroundThread.getExecutor()
|
||||
);
|
||||
}
|
||||
|
||||
private void pullWifiActivityInfo() {
|
||||
// No op.
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
private int pullWifiActivityInfo(int atomTag, List<StatsEvent> pulledData) {
|
||||
long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
SynchronousResultReceiver wifiReceiver = new SynchronousResultReceiver("wifi");
|
||||
mWifiManager.getWifiActivityEnergyInfoAsync(
|
||||
new Executor() {
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
// run the listener on the binder thread, if it was run on the main
|
||||
// thread it would deadlock since we would be waiting on ourselves
|
||||
runnable.run();
|
||||
}
|
||||
},
|
||||
info -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, info);
|
||||
wifiReceiver.send(0, bundle);
|
||||
}
|
||||
);
|
||||
final WifiActivityEnergyInfo wifiInfo = awaitControllerInfo(wifiReceiver);
|
||||
if (wifiInfo == null) {
|
||||
return StatsManager.PULL_SKIP;
|
||||
}
|
||||
StatsEvent e = StatsEvent.newBuilder()
|
||||
.setAtomId(atomTag)
|
||||
.writeLong(wifiInfo.getTimeSinceBootMillis())
|
||||
.writeInt(wifiInfo.getStackState())
|
||||
.writeLong(wifiInfo.getControllerTxDurationMillis())
|
||||
.writeLong(wifiInfo.getControllerRxDurationMillis())
|
||||
.writeLong(wifiInfo.getControllerIdleDurationMillis())
|
||||
.writeLong(wifiInfo.getControllerEnergyUsedMicroJoules())
|
||||
.build();
|
||||
pulledData.add(e);
|
||||
} catch (RuntimeException e) {
|
||||
Slog.e(TAG, "failed to getWifiActivityEnergyInfoAsync", e);
|
||||
return StatsManager.PULL_SKIP;
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
return StatsManager.PULL_SUCCESS;
|
||||
}
|
||||
|
||||
private void registerModemActivityInfo() {
|
||||
|
||||
Reference in New Issue
Block a user