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

Commit 5b2dfe37 authored by kholoud mohamed's avatar kholoud mohamed
Browse files

Add createRequestInteractAcrossProfilesIntent API.

Creates intent to open the relevant settings page for the
user to enable/disable the INTERACT_ACROSS_PROFILES appop.

BUG: 140728653
BUG: 136249261
Test: atest CrossProfileAppsPermissionHostSideTest

Change-Id: Ia86ae5c8318190374ee73377b81cfade3b0e34c8
parent d55ef0b5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11358,6 +11358,7 @@ package android.content.pm {
  public class CrossProfileApps {
    method public boolean canInteractAcrossProfiles();
    method public boolean canRequestInteractAcrossProfiles();
    method @Nullable public android.content.Intent createRequestInteractAcrossProfilesIntent();
    method @NonNull public android.graphics.drawable.Drawable getProfileSwitchingIconDrawable(@NonNull android.os.UserHandle);
    method @NonNull public CharSequence getProfileSwitchingLabel(@NonNull android.os.UserHandle);
    method @NonNull public java.util.List<android.os.UserHandle> getTargetUserProfiles();
+28 −0
Original line number Diff line number Diff line
@@ -16,15 +16,19 @@
package android.content.pm;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;

import com.android.internal.R;
import com.android.internal.util.UserIcons;
@@ -226,6 +230,30 @@ public class CrossProfileApps {
        }
    }

    /**
     * Returns an {@link Intent} to open the settings page that allows the user to decide whether
     * the calling app can interact across profiles. The current state is given by
     * {@link #canInteractAcrossProfiles()}.
     *
     * <p>Returns {@code null} if {@link #canRequestInteractAcrossProfiles()} is {@code false}.
     *
     * @return an {@link Intent} to open the settings page that allows the user to decide whether
     * the app can interact across profiles
     *
     * @throws SecurityException if {@code mContext.getPackageName()} does not belong to the
     * calling UID.
     */
    public @Nullable Intent createRequestInteractAcrossProfilesIntent() {
        if (!canRequestInteractAcrossProfiles()) {
            return null;
        }
        final Intent settingsIntent = new Intent();
        settingsIntent.setAction(Settings.ACTION_MANAGE_CROSS_PROFILE_ACCESS);
        final Uri packageUri = Uri.parse("package:" + mContext.getPackageName());
        settingsIntent.setData(packageUri);
        return settingsIntent;
    }

    private void verifyCanAccessUser(UserHandle userHandle) {
        if (!getTargetUserProfiles().contains(userHandle)) {
            throw new SecurityException("Not allowed to access " + userHandle);
+15 −0
Original line number Diff line number Diff line
@@ -388,6 +388,21 @@ public final class Settings {
    public static final String ACTION_MANAGE_UNKNOWN_APP_SOURCES =
            "android.settings.MANAGE_UNKNOWN_APP_SOURCES";
    /**
     * Activity Action: Show settings to allow configuration of cross-profile access for apps
     *
     * Input: Optionally, the Intent's data URI can specify the application package name to
     * directly invoke the management GUI specific to the package name. For example
     * "package:com.my.app".
     * <p>
     * Output: Nothing.
     *
     * @hide
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_MANAGE_CROSS_PROFILE_ACCESS =
            "android.settings.MANAGE_CROSS_PROFILE_ACCESS";
    /**
     * Activity Action: Show the "Open by Default" page in a particular application's details page.
     * <p>