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

Commit c6abcbab authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Set calling user as intent extra to indicate intent resolver edge case"...

Merge "Set calling user as intent extra to indicate intent resolver edge case" into rvc-dev am: c235831a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11689273

Change-Id: I84603da867fac816d45509c597a09d245c637706
parents 7b69285f c235831a
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.app;


import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;


import static com.android.internal.app.ResolverActivity.EXTRA_CALLING_USER;
import static com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE;
import static com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE;


import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -246,6 +247,7 @@ public class IntentForwarderActivity extends Activity {
        int selectedProfile = findSelectedProfile(className);
        int selectedProfile = findSelectedProfile(className);
        sanitizeIntent(intentReceived);
        sanitizeIntent(intentReceived);
        intentReceived.putExtra(EXTRA_SELECTED_PROFILE, selectedProfile);
        intentReceived.putExtra(EXTRA_SELECTED_PROFILE, selectedProfile);
        intentReceived.putExtra(EXTRA_CALLING_USER, UserHandle.of(callingUserId));
        startActivityAsCaller(intentReceived, null, null, false, userId);
        startActivityAsCaller(intentReceived, null, null, false, userId);
        finish();
        finish();
    }
    }
+20 −21
Original line number Original line Diff line number Diff line
@@ -184,6 +184,18 @@ public class ResolverActivity extends Activity implements
    static final String EXTRA_SELECTED_PROFILE =
    static final String EXTRA_SELECTED_PROFILE =
            "com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE";
            "com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE";


    /**
     * {@link UserHandle} extra to indicate the user of the user that the starting intent
     * originated from.
     * <p>This is not necessarily the same as {@link #getUserId()} or {@link UserHandle#myUserId()},
     * as there are edge cases when the intent resolver is launched in the other profile.
     * For example, when we have 0 resolved apps in current profile and multiple resolved
     * apps in the other profile, opening a link from the current profile launches the intent
     * resolver in the other one. b/148536209 for more info.
     */
    static final String EXTRA_CALLING_USER =
            "com.android.internal.app.ResolverActivity.EXTRA_CALLING_USER";

    static final int PROFILE_PERSONAL = AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL;
    static final int PROFILE_PERSONAL = AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL;
    static final int PROFILE_WORK = AbstractMultiProfilePagerAdapter.PROFILE_WORK;
    static final int PROFILE_WORK = AbstractMultiProfilePagerAdapter.PROFILE_WORK;


@@ -470,18 +482,21 @@ public class ResolverActivity extends Activity implements
        // the intent resolver is started in the other profile. Since this is the only case when
        // the intent resolver is started in the other profile. Since this is the only case when
        // this happens, we check for it here and set the current profile's tab.
        // this happens, we check for it here and set the current profile's tab.
        int selectedProfile = getCurrentProfile();
        int selectedProfile = getCurrentProfile();
        UserHandle intentUser = UserHandle.of(getLaunchingUserId());
        UserHandle intentUser = getIntent().hasExtra(EXTRA_CALLING_USER)
                ? getIntent().getParcelableExtra(EXTRA_CALLING_USER)
                : getUser();
        if (!getUser().equals(intentUser)) {
        if (!getUser().equals(intentUser)) {
            if (getPersonalProfileUserHandle().equals(intentUser)) {
            if (getPersonalProfileUserHandle().equals(intentUser)) {
                selectedProfile = PROFILE_PERSONAL;
                selectedProfile = PROFILE_PERSONAL;
            } else if (getWorkProfileUserHandle().equals(intentUser)) {
            } else if (getWorkProfileUserHandle().equals(intentUser)) {
                selectedProfile = PROFILE_WORK;
                selectedProfile = PROFILE_WORK;
            }
            }
        }
        } else {
            int selectedProfileExtra = getSelectedProfileExtra();
            int selectedProfileExtra = getSelectedProfileExtra();
            if (selectedProfileExtra != -1) {
            if (selectedProfileExtra != -1) {
                selectedProfile = selectedProfileExtra;
                selectedProfile = selectedProfileExtra;
            }
            }
        }
        // We only show the default app for the profile of the current user. The filterLastUsed
        // We only show the default app for the profile of the current user. The filterLastUsed
        // flag determines whether to show a default app and that app is not shown in the
        // flag determines whether to show a default app and that app is not shown in the
        // resolver list. So filterLastUsed should be false for the other profile.
        // resolver list. So filterLastUsed should be false for the other profile.
@@ -535,22 +550,6 @@ public class ResolverActivity extends Activity implements
        return selectedProfile;
        return selectedProfile;
    }
    }


    /**
     * Returns the user id of the user that the starting intent originated from.
     * <p>This is not necessarily equal to {@link #getUserId()} or {@link UserHandle#myUserId()},
     * as there are edge cases when the intent resolver is launched in the other profile.
     * For example, when we have 0 resolved apps in current profile and multiple resolved apps
     * in the other profile, opening a link from the current profile launches the intent resolver
     * in the other one. b/148536209 for more info.
     */
    private int getLaunchingUserId() {
        int contentUserHint = getIntent().getContentUserHint();
        if (contentUserHint == UserHandle.USER_CURRENT) {
            return UserHandle.myUserId();
        }
        return contentUserHint;
    }

    protected @Profile int getCurrentProfile() {
    protected @Profile int getCurrentProfile() {
        return (UserHandle.myUserId() == UserHandle.USER_SYSTEM ? PROFILE_PERSONAL : PROFILE_WORK);
        return (UserHandle.myUserId() == UserHandle.USER_SYSTEM ? PROFILE_PERSONAL : PROFILE_WORK);
    }
    }