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

Commit 9613a973 authored by Jeffrey Huang's avatar Jeffrey Huang
Browse files

Update getStatsMetadata

Test: GTS Tests
Bug: 146384074
Change-Id: I263489874616d4ed5d16f2796fa74c740059a35a
parent 80c9a975
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -92,4 +92,11 @@ interface IStatsManagerService {
     * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
     */
    long[] getRegisteredExperimentIds();

    /**
     * Fetches metadata across statsd. Returns byte array representing wire-encoded proto.
     *
     * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
     */
    byte[] getMetadata(in String packageName);
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ interface IStatsd {
     *
     * Requires Manifest.permission.DUMP.
     */
    byte[] getMetadata(in String packageName);
    byte[] getMetadata();

    /**
     * Sets a configuration with the specified config key and subscribes to updates for this
+18 −0
Original line number Diff line number Diff line
@@ -264,6 +264,24 @@ public class StatsManagerService extends IStatsManagerService.Stub {
        throw new IllegalStateException("Failed to connect to statsd to registerExperimentIds");
    }

    @Override
    public byte[] getMetadata(String packageName) throws IllegalStateException {
        enforceDumpAndUsageStatsPermission(packageName);
        final long token = Binder.clearCallingIdentity();
        try {
            IStatsd statsd = waitForStatsd();
            if (statsd != null) {
                return statsd.getMetadata();
            }
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to getMetadata with statsd");
            throw new IllegalStateException(e.getMessage(), e);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        throw new IllegalStateException("Failed to connect to statsd to getMetadata");
    }

    void setStatsCompanionService(StatsCompanionService statsCompanionService) {
        mStatsCompanionService = statsCompanionService;
    }
+2 −5
Original line number Diff line number Diff line
@@ -1148,12 +1148,9 @@ Status StatsService::getData(int64_t key, const String16& packageName, vector<ui
    return Status::ok();
}

Status StatsService::getMetadata(const String16& packageName, vector<uint8_t>* output) {
    ENFORCE_DUMP_AND_USAGE_STATS(packageName);
Status StatsService::getMetadata(vector<uint8_t>* output) {
    ENFORCE_UID(AID_SYSTEM);

    IPCThreadState* ipc = IPCThreadState::self();
    VLOG("StatsService::getMetadata with Pid %i, Uid %i", ipc->getCallingPid(),
         ipc->getCallingUid());
    StatsdStats::getInstance().dumpStats(output, false); // Don't reset the counters.
    return Status::ok();
}
+1 −2
Original line number Diff line number Diff line
@@ -106,8 +106,7 @@ public:
    /**
     * Binder call for clients to get metadata across all configs in statsd.
     */
    virtual Status getMetadata(const String16& packageName,
                               vector<uint8_t>* output) override;
    virtual Status getMetadata(vector<uint8_t>* output) override;


    /**
Loading