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

Commit 9432456a authored by Himanshu Gupta's avatar Himanshu Gupta
Browse files

Swithing to ResolveInfo.userHandle in Sharesheet.

This change will serve as a switch to allow enabling clone profile
related modifications in sharesheet code, which were added in
ag/20508867

MyUserIdProvider is re-added in AbstractMultiProfilePagerAdapter and
ResolverActivity as ag/20821101 seems to use it.

Bug: 240100378

Test: atest ResolverActivityTest
Change-Id: Ied5c304026b41b95df72cfc012040b930f79e223
parent 9085abc4
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -324,6 +324,18 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
        showEmptyState(listAdapter, emptyState, clickListener);
    }

    /**
     * Class to get user id of the current process
     */
    public static class MyUserIdProvider {
        /**
         * @return user id of the current process
         */
        public int getMyUserId() {
            return UserHandle.myUserId();
        }
    }

    /**
     * Utility class to check if there are cross profile intents, it is in a separate class so
     * it could be mocked in tests
+1 −2
Original line number Diff line number Diff line
@@ -197,8 +197,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
                    ri.nonLocalizedLabel = li.getNonLocalizedLabel();
                    ri.icon = li.getIconResource();
                    ri.iconResourceId = ri.icon;
                    // TODO: Uncomment the below line once userHandle is added to ResolveInfo
                    //ri.userHandle = getUserHandle();
                    ri.userHandle = getUserHandle();
                }
                if (userManager.isManagedProfile()) {
                    ri.noResourceId = true;
+7 −1
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.AbstractMultiProfilePagerAdapter.CompositeEmptyStateProvider;
import com.android.internal.app.AbstractMultiProfilePagerAdapter.CrossProfileIntentsChecker;
import com.android.internal.app.AbstractMultiProfilePagerAdapter.EmptyStateProvider;
import com.android.internal.app.AbstractMultiProfilePagerAdapter.MyUserIdProvider;
import com.android.internal.app.AbstractMultiProfilePagerAdapter.OnSwitchOnWorkSelectedListener;
import com.android.internal.app.AbstractMultiProfilePagerAdapter.Profile;
import com.android.internal.app.AbstractMultiProfilePagerAdapter.QuietModeManager;
@@ -505,6 +506,11 @@ public class ResolverActivity extends Activity implements
        return resolverMultiProfilePagerAdapter;
    }

    @VisibleForTesting
    protected MyUserIdProvider createMyUserIdProvider() {
        return new MyUserIdProvider();
    }

    @VisibleForTesting
    protected CrossProfileIntentsChecker createCrossProfileIntentsChecker() {
        return new CrossProfileIntentsChecker(getContentResolver());
@@ -2526,6 +2532,6 @@ public class ResolverActivity extends Activity implements
     */
    public static UserHandle getResolveInfoUserHandle(ResolveInfo resolveInfo,
            UserHandle predictedHandle) {
        return predictedHandle;
        return resolveInfo.userHandle;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -440,6 +440,7 @@ public class ResolverListAdapter extends BaseAdapter {
                        ri.nonLocalizedLabel = li.getNonLocalizedLabel();
                        ri.icon = li.getIconResource();
                        ri.iconResourceId = ri.icon;
                        ri.userHandle = getUserHandle();
                    }
                    if (userManager.isManagedProfile()) {
                        ri.noResourceId = true;
+4 −4
Original line number Diff line number Diff line
@@ -174,10 +174,10 @@ public class ResolverListController {
        final int intoCount = into.size();
        for (int i = 0; i < fromCount; i++) {
            final ResolveInfo newInfo = from.get(i);
            // TODO: Once resolveInfo.userHandle is available, add the logic to drop any ResolveInfo
            //  with userHandle as null, with a warning logged. This is necessary as sharesheet is
            //  going to use userHandle to determine icon badging and starting the activity in
            //  correct userSpace.
            if (newInfo.userHandle == null) {
                Log.w(TAG, "Skipping ResolveInfo with no userHandle: " + newInfo);
                continue;
            }
            boolean found = false;
            // Only loop to the end of into as it was before we started; no dupes in from.
            for (int j = 0; j < intoCount; j++) {
Loading