Rename LegacyRoleHoldersResolver to LegacyRoleHolderProvider for system API.

LegacyRoleHolderProvider will need to live in the system server to
allow OEMs to provide their custom logic, meanwhile its various usages
of hidden APIs are also unfit for mainline.

Bug: 158736025
Test: presubmit
Change-Id: I979814a8de91b07176e2b5a6e5d4be914cd3c99d
This commit is contained in:
Hai Zhang
2020-12-14 16:57:43 -08:00
parent 1923524096
commit 7c7dd829ed
3 changed files with 47 additions and 13 deletions

View File

@@ -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;

View File

@@ -0,0 +1,40 @@
/*
* 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);
}

View File

@@ -104,14 +104,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.
@@ -147,10 +140,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);
@@ -276,7 +269,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;
}