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

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

Merge "Make onGrantDefaultRoles() run on worker thread."

parents 2dc83f68 72892c4f
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.packageinstaller.role.utils.PackageUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Implementation of {@link RoleControllerService}.
@@ -67,6 +68,15 @@ public class RoleControllerServiceImpl extends RoleControllerService {
        mWorkerThread.quitSafely();
    }

    @Override
    public void onGrantDefaultRoles(@NonNull RoleManagerCallback callback) {
        if (callback == null) {
            Log.e(LOG_TAG, "callback cannot be null");
            return;
        }
        mWorkerHandler.post(() -> grantDefaultRoles(callback));
    }

    @Override
    public void onAddRoleHolder(@NonNull String roleName, @NonNull String packageName,
            @NonNull RoleManagerCallback callback) {
@@ -122,18 +132,14 @@ public class RoleControllerServiceImpl extends RoleControllerService {
        mWorkerHandler.post(() -> clearRoleHolders(roleName, callback));
    }

    @Override
    public void onGrantDefaultRoles(@NonNull RoleManagerCallback callback) {
        if (callback == null) {
            Log.e(LOG_TAG, "callback cannot be null");
            return;
        }

    @WorkerThread
    private void grantDefaultRoles(@NonNull RoleManagerCallback callback) {
        ArrayMap<String, Role> roles = Roles.getRoles(this);
        List<String> roleNames = new ArrayList<>();
        int rolesSize = roles.size();
        for (int i = 0; i < rolesSize; i++) {
            Role role = roles.valueAt(i);

            if (!role.isAvailable(this)) {
                continue;
            }
@@ -189,7 +195,7 @@ public class RoleControllerServiceImpl extends RoleControllerService {
            for (int i = 0; i < currentPackageNamesSize; i++) {
                String currentPackageName = currentPackageNames.get(i);

                if (currentPackageName.equals(packageName)) {
                if (Objects.equals(currentPackageName, packageName)) {
                    Log.i(LOG_TAG, packageName + " already holds " + roleName);
                    added = true;
                    continue;