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

Commit 297308fb authored by Hai Zhang's avatar Hai Zhang Committed by Android (Google) Code Review
Browse files

Merge "Prepare role code for modularization."

parents 6a3f0503 0de31fe1
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.os.Looper;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@@ -40,8 +38,7 @@ import java.lang.annotation.Target;
 * </code>
 * </pre>
 *
 * @memberDoc This method must be called from the
 *            {@linkplain Looper#getMainLooper() main thread} of your app.
 * @memberDoc This method must be called from the main thread of your app.
 * @hide
 */
@Retention(SOURCE)
+2 −9
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import android.app.contentsuggestions.IContentSuggestionsManager;
import android.app.job.JobSchedulerFrameworkInitializer;
import android.app.people.PeopleManager;
import android.app.prediction.AppPredictionManager;
import android.app.role.RoleManager;
import android.app.role.RoleFrameworkInitializer;
import android.app.search.SearchUiManager;
import android.app.slice.SliceManager;
import android.app.time.TimeManager;
@@ -1320,14 +1320,6 @@ public final class SystemServiceRegistry {
                                ctx.getMainThreadHandler());
                    }});

        registerService(Context.ROLE_SERVICE, RoleManager.class,
                new CachedServiceFetcher<RoleManager>() {
                    @Override
                    public RoleManager createService(ContextImpl ctx)
                            throws ServiceNotFoundException {
                        return new RoleManager(ctx.getOuterContext());
                    }});

        registerService(Context.DYNAMIC_SYSTEM_SERVICE, DynamicSystemManager.class,
                new CachedServiceFetcher<DynamicSystemManager>() {
                    @Override
@@ -1423,6 +1415,7 @@ public final class SystemServiceRegistry {
            RollbackManagerFrameworkInitializer.initialize();
            MediaFrameworkPlatformInitializer.registerServiceWrappers();
            MediaFrameworkInitializer.registerServiceWrappers();
            RoleFrameworkInitializer.registerServiceWrappers();
        } finally {
            // If any of the above code throws, we're in a pretty bad shape and the process
            // will likely crash, but we'll reset it just in case there's an exception handler...
+7 −8
Original line number Diff line number Diff line
@@ -20,15 +20,15 @@ import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.app.ActivityThread;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteCallback;
import android.util.Log;
import android.util.SparseArray;
@@ -95,11 +95,10 @@ public class RoleControllerManager {
    private RoleControllerManager(@NonNull ComponentName remoteServiceComponentName,
            @NonNull Handler handler, @NonNull Context context) {
        synchronized (sRemoteServicesLock) {
            int userId = context.getUserId();
            int userId = context.getUser().getIdentifier();
            ServiceConnector<IRoleController> remoteService = sRemoteServices.get(userId);
            if (remoteService == null) {
                remoteService = new ServiceConnector.Impl<IRoleController>(
                        ActivityThread.currentApplication(),
                remoteService = new ServiceConnector.Impl<IRoleController>(context,
                        new Intent(RoleControllerService.SERVICE_INTERFACE)
                                .setComponent(remoteServiceComponentName),
                        0 /* bindingFlags */, userId, IRoleController.Stub::asInterface) {
@@ -119,7 +118,7 @@ public class RoleControllerManager {
     * @hide
     */
    public RoleControllerManager(@NonNull Context context) {
        this(getRemoteServiceComponentName(context), context.getMainThreadHandler(), context);
        this(getRemoteServiceComponentName(context), new Handler(Looper.getMainLooper()), context);
    }

    @NonNull
@@ -127,8 +126,8 @@ public class RoleControllerManager {
        Intent intent = new Intent(RoleControllerService.SERVICE_INTERFACE);
        PackageManager packageManager = context.getPackageManager();
        intent.setPackage(packageManager.getPermissionControllerPackageName());
        ResolveInfo resolveInfo = packageManager.resolveService(intent, 0);
        return resolveInfo.getComponentInfo().getComponentName();
        ServiceInfo serviceInfo = packageManager.resolveService(intent, 0).serviceInfo;
        return new ComponentName(serviceInfo.packageName, serviceInfo.name);
    }

    /**
+8 −13
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.os.RemoteCallback;
import android.os.UserHandle;

import com.android.internal.util.Preconditions;
import com.android.internal.util.function.pooled.PooledLambda;

import java.util.Objects;
import java.util.concurrent.Executor;
@@ -85,9 +84,7 @@ public abstract class RoleControllerService extends Service {

                Objects.requireNonNull(callback, "callback cannot be null");

                mWorkerHandler.sendMessage(PooledLambda.obtainMessage(
                        RoleControllerService::grantDefaultRoles, RoleControllerService.this,
                        callback));
                mWorkerHandler.post(() -> RoleControllerService.this.grantDefaultRoles(callback));
            }

            @Override
@@ -100,9 +97,8 @@ public abstract class RoleControllerService extends Service {
                        "packageName cannot be null or empty");
                Objects.requireNonNull(callback, "callback cannot be null");

                mWorkerHandler.sendMessage(PooledLambda.obtainMessage(
                        RoleControllerService::onAddRoleHolder, RoleControllerService.this,
                        roleName, packageName, flags, callback));
                mWorkerHandler.post(() -> RoleControllerService.this.onAddRoleHolder(roleName,
                        packageName, flags, callback));
            }

            @Override
@@ -115,9 +111,8 @@ public abstract class RoleControllerService extends Service {
                        "packageName cannot be null or empty");
                Objects.requireNonNull(callback, "callback cannot be null");

                mWorkerHandler.sendMessage(PooledLambda.obtainMessage(
                        RoleControllerService::onRemoveRoleHolder, RoleControllerService.this,
                        roleName, packageName, flags, callback));
                mWorkerHandler.post(() -> RoleControllerService.this.onRemoveRoleHolder(roleName,
                        packageName, flags, callback));
            }

            @Override
@@ -127,9 +122,8 @@ public abstract class RoleControllerService extends Service {
                Preconditions.checkStringNotEmpty(roleName, "roleName cannot be null or empty");
                Objects.requireNonNull(callback, "callback cannot be null");

                mWorkerHandler.sendMessage(PooledLambda.obtainMessage(
                        RoleControllerService::onClearRoleHolders, RoleControllerService.this,
                        roleName, flags, callback));
                mWorkerHandler.post(() -> RoleControllerService.this.onClearRoleHolders(roleName,
                        flags, callback));
            }

            private void enforceCallerSystemUid(@NonNull String methodName) {
@@ -274,6 +268,7 @@ public abstract class RoleControllerService extends Service {
     *
     * @deprecated Implement {@link #onIsApplicationVisibleForRole(String, String)} instead.
     */
    @Deprecated
    public abstract boolean onIsApplicationQualifiedForRole(@NonNull String roleName,
            @NonNull String packageName);

+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 android.app.role;

import android.app.SystemServiceRegistry;
import android.content.Context;

/**
 * Class holding initialization code for role in the permission module.
 *
 * @hide
 */
//@SystemApi
public class RoleFrameworkInitializer {
    private RoleFrameworkInitializer() {}

    /**
     * Called by {@link SystemServiceRegistry}'s static initializer and registers
     * {@link RoleManager} to {@link Context}, so that {@link Context#getSystemService} can return
     * it.
     *
     * <p>If this is called from other places, it throws a {@link IllegalStateException).
     */
    public static void registerServiceWrappers() {
        SystemServiceRegistry.registerContextAwareService(Context.ROLE_SERVICE, RoleManager.class,
                (context, serviceBinder) -> new RoleManager(context,
                        IRoleManager.Stub.asInterface(serviceBinder)));
    }
}
Loading