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

Commit 4ab95119 authored by Eugene Susla's avatar Eugene Susla
Browse files

Mirgate default SMS app handling to RoleManager

This includes laying down some groundwork to make the remaining migrations
more straightforward

Bug: 110557011
Test: atest RoleManagerTest && atest SmsManagerTest
Change-Id: Ie96abd73751d10f521756c9dcdab2a5710ca2045
parent c54ffd28
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -50,4 +50,6 @@ interface IRoleManager {
    boolean removeRoleHolderFromController(in String roleName, in String packageName);

    List<String> getHeldRolesFromController(in String packageName);

    String getDefaultSmsPackage(int userId);
}
+17 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app.role;
import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
@@ -542,7 +543,6 @@ public final class RoleManager {
        }
    }


    /**
     * Returns the list of all roles that the given package is currently holding
     *
@@ -563,6 +563,22 @@ public final class RoleManager {
        }
    }

    /**
     * Allows getting the role holder for {@link #ROLE_SMS} without
     * {@link Manifest.permission#OBSERVE_ROLE_HOLDERS}, as required by
     * {@link android.provider.Telephony.Sms#getDefaultSmsPackage(Context)}
     *
     * @hide
     */
    @Nullable
    public String getDefaultSmsPackage(@UserIdInt int userId) {
        try {
            return mService.getDefaultSmsPackage(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    private static class RoleManagerCallbackDelegate extends IRoleManagerCallback.Stub {

        @NonNull
+19 −4
Original line number Diff line number Diff line
@@ -29,8 +29,11 @@ import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;

import android.annotation.UnsupportedAppUsage;
import android.os.BaseBundle;
import android.os.Debug;
import android.os.PersistableBundle;
import android.util.ArraySet;
import android.util.DebugUtils;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
@@ -43,6 +46,9 @@ import java.util.Objects;
 * @hide
 */
public class PackageUserState {
    private static final boolean DEBUG = false;
    private static final String LOG_TAG = "PackageUserState";

    public long ceDataInode;
    public boolean installed;
    public boolean stopped;
@@ -132,12 +138,12 @@ public class PackageUserState {
        final boolean isSystemApp = componentInfo.applicationInfo.isSystemApp();
        final boolean matchUninstalled = (flags & PackageManager.MATCH_KNOWN_PACKAGES) != 0;
        if (!isAvailable(flags)
                && !(isSystemApp && matchUninstalled)) return false;
        if (!isEnabled(componentInfo, flags)) return false;
                && !(isSystemApp && matchUninstalled)) return reportIfDebug(false, flags);
        if (!isEnabled(componentInfo, flags)) return reportIfDebug(false, flags);

        if ((flags & MATCH_SYSTEM_ONLY) != 0) {
            if (!isSystemApp) {
                return false;
                return reportIfDebug(false, flags);
            }
        }

@@ -145,7 +151,16 @@ public class PackageUserState {
                && !componentInfo.directBootAware;
        final boolean matchesAware = ((flags & MATCH_DIRECT_BOOT_AWARE) != 0)
                && componentInfo.directBootAware;
        return matchesUnaware || matchesAware;
        return reportIfDebug(matchesUnaware || matchesAware, flags);
    }

    private boolean reportIfDebug(boolean result, int flags) {
        if (DEBUG && !result) {
            Slog.i(LOG_TAG, "No match!; flags: "
                    + DebugUtils.flagsToString(PackageManager.class, "MATCH_", flags) + " "
                    + Debug.getCaller());
        }
        return result;
    }

    /**
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.util;

import android.annotation.UnsupportedAppUsage;
import android.os.Build;

import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -250,7 +251,7 @@ public class DebugUtils {
                    if (value == 0 && flagsWasZero) {
                        return constNameWithoutPrefix(prefix, field);
                    }
                    if ((flags & value) != 0) {
                    if ((flags & value) == value) {
                        flags &= ~value;
                        res.append(constNameWithoutPrefix(prefix, field)).append('|');
                    }
+14 −0
Original line number Diff line number Diff line
@@ -330,4 +330,18 @@ public class CollectionUtils {
    public static @NonNull <T> List<T> defeatNullable(@Nullable List<T> val) {
        return (val != null) ? val : Collections.emptyList();
    }

    /**
     * @return the first element if not empty/null, null otherwise
     */
    public static @Nullable <T> T firstOrNull(@Nullable List<T> cur) {
        return isEmpty(cur) ? null : cur.get(0);
    }

    /**
     * @return list of single given element if it's not null, empty list otherwise
     */
    public static @NonNull <T> List<T> singletonOrEmpty(@Nullable T item) {
        return item == null ? Collections.emptyList() : Collections.singletonList(item);
    }
}
Loading