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

Commit 35f7f6f3 authored by Carmen Agimof's avatar Carmen Agimof
Browse files

Pull sdcard mounted atom.

Change-Id: I334fef334b67e94ee040026880ffbec2803b9982
Bug: 123688171
Test: Manually tested using statsd_testdrive script
parent 8a742802
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -303,6 +303,7 @@ message Atom {
        DangerousPermissionState dangerous_permission_state = 10050;
        TrainInfo train_info = 10051;
        TimeZoneDataInfo time_zone_data_info = 10052;
        SDCardInfo sdcard_info = 10053;
    }

    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -3231,6 +3232,28 @@ message BatteryCycleCount {
    optional int32 cycle_count = 1;
}

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

message SDCardInfo {

    enum Type {
        UNKNOWN = 0;
        TYPE_PUBLIC = 1;
        TYPE_PRIVATE = 2;
        OTHERS = 3;
    }

    // Type of the SD card: TYPE_PUBLIC if portable and TYPE_PRIVATE if internal.
    optional Type type = 1;
    // Total size of the sd card in bytes.
    optional int64 size_bytes = 2;
}

/*
 * Logs when a connection becomes available and lost.
 * Logged in StatsCompanionService.java
+3 −0
Original line number Diff line number Diff line
@@ -237,6 +237,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)}},
};

StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) {
+27 −0
Original line number Diff line number Diff line
@@ -85,7 +85,9 @@ import android.os.SystemProperties;
import android.os.Temperature;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.telephony.ModemActivityInfo;
import android.telephony.TelephonyManager;
import android.util.ArrayMap;
@@ -1956,6 +1958,27 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
        pulledData.add(e);
    }

    private void pullSDCardInfo(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 && diskInfo.isSd()) {
                    if (envState.equals(Environment.MEDIA_MOUNTED)) {
                        StatsLogEventWrapper e =
                                new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
                        e.writeInt(vol.getType() + 1);
                        e.writeLong(diskInfo.size);
                        pulledData.add(e);
                    }
                }
            }
        }
    }

    /**
     * Pulls various data.
     */
@@ -2148,6 +2171,10 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                pullTimeZoneDataInfo(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }
            case StatsLog.SDCARD_INFO: {
                pullSDCardInfo(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }
            default:
                Slog.w(TAG, "No such tagId data as " + tagId);
                return null;