Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12dec126 authored by Carmen Agimof's avatar Carmen Agimof
Browse files

Change the pulled atom SDCardInfo to ExternalStorageInfo so that we log

information about all types of external storage (e.g. USBs).

Bug: 123688171
Test: Manually tested using statsd_testdrive script
Change-Id: I4bc7c43bb7f5ee9dee3989eb724d05c4d350aff2
parent 09e2fbe6
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -310,7 +310,7 @@ message Atom {
        DangerousPermissionState dangerous_permission_state = 10050;
        TrainInfo train_info = 10051;
        TimeZoneDataInfo time_zone_data_info = 10052;
        SDCardInfo sdcard_info = 10053;
        ExternalStorageInfo external_storage_info = 10053;
        GpuStatsGlobalInfo gpu_stats_global_info = 10054;
        GpuStatsAppInfo gpu_stats_app_info = 10055;
        SystemIonHeapSize system_ion_heap_size = 10056;
@@ -3311,25 +3311,27 @@ message BatteryCycleCount {
}

/**
 * Logs that an SD card is mounted and information about it, its type (public or private) and the
 * size in bytes.
 * Logs that external storage is mounted and information about it, the storage type (sd card/usb/
 * others), its type (public or private) and the size in bytes.
 * Pulled from:
 *   StatsCompanionService
 */

message SDCardInfo {
message ExternalStorageInfo {

    enum Type {
    enum VolumeType {
        UNKNOWN = 0;
        TYPE_PUBLIC = 1;
        TYPE_PRIVATE = 2;
        OTHERS = 3;
        PUBLIC = 1;
        PRIVATE = 2;
        OTHER = 3;
    }

    // Type of the SD card: TYPE_PUBLIC if portable and TYPE_PRIVATE if internal.
    optional Type type = 1;
    // The type of external storage.
    optional android.stats.storage.ExternalStorageType storage_type = 1;
    // Type of the volume: TYPE_PUBLIC if portable and TYPE_PRIVATE if internal.
    optional VolumeType volume_type = 2;
    // Total size of the sd card in bytes.
    optional int64 size_bytes = 2;
    optional int64 size_bytes = 3;
}

/*
+3 −3
Original line number Diff line number Diff line
@@ -242,9 +242,9 @@ std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
        // TimeZoneDataInfo.
        {android::util::TIME_ZONE_DATA_INFO,
         {.puller = new StatsCompanionServicePuller(android::util::TIME_ZONE_DATA_INFO)}},
        // SDCardInfo
        {android::util::SDCARD_INFO,
         {.puller = new StatsCompanionServicePuller(android::util::SDCARD_INFO)}},
        // ExternalStorageInfo
        {android::util::EXTERNAL_STORAGE_INFO,
         {.puller = new StatsCompanionServicePuller(android::util::EXTERNAL_STORAGE_INFO)}},
        // GpuStatsGlobalInfo
        {android::util::GPU_STATS_GLOBAL_INFO,
         {.puller = new GpuStatsPuller(android::util::GPU_STATS_GLOBAL_INFO)}},
+26 −5
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS;
import static android.os.Process.getPidsForCommands;
import static android.os.Process.getUidForPid;
import static android.os.storage.VolumeInfo.TYPE_PRIVATE;
import static android.os.storage.VolumeInfo.TYPE_PUBLIC;

import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.server.am.MemoryStatUtil.readCmdlineFromProcfs;
@@ -89,6 +91,7 @@ import android.os.UserManager;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.stats.storage.StorageEnums;
import android.telephony.ModemActivityInfo;
import android.telephony.TelephonyManager;
import android.util.ArrayMap;
@@ -1968,7 +1971,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
        pulledData.add(e);
    }

    private void pullSDCardInfo(int tagId, long elapsedNanos, long wallClockNanos,
    private void pullExternalStorageInfo(int tagId, long elapsedNanos, long wallClockNanos,
            List<StatsLogEventWrapper> pulledData) {
        StorageManager storageManager = mContext.getSystemService(StorageManager.class);
        if (storageManager != null) {
@@ -1976,11 +1979,29 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
            for (VolumeInfo vol : volumes) {
                final String envState = VolumeInfo.getEnvironmentForState(vol.getState());
                final DiskInfo diskInfo = vol.getDisk();
                if (diskInfo != null && diskInfo.isSd()) {
                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(vol.getType() + 1);
                        e.writeInt(externalStorageType);
                        e.writeInt(volumeType);
                        e.writeLong(diskInfo.size);
                        pulledData.add(e);
                    }
@@ -2185,8 +2206,8 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                pullTimeZoneDataInfo(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }
            case StatsLog.SDCARD_INFO: {
                pullSDCardInfo(tagId, elapsedNanos, wallClockNanos, ret);
            case StatsLog.EXTERNAL_STORAGE_INFO: {
                pullExternalStorageInfo(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }
            default: