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

Commit 70b42ae8 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Pull all current role holders into statsd

Create a new atom RoleHolder that maps a uid -> role and add the
mappings that currently exist in RoleManagerService

Test: - ./out/host/linux-x86/bin/statsd_testdrive 10049
      - adb shell cmd stats pull-source 10049
Bug: 123594188
Change-Id: Ib0fa60b07a95c06a219f3e3b37d51f59b624a017
parent 48518f43
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -269,6 +269,7 @@ message Atom {
        DebugElapsedClock debug_elapsed_clock = 10046;
        DebugFailingElapsedClock debug_failing_elapsed_clock = 10047;
        NumBiometricsEnrolled num_faces_enrolled = 10048;
        RoleHolder role_holder = 10049;
    }

    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -3420,6 +3421,20 @@ message NumBiometricsEnrolled {
    optional int32 num_enrolled = 2;
}

/**
 * A mapping of role holder -> role
 */
message RoleHolder {
    // uid of the role holder
    optional int32 uid = 1 [(is_uid) = true];

    // package name of the role holder
    optional string package_name = 2;

    // the role held
    optional string role = 3;
}

message AggStats {
    optional int64 min = 1;

+3 −0
Original line number Diff line number Diff line
@@ -220,6 +220,9 @@ const std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
        // BuildInformation.
        {android::util::BUILD_INFORMATION,
         {.puller = new StatsCompanionServicePuller(android::util::BUILD_INFORMATION)}},
        // RoleHolder.
        {android::util::ROLE_HOLDER,
         {.puller = new StatsCompanionServicePuller(android::util::ROLE_HOLDER)}},
};

StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) {
+29 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.os.UserManagerInternal;
import android.service.sms.FinancialSmsService;
import android.telephony.IFinancialSmsCallback;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.PackageUtils;
import android.util.Slog;
@@ -145,6 +146,9 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
        mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
        mAppOpsManager = context.getSystemService(AppOpsManager.class);

        LocalServices.addService(RoleManagerServiceInternal.class,
                new RoleManagerServiceInternalImpl());

        registerUserRemovedReceiver();
    }

@@ -381,6 +385,19 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
        }
    }

    /**
     * Get all roles and packages hold them.
     *
     * @param user The user to query to roles for
     *
     * @return The roles and their holders
     */
    @NonNull
    private ArrayMap<String, ArraySet<String>> getRoleHoldersAsUser(@NonNull UserHandle user) {
        RoleUserState userState = getOrCreateUserState(user.getIdentifier());
        return userState.getRoleHolders();
    }

    private class Stub extends IRoleManager.Stub {

        @Override
@@ -675,4 +692,16 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
            }
        }
    }

    /**
     * Entry point for internal calls into role manager
     */
    private final class RoleManagerServiceInternalImpl extends RoleManagerServiceInternal {

        @NonNull
        @Override
        public ArrayMap<String, ArraySet<String>> getRoleHoldersAsUser(@NonNull UserHandle user) {
            return RoleManagerService.this.getRoleHoldersAsUser(user);
        }
    }
}
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.role;

import android.annotation.NonNull;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;

/**
 * Internal calls into {@link RoleManagerService}
 */
public abstract class RoleManagerServiceInternal {
    /**
     * Get all roles and packages hold them.
     *
     * @param user The user to query to roles for
     *
     * @return The roles and their holders
     */
    @NonNull
    public abstract ArrayMap<String, ArraySet<String>> getRoleHoldersAsUser(
            @NonNull UserHandle user);
}
+19 −12
Original line number Diff line number Diff line
@@ -376,7 +376,7 @@ public class RoleUserState {

            version = mVersion;
            packagesHash = mPackagesHash;
            roles = snapshotRolesLocked();
            roles = getRoleHolders();
        }

        AtomicFile atomicFile = new AtomicFile(getFile(mUserId), "roles-" + mUserId);
@@ -541,7 +541,7 @@ public class RoleUserState {

            version = mVersion;
            packagesHash = mPackagesHash;
            roles = snapshotRolesLocked();
            roles = getRoleHolders();
        }

        long fieldToken = dumpOutputStream.start(fieldName, fieldId);
@@ -570,8 +570,14 @@ public class RoleUserState {
        dumpOutputStream.end(fieldToken);
    }

    @GuardedBy("mLock")
    private ArrayMap<String, ArraySet<String>> snapshotRolesLocked() {
    /**
     * Get the roles and their holders.
     *
     * @return A copy of the roles and their holders
     */
    @NonNull
    public ArrayMap<String, ArraySet<String>> getRoleHolders() {
        synchronized (mLock) {
            ArrayMap<String, ArraySet<String>> roles = new ArrayMap<>();
            for (int i = 0, size = CollectionUtils.size(mRoles); i < size; ++i) {
                String roleName = mRoles.keyAt(i);
@@ -582,6 +588,7 @@ public class RoleUserState {
            }
            return roles;
        }
    }

    /**
     * Destroy this user state and delete the corresponding file. Any pending writes to the file
Loading