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

Commit 7951aba0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Enforce permission on native puller API" into rvc-dev am: 591bb7b1 am: af0f4cbc

Change-Id: Iaea82e4cd91b2829dc16b959c771418bb2f0ebd8
parents c172c53e af0f4cbc
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -193,6 +193,8 @@ interface IStatsd {
    /**
     * Registers a puller callback function that, when invoked, pulls the data
     * for the specified atom tag.
     *
     * Enforces the REGISTER_STATS_PULL_ATOM permission.
     */
    oneway void registerNativePullAtomCallback(int atomTag, long coolDownNs, long timeoutNs,
                           in int[] additiveFields, IPullAtomCallback pullerCallback);
@@ -203,7 +205,9 @@ interface IStatsd {
    oneway void unregisterPullAtomCallback(int uid, int atomTag);

    /**
     * Unregisters any pullAtomCallback for the given atom.
     * Unregisters any pullAtomCallback for the given atom + caller.
     *
     * Enforces the REGISTER_STATS_PULL_ATOM permission.
     */
    oneway void unregisterNativePullAtomCallback(int atomTag);

+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

    <uses-permission android:name="android.permission.DUMP" />
    <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
    <uses-permission android:name="android.permission.REGISTER_STATS_PULL_ATOM" />

    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
                     android:targetPackage="com.android.internal.os.statsd.libstats"
+15 −2
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ namespace statsd {

constexpr const char* kPermissionDump = "android.permission.DUMP";

constexpr const char* kPermissionRegisterPullAtom = "android.permission.REGISTER_STATS_PULL_ATOM";

#define STATS_SERVICE_DIR "/data/misc/stats-service"

// for StatsDataDumpProto
@@ -60,7 +62,7 @@ const int FIELD_ID_REPORTS_LIST = 1;

static Status exception(int32_t code, const std::string& msg) {
    ALOGE("%s (%d)", msg.c_str(), code);
    return ::ndk::ScopedAStatus(AStatus_fromExceptionCodeWithMessage(code, msg.c_str()));
    return Status::fromExceptionCodeWithMessage(code, msg.c_str());
}

static bool checkPermission(const char* permission) {
@@ -1210,7 +1212,12 @@ Status StatsService::registerPullAtomCallback(int32_t uid, int32_t atomTag, int6
Status StatsService::registerNativePullAtomCallback(int32_t atomTag, int64_t coolDownNs,
                                    int64_t timeoutNs, const std::vector<int32_t>& additiveFields,
                                    const shared_ptr<IPullAtomCallback>& pullerCallback) {

    if (!checkPermission(kPermissionRegisterPullAtom)) {
        return exception(
                EX_SECURITY,
                StringPrintf("Uid %d does not have the %s permission when registering atom %d",
                             AIBinder_getCallingUid(), kPermissionRegisterPullAtom, atomTag));
    }
    VLOG("StatsService::registerNativePullAtomCallback called.");
    int32_t uid = AIBinder_getCallingUid();
    mPullerManager->RegisterPullAtomCallback(uid, atomTag, coolDownNs, timeoutNs, additiveFields,
@@ -1226,6 +1233,12 @@ Status StatsService::unregisterPullAtomCallback(int32_t uid, int32_t atomTag) {
}

Status StatsService::unregisterNativePullAtomCallback(int32_t atomTag) {
    if (!checkPermission(kPermissionRegisterPullAtom)) {
        return exception(
                EX_SECURITY,
                StringPrintf("Uid %d does not have the %s permission when unregistering atom %d",
                             AIBinder_getCallingUid(), kPermissionRegisterPullAtom, atomTag));
    }
    VLOG("StatsService::unregisterNativePullAtomCallback called.");
    int32_t uid = AIBinder_getCallingUid();
    mPullerManager->UnregisterPullAtomCallback(uid, atomTag);
+2 −0
Original line number Diff line number Diff line
@@ -190,6 +190,8 @@
    <assign-permission name="android.permission.STATSCOMPANION" uid="statsd" />
    <assign-permission name="android.permission.UPDATE_APP_OPS_STATS" uid="statsd" />

    <assign-permission name="android.permission.REGISTER_STATS_PULL_ATOM" uid="gpu_service" />

    <split-permission name="android.permission.ACCESS_FINE_LOCATION">
        <new-permission name="android.permission.ACCESS_COARSE_LOCATION" />
    </split-permission>