summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java83
-rw-r--r--cmds/statsd/src/external/StatsPullerManager.cpp8
-rw-r--r--services/core/java/com/android/server/stats/pull/StatsPullAtomService.java104
3 files changed, 98 insertions, 97 deletions
diff --git a/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java b/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java
index 833aec690ee2..e5d1182903f4 100644
--- a/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java
+++ b/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java
@@ -856,79 +856,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
pulledData.add(e);
}
- private void pullExternalStorageInfo(int tagId, long elapsedNanos, long wallClockNanos,
- List<StatsLogEventWrapper> pulledData) {
- StorageManager storageManager = mContext.getSystemService(StorageManager.class);
- if (storageManager != null) {
- List<VolumeInfo> volumes = storageManager.getVolumes();
- for (VolumeInfo vol : volumes) {
- final String envState = VolumeInfo.getEnvironmentForState(vol.getState());
- final DiskInfo diskInfo = vol.getDisk();
- if (diskInfo != null) {
- if (envState.equals(Environment.MEDIA_MOUNTED)) {
- // Get the type of the volume, if it is adoptable or portable.
- int volumeType = StatsLog.EXTERNAL_STORAGE_INFO__VOLUME_TYPE__OTHER;
- if (vol.getType() == TYPE_PUBLIC) {
- volumeType = StatsLog.EXTERNAL_STORAGE_INFO__VOLUME_TYPE__PUBLIC;
- } else if (vol.getType() == TYPE_PRIVATE) {
- volumeType = StatsLog.EXTERNAL_STORAGE_INFO__VOLUME_TYPE__PRIVATE;
- }
- // Get the type of external storage inserted in the device (sd cards,
- // usb, etc)
- int externalStorageType;
- if (diskInfo.isSd()) {
- externalStorageType = StorageEnums.SD_CARD;
- } else if (diskInfo.isUsb()) {
- externalStorageType = StorageEnums.USB;
- } else {
- externalStorageType = StorageEnums.OTHER;
- }
- StatsLogEventWrapper e =
- new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
- e.writeInt(externalStorageType);
- e.writeInt(volumeType);
- e.writeLong(diskInfo.size);
- pulledData.add(e);
- }
- }
- }
- }
- }
-
- private void pullAppsOnExternalStorageInfo(int tagId, long elapsedNanos, long wallClockNanos,
- List<StatsLogEventWrapper> pulledData) {
- PackageManager pm = mContext.getPackageManager();
- StorageManager storage = mContext.getSystemService(StorageManager.class);
- List<ApplicationInfo> apps = pm.getInstalledApplications(/* flags = */ 0);
- for (ApplicationInfo appInfo : apps) {
- UUID storageUuid = appInfo.storageUuid;
- if (storageUuid != null) {
- VolumeInfo volumeInfo = storage.findVolumeByUuid(appInfo.storageUuid.toString());
- if (volumeInfo != null) {
- DiskInfo diskInfo = volumeInfo.getDisk();
- if (diskInfo != null) {
- int externalStorageType = -1;
- if (diskInfo.isSd()) {
- externalStorageType = StorageEnums.SD_CARD;
- } else if (diskInfo.isUsb()) {
- externalStorageType = StorageEnums.USB;
- } else if (appInfo.isExternal()) {
- externalStorageType = StorageEnums.OTHER;
- }
- // App is installed on external storage.
- if (externalStorageType != -1) {
- StatsLogEventWrapper e =
- new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
- e.writeInt(externalStorageType);
- e.writeString(appInfo.packageName);
- pulledData.add(e);
- }
- }
- }
- }
- }
- }
-
private void pullFaceSettings(int tagId, long elapsedNanos, long wallClockNanos,
List<StatsLogEventWrapper> pulledData) {
long callingToken = Binder.clearCallingIdentity();
@@ -1001,16 +928,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
break;
}
- case StatsLog.EXTERNAL_STORAGE_INFO: {
- pullExternalStorageInfo(tagId, elapsedNanos, wallClockNanos, ret);
- break;
- }
-
- case StatsLog.APPS_ON_EXTERNAL_STORAGE_INFO: {
- pullAppsOnExternalStorageInfo(tagId, elapsedNanos, wallClockNanos, ret);
- break;
- }
-
case StatsLog.FACE_SETTINGS: {
pullFaceSettings(tagId, elapsedNanos, wallClockNanos, ret);
break;
diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp
index f2c4c855164c..b1589f9e674d 100644
--- a/cmds/statsd/src/external/StatsPullerManager.cpp
+++ b/cmds/statsd/src/external/StatsPullerManager.cpp
@@ -109,10 +109,6 @@ std::map<PullerKey, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
// TrainInfo.
{{.atomTag = android::util::TRAIN_INFO}, {.puller = new TrainInfoPuller()}},
- // ExternalStorageInfo
- {{.atomTag = android::util::EXTERNAL_STORAGE_INFO},
- {.puller = new StatsCompanionServicePuller(android::util::EXTERNAL_STORAGE_INFO)}},
-
// GpuStatsGlobalInfo
{{.atomTag = android::util::GPU_STATS_GLOBAL_INFO},
{.puller = new GpuStatsPuller(android::util::GPU_STATS_GLOBAL_INFO)}},
@@ -121,10 +117,6 @@ std::map<PullerKey, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
{{.atomTag = android::util::GPU_STATS_APP_INFO},
{.puller = new GpuStatsPuller(android::util::GPU_STATS_APP_INFO)}},
- // AppsOnExternalStorageInfo
- {{.atomTag = android::util::APPS_ON_EXTERNAL_STORAGE_INFO},
- {.puller = new StatsCompanionServicePuller(android::util::APPS_ON_EXTERNAL_STORAGE_INFO)}},
-
// Face Settings
{{.atomTag = android::util::FACE_SETTINGS},
{.puller = new StatsCompanionServicePuller(android::util::FACE_SETTINGS)}},
diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
index fda366f94c8f..b11ec6fd97fb 100644
--- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
+++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
@@ -208,6 +208,7 @@ public class StatsPullAtomService extends SystemService {
private final Context mContext;
private StatsManager mStatsManager;
+ private StorageManager mStorageManager;
public StatsPullAtomService(Context context) {
super(context);
@@ -219,6 +220,7 @@ public class StatsPullAtomService extends SystemService {
mStatsManager = (StatsManager) mContext.getSystemService(Context.STATS_MANAGER);
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mTelephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
+ mStorageManager = (StorageManager) mContext.getSystemService(StorageManager.class);
// Used to initialize the CPU Frequency atom.
PowerProfile powerProfile = new PowerProfile(mContext);
@@ -2389,19 +2391,109 @@ public class StatsPullAtomService extends SystemService {
}
private void registerExternalStorageInfo() {
- // No op.
+ int tagId = StatsLog.EXTERNAL_STORAGE_INFO;
+ mStatsManager.registerPullAtomCallback(
+ tagId,
+ null, // use default PullAtomMetadata values
+ (atomTag, data) -> pullExternalStorageInfo(atomTag, data),
+ BackgroundThread.getExecutor()
+ );
}
- private void pullExternalStorageInfo() {
- // No op.
+ private int pullExternalStorageInfo(int atomTag, List<StatsEvent> pulledData) {
+ if (mStorageManager == null) {
+ return StatsManager.PULL_SKIP;
+ }
+
+ List<VolumeInfo> volumes = mStorageManager.getVolumes();
+ for (VolumeInfo vol : volumes) {
+ final String envState = VolumeInfo.getEnvironmentForState(vol.getState());
+ final DiskInfo diskInfo = vol.getDisk();
+ if (diskInfo != null && envState.equals(Environment.MEDIA_MOUNTED)) {
+ // Get the type of the volume, if it is adoptable or portable.
+ int volumeType = StatsLog.EXTERNAL_STORAGE_INFO__VOLUME_TYPE__OTHER;
+ if (vol.getType() == TYPE_PUBLIC) {
+ volumeType = StatsLog.EXTERNAL_STORAGE_INFO__VOLUME_TYPE__PUBLIC;
+ } else if (vol.getType() == TYPE_PRIVATE) {
+ volumeType = StatsLog.EXTERNAL_STORAGE_INFO__VOLUME_TYPE__PRIVATE;
+ }
+
+ // Get the type of external storage inserted in the device (sd cards, usb, etc.)
+ int externalStorageType;
+ if (diskInfo.isSd()) {
+ externalStorageType = StorageEnums.SD_CARD;
+ } else if (diskInfo.isUsb()) {
+ externalStorageType = StorageEnums.USB;
+ } else {
+ externalStorageType = StorageEnums.OTHER;
+ }
+
+ StatsEvent e = StatsEvent.newBuilder()
+ .setAtomId(atomTag)
+ .writeInt(externalStorageType)
+ .writeInt(volumeType)
+ .writeLong(diskInfo.size)
+ .build();
+ pulledData.add(e);
+ }
+ }
+ return StatsManager.PULL_SUCCESS;
}
private void registerAppsOnExternalStorageInfo() {
- // No op.
+ int tagId = StatsLog.APPS_ON_EXTERNAL_STORAGE_INFO;
+ mStatsManager.registerPullAtomCallback(
+ tagId,
+ null, // use default PullAtomMetadata values
+ (atomTag, data) -> pullAppsOnExternalStorageInfo(atomTag, data),
+ BackgroundThread.getExecutor()
+ );
}
- private void pullAppsOnExternalStorageInfo() {
- // No op.
+ private int pullAppsOnExternalStorageInfo(int atomTag, List<StatsEvent> pulledData) {
+ if (mStorageManager == null) {
+ return StatsManager.PULL_SKIP;
+ }
+
+ PackageManager pm = mContext.getPackageManager();
+ List<ApplicationInfo> apps = pm.getInstalledApplications(/*flags=*/ 0);
+ for (ApplicationInfo appInfo : apps) {
+ UUID storageUuid = appInfo.storageUuid;
+ if (storageUuid == null) {
+ continue;
+ }
+
+ VolumeInfo volumeInfo = mStorageManager.findVolumeByUuid(
+ appInfo.storageUuid.toString());
+ if (volumeInfo == null) {
+ continue;
+ }
+
+ DiskInfo diskInfo = volumeInfo.getDisk();
+ if (diskInfo == null) {
+ continue;
+ }
+
+ int externalStorageType = -1;
+ if (diskInfo.isSd()) {
+ externalStorageType = StorageEnums.SD_CARD;
+ } else if (diskInfo.isUsb()) {
+ externalStorageType = StorageEnums.USB;
+ } else if (appInfo.isExternal()) {
+ externalStorageType = StorageEnums.OTHER;
+ }
+
+ // App is installed on external storage.
+ if (externalStorageType != -1) {
+ StatsEvent e = StatsEvent.newBuilder()
+ .setAtomId(atomTag)
+ .writeInt(externalStorageType)
+ .writeString(appInfo.packageName)
+ .build();
+ pulledData.add(e);
+ }
+ }
+ return StatsManager.PULL_SUCCESS;
}
private void registerFaceSettings() {