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

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

Merge changes I42839dac,I84b9519a

* changes:
  Move CheckPermissionDelegate API into PermissionManagerServiceInternal.
  Move default app related methods to role manager.
parents 80b8e0af 1ca9409d
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.annotation.Nullable;
import android.annotation.StringRes;
import android.annotation.UserIdInt;
import android.annotation.XmlRes;
import android.app.role.RoleManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -2306,20 +2307,14 @@ public class ApplicationPackageManager extends PackageManager {

    @Override
    public String getDefaultBrowserPackageNameAsUser(int userId) {
        try {
            return mPermissionManager.getDefaultBrowser(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        RoleManager roleManager = mContext.getSystemService(RoleManager.class);
        return roleManager.getBrowserRoleHolder(userId);
    }

    @Override
    public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
        try {
            return mPermissionManager.setDefaultBrowser(packageName, userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        RoleManager roleManager = mContext.getSystemService(RoleManager.class);
        return roleManager.setBrowserRoleHolder(packageName, userId);
    }

    @Override
+5 −1
Original line number Diff line number Diff line
@@ -53,5 +53,9 @@ interface IRoleManager {

    List<String> getHeldRolesFromController(in String packageName);

    String getDefaultSmsPackage(int userId);
    String getBrowserRoleHolder(int userId);

    boolean setBrowserRoleHolder(String packageName, int userId);

    String getSmsRoleHolder(int userId);
}
+50 −6
Original line number Diff line number Diff line
@@ -613,12 +613,56 @@ 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)}
     * Get the role holder of {@link #ROLE_BROWSER} without requiring
     * {@link Manifest.permission#OBSERVE_ROLE_HOLDERS}, as in
     * {@link android.content.pm.PackageManager#getDefaultBrowserPackageNameAsUser(int)}
     *
     * @param userId the user ID
     * @return the package name of the default browser, or {@code null} if none
     *
     * @hide
     */
    @Nullable
    //@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public String getBrowserRoleHolder(@UserIdInt int userId) {
        try {
            return mService.getBrowserRoleHolder(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Set the role holder of {@link #ROLE_BROWSER} requiring
     * {@link Manifest.permission.SET_PREFERRED_APPLICATIONS} instead of
     * {@link Manifest.permission#MANAGE_ROLE_HOLDERS}, as in
     * {@link android.content.pm.PackageManager#setDefaultBrowserPackageNameAsUser(String, int)}
     *
     * @param packageName the package name of the default browser, or {@code null} if none
     * @param userId the user ID
     * @return whether the default browser was set successfully
     *
     * @hide
     */
    @Nullable
    @RequiresPermission(Manifest.permission.SET_PREFERRED_APPLICATIONS)
    //@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public boolean setBrowserRoleHolder(@Nullable String packageName, @UserIdInt int userId) {
        try {
            return mService.setBrowserRoleHolder(packageName, userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Allows getting the role holder for {@link #ROLE_SMS} without requiring
     * {@link Manifest.permission#OBSERVE_ROLE_HOLDERS}, as in
     * {@link android.provider.Telephony.Sms#getDefaultSmsPackage(Context)}.
     *
     * @param userId the user ID to get the default SMS package for
     * @return the package name of the default SMS app, or {@code null} if none
     *
     * @param userId The user ID to get the default SMS package for.
     * @return the package name of the default SMS app, or {@code null} if not configured.
     * @hide
     */
    @Nullable
@@ -626,7 +670,7 @@ public final class RoleManager {
    @TestApi
    public String getSmsRoleHolder(@UserIdInt int userId) {
        try {
            return mService.getDefaultSmsPackage(userId);
            return mService.getSmsRoleHolder(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+0 −4
Original line number Diff line number Diff line
@@ -73,10 +73,6 @@ interface IPermissionManager {

    void resetRuntimePermissions();

    boolean setDefaultBrowser(String packageName, int userId);

    String getDefaultBrowser(int userId);

    void grantDefaultPermissionsToEnabledCarrierApps(in String[] packageNames, int userId);

    void grantDefaultPermissionsToEnabledImsServices(in String[] packageNames, int userId);
+0 −31
Original line number Diff line number Diff line
@@ -21,10 +21,6 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.os.UserHandle;

import com.android.internal.util.function.TriFunction;

import java.util.function.BiFunction;

/**
 * Internal interfaces to be used by other components within the system server.
 *
@@ -50,33 +46,6 @@ public abstract class PermissionManagerInternal {
                @UserIdInt int userId);
    }

    /** Interface to override permission checks via composition */
    public interface CheckPermissionDelegate {
        /**
         * Checks whether the given package has been granted the specified permission.
         *
         * @return If the package has the permission, PERMISSION_GRANTED is
         * returned.  If it does not have the permission, PERMISSION_DENIED
         * is returned.
         *
         * @see android.content.pm.PackageManager#checkPermission(String, String)
         */
        int checkPermission(String permName, String pkgName, int userId,
                TriFunction<String, String, Integer, Integer> superImpl);

        /**
        /**
         * Checks whether the given uid has been granted the specified permission.
         *
         * @return If the package has the permission, PERMISSION_GRANTED is
         * returned.  If it does not have the permission, PERMISSION_DENIED
         * is returned.
         *
         */
        int checkUidPermission(String permName, int uid,
                BiFunction<String, Integer, Integer> superImpl);
    }

    /**
     * Get the state of the runtime permissions as xml file.
     *
Loading