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

Commit 7c72b864 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Rename LegacyRoleHoldersResolver to LegacyRoleHolderProvider for system API."

parents 39a6d69a 7c7dd829
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.internal.R;
import com.android.internal.telephony.SmsApplication;
import com.android.internal.util.CollectionUtils;
import com.android.server.LocalServices;
import com.android.server.role.LegacyRoleHolderProvider;
import com.android.server.role.RoleManagerService;

import java.util.Collections;
@@ -48,7 +49,7 @@ import java.util.Objects;
 *
 * @see RoleManagerService#migrateRoleIfNecessary
 */
public class LegacyRoleResolutionPolicy implements RoleManagerService.RoleHoldersResolver {
public class LegacyRoleResolutionPolicy implements LegacyRoleHolderProvider {

    private static final boolean DEBUG = false;
    private static final String LOG_TAG = "LegacyRoleResolutionPol";
@@ -62,7 +63,7 @@ public class LegacyRoleResolutionPolicy implements RoleManagerService.RoleHolder

    @NonNull
    @Override
    public List<String> getRoleHolders(@NonNull String roleName, @UserIdInt int userId) {
    public List<String> getLegacyRoleHolders(@NonNull String roleName, @UserIdInt int userId) {
        switch (roleName) {
            case RoleManager.ROLE_ASSISTANT: {
                String packageName;
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.annotation.UserIdInt;

import java.util.List;

/**
 * A provider for migrating legacy "role"s to their actual role implementation.
 */
//@SystemApi(client = SystemApi.Client.SYSTEM_SERVER)
public interface LegacyRoleHolderProvider {
    /**
     * Get the list of holders of a legacy "role" before its actual role is introduced.
     * <p>
     * This method will only be called for the first time a role is made available in the platform.
     *
     * @param roleName the name of the role
     * @param userId the user ID
     * @return a list of holders for the given role
     */
    @NonNull
    List<String> getLegacyRoleHolders(@NonNull String roleName, @UserIdInt int userId);
}
+4 −11
Original line number Diff line number Diff line
@@ -103,14 +103,7 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
    private final Object mLock = new Object();

    @NonNull
    private final RoleHoldersResolver mLegacyRoleResolver;

    /** @see #getRoleHolders(String, int) */
    public interface RoleHoldersResolver {
        /** @return a list of packages that hold a given role for a given user */
        @NonNull
        List<String> getRoleHolders(@NonNull String roleName, @UserIdInt int userId);
    }
    private final LegacyRoleHolderProvider mLegacyRoleHolderProvider;

    /**
     * Maps user id to its state.
@@ -146,10 +139,10 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
            new SparseArray<>();

    public RoleManagerService(@NonNull Context context,
            @NonNull RoleHoldersResolver legacyRoleResolver) {
            @NonNull LegacyRoleHolderProvider legacyRoleHolderProvider) {
        super(context);

        mLegacyRoleResolver = legacyRoleResolver;
        mLegacyRoleHolderProvider = legacyRoleHolderProvider;

        RoleControllerManager.initializeRemoteServiceComponentName(context);

@@ -275,7 +268,7 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
        // Any role for which we have a record are already migrated
        RoleUserState userState = getOrCreateUserState(userId);
        if (!userState.isRoleAvailable(role)) {
            List<String> roleHolders = mLegacyRoleResolver.getRoleHolders(role, userId);
            List<String> roleHolders = mLegacyRoleHolderProvider.getLegacyRoleHolders(role, userId);
            if (roleHolders.isEmpty()) {
                return;
            }