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

Commit 94eafe74 authored by Jeffrey Huang's avatar Jeffrey Huang
Browse files

Update Add/Remove Configuration

Test: GTS Tests
Bug: 146383400
Change-Id: Ibcd6802468fa3be3ffde4357b37060711deff9b3
parent 04f948b4
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -107,4 +107,22 @@ interface IStatsManagerService {
     * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
     */
    byte[] getData(in long key, in String packageName);

    /**
     * Sets a configuration with the specified config id and subscribes to updates for this
     * configuration id. Broadcasts will be sent if this configuration needs to be collected.
     * The configuration must be a wire-encoded StatsdConfig. The receiver for this data is
     * registered in a separate function.
     *
     * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
     */
    void addConfiguration(in long configId, in byte[] config, in String packageName);

    /**
     * Removes the configuration with the matching config id. No-op if this config id does not
     * exist.
     *
     * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
     */
    void removeConfiguration(in long configId, in String packageName);
}
 No newline at end of file
+4 −4
Original line number Diff line number Diff line
@@ -99,14 +99,14 @@ interface IStatsd {
    byte[] getMetadata();

    /**
     * Sets a configuration with the specified config key and subscribes to updates for this
     * Sets a configuration with the specified config id and subscribes to updates for this
     * configuration key. Broadcasts will be sent if this configuration needs to be collected.
     * The configuration must be a wire-encoded StatsdConfig. The receiver for this data is
     * registered in a separate function.
     *
     * Requires Manifest.permission.DUMP.
     */
    void addConfiguration(in long configKey, in byte[] config, in String packageName);
    void addConfiguration(in long configId, in byte[] config, in int callingUid);

    /**
     * Registers the given pending intent for this config key. This intent is invoked when the
@@ -143,12 +143,12 @@ interface IStatsd {
    void removeActiveConfigsChangedOperation(int callingUid);

    /**
     * Removes the configuration with the matching config key. No-op if this config key does not
     * Removes the configuration with the matching config id. No-op if this config id does not
     * exist.
     *
     * Requires Manifest.permission.DUMP.
     */
    void removeConfiguration(in long configKey, in String packageName);
    void removeConfiguration(in long configId, in int callingUid);

    /**
     * Set the PendingIntentRef to be used when broadcasting subscriber
+42 −0
Original line number Diff line number Diff line
@@ -301,6 +301,48 @@ public class StatsManagerService extends IStatsManagerService.Stub {
        throw new IllegalStateException("Failed to connect to statsd to getData");
    }

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

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

    void setStatsCompanionService(StatsCompanionService statsCompanionService) {
        mStatsCompanionService = statsCompanionService;
    }
+6 −8
Original line number Diff line number Diff line
@@ -1155,11 +1155,10 @@ Status StatsService::getMetadata(vector<uint8_t>* output) {
}

Status StatsService::addConfiguration(int64_t key, const vector <uint8_t>& config,
                                      const String16& packageName) {
    ENFORCE_DUMP_AND_USAGE_STATS(packageName);
                                      const int32_t callingUid) {
    ENFORCE_UID(AID_SYSTEM);

    IPCThreadState* ipc = IPCThreadState::self();
    if (addConfigurationChecked(ipc->getCallingUid(), key, config)) {
    if (addConfigurationChecked(callingUid, key, config)) {
        return Status::ok();
    } else {
        ALOGE("Could not parse malformatted StatsdConfig");
@@ -1224,11 +1223,10 @@ Status StatsService::removeActiveConfigsChangedOperation(const int32_t callingUi
    return Status::ok();
}

Status StatsService::removeConfiguration(int64_t key, const String16& packageName) {
    ENFORCE_DUMP_AND_USAGE_STATS(packageName);
Status StatsService::removeConfiguration(int64_t key, const int32_t callingUid) {
    ENFORCE_UID(AID_SYSTEM);

    IPCThreadState* ipc = IPCThreadState::self();
    ConfigKey configKey(ipc->getCallingUid(), key);
    ConfigKey configKey(callingUid, key);
    mConfigManager->RemoveConfig(configKey);
    SubscriberReporter::getInstance().removeConfig(configKey);
    return Status::ok();
+2 −2
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ public:
     */
    virtual Status addConfiguration(int64_t key,
                                    const vector<uint8_t>& config,
                                    const String16& packageName) override;
                                    const int32_t callingUid) override;

    /**
     * Binder call to let clients register the data fetch operation for a configuration.
@@ -145,7 +145,7 @@ public:
     * Binder call to allow clients to remove the specified configuration.
     */
    virtual Status removeConfiguration(int64_t key,
                                       const String16& packageName) override;
                                       const int32_t callingUid) override;

    /**
     * Binder call to associate the given config's subscriberId with the given pendingIntentRef.
Loading