Merge changes I1eec8c74,I6c4e80df
* changes: Migrate pullModemActivityInfo Migrate pullWifiActivityInfo
This commit is contained in:
committed by
Android (Google) Code Review
commit
0e332b3dcb
@@ -714,111 +714,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to extract the Parcelable controller info from a
|
||||
* SynchronousResultReceiver.
|
||||
*/
|
||||
private static <T extends Parcelable> T awaitControllerInfo(
|
||||
@Nullable SynchronousResultReceiver receiver) {
|
||||
if (receiver == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
final SynchronousResultReceiver.Result result =
|
||||
receiver.awaitResult(EXTERNAL_STATS_SYNC_TIMEOUT_MILLIS);
|
||||
if (result.bundle != null) {
|
||||
// This is the final destination for the Bundle.
|
||||
result.bundle.setDefusable(true);
|
||||
|
||||
final T data = result.bundle.getParcelable(
|
||||
RESULT_RECEIVER_CONTROLLER_KEY);
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Slog.e(TAG, "no controller energy info supplied for " + receiver.getName());
|
||||
} catch (TimeoutException e) {
|
||||
Slog.w(TAG, "timeout reading " + receiver.getName() + " stats");
|
||||
}
|
||||
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) {
|
||||
long token = Binder.clearCallingIdentity();
|
||||
synchronized (this) {
|
||||
if (mTelephony == null) {
|
||||
mTelephony = mContext.getSystemService(TelephonyManager.class);
|
||||
}
|
||||
}
|
||||
if (mTelephony != null) {
|
||||
SynchronousResultReceiver modemReceiver = new SynchronousResultReceiver("telephony");
|
||||
mTelephony.requestModemActivityInfo(modemReceiver);
|
||||
final ModemActivityInfo modemInfo = awaitControllerInfo(modemReceiver);
|
||||
StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
|
||||
e.writeLong(modemInfo.getTimestamp());
|
||||
e.writeLong(modemInfo.getSleepTimeMillis());
|
||||
e.writeLong(modemInfo.getIdleTimeMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(0).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(1).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(2).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(3).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(4).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getReceiveTimeMillis());
|
||||
pulledData.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void pullSystemElapsedRealtime(
|
||||
int tagId, long elapsedNanos, long wallClockNanos,
|
||||
List<StatsLogEventWrapper> pulledData) {
|
||||
@@ -1995,16 +1890,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;
|
||||
}
|
||||
|
||||
case StatsLog.SYSTEM_ELAPSED_REALTIME: {
|
||||
pullSystemElapsedRealtime(tagId, elapsedNanos, wallClockNanos, ret);
|
||||
break;
|
||||
|
||||
@@ -68,14 +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)}},
|
||||
|
||||
// system_elapsed_realtime
|
||||
{{.atomTag = android::util::SYSTEM_ELAPSED_REALTIME},
|
||||
{.coolDownNs = NS_PER_SEC,
|
||||
|
||||
@@ -211,6 +211,8 @@ public class StatsPullAtomService extends SystemService {
|
||||
@Override
|
||||
public void onStart() {
|
||||
mStatsManager = (StatsManager) mContext.getSystemService(Context.STATS_MANAGER);
|
||||
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||
mTelephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
|
||||
// Used to initialize the CPU Frequency atom.
|
||||
PowerProfile powerProfile = new PowerProfile(mContext);
|
||||
@@ -814,19 +816,96 @@ 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 TelephonyManager mTelephony;
|
||||
|
||||
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() {
|
||||
// No op.
|
||||
int tagId = StatsLog.MODEM_ACTIVITY_INFO;
|
||||
mStatsManager.registerPullAtomCallback(
|
||||
tagId,
|
||||
null, // use default PullAtomMetadata values
|
||||
(atomTag, data) -> pullModemActivityInfo(atomTag, data),
|
||||
BackgroundThread.getExecutor()
|
||||
);
|
||||
}
|
||||
|
||||
private void pullModemActivityInfo() {
|
||||
// No op.
|
||||
private int pullModemActivityInfo(int atomTag, List<StatsEvent> pulledData) {
|
||||
long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
SynchronousResultReceiver modemReceiver = new SynchronousResultReceiver("telephony");
|
||||
mTelephony.requestModemActivityInfo(modemReceiver);
|
||||
final ModemActivityInfo modemInfo = awaitControllerInfo(modemReceiver);
|
||||
if (modemInfo == null) {
|
||||
return StatsManager.PULL_SKIP;
|
||||
}
|
||||
StatsEvent e = StatsEvent.newBuilder()
|
||||
.setAtomId(atomTag)
|
||||
.writeLong(modemInfo.getTimestamp())
|
||||
.writeLong(modemInfo.getSleepTimeMillis())
|
||||
.writeLong(modemInfo.getIdleTimeMillis())
|
||||
.writeLong(modemInfo.getTransmitPowerInfo().get(0).getTimeInMillis())
|
||||
.writeLong(modemInfo.getTransmitPowerInfo().get(1).getTimeInMillis())
|
||||
.writeLong(modemInfo.getTransmitPowerInfo().get(2).getTimeInMillis())
|
||||
.writeLong(modemInfo.getTransmitPowerInfo().get(3).getTimeInMillis())
|
||||
.writeLong(modemInfo.getTransmitPowerInfo().get(4).getTimeInMillis())
|
||||
.writeLong(modemInfo.getReceiveTimeMillis())
|
||||
.build();
|
||||
pulledData.add(e);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
return StatsManager.PULL_SUCCESS;
|
||||
}
|
||||
|
||||
private void registerBluetoothActivityInfo() {
|
||||
|
||||
Reference in New Issue
Block a user