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

Commit 703d1c43 authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Added primaryUserOnly attribute for activities

In addition to receivers, primaryUserOnly is now supported for activities.

In queryIntentActivities method, activities with primaryUserOnly flag set will
be filtered out, when current user is not the owner.

Change-Id: I0b7168b8c96749cd6d23b8c95d5624589f5f2d86
parent cd4c8525
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -3082,6 +3082,12 @@ public class PackageParser {
            a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
        }

        if (sa.getBoolean(
                com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
                false)) {
            a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
        }

        if (!receiver) {
            if (sa.getBoolean(
                    com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
@@ -3153,11 +3159,6 @@ public class PackageParser {
                    setExported = true;
                }
            }
            if (sa.getBoolean(
                    com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
                    false)) {
                a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
            }
        }

        sa.recycle();
+25 −4
Original line number Diff line number Diff line
@@ -3381,7 +3381,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                if (resolveInfo != null) {
                    List<ResolveInfo> result = new ArrayList<ResolveInfo>(1);
                    result.add(resolveInfo);
                    return result;
                    return filterIfNotPrimaryUser(result, userId);
                }
                // Check for cross profile results.
                resolveInfo = queryCrossProfileIntents(
@@ -3394,17 +3394,38 @@ public class PackageManagerService extends IPackageManager.Stub {
                    result.add(resolveInfo);
                    Collections.sort(result, mResolvePrioritySorter);
                }
                return result;
                return filterIfNotPrimaryUser(result, userId);
            }
            final PackageParser.Package pkg = mPackages.get(pkgName);
            if (pkg != null) {
                return mActivities.queryIntentForPackage(intent, resolvedType, flags,
                        pkg.activities, userId);
                return filterIfNotPrimaryUser(
                        mActivities.queryIntentForPackage(
                                intent, resolvedType, flags, pkg.activities, userId),
                        userId);
            }
            return new ArrayList<ResolveInfo>();
        }
    }
    /**
     * Filter out activities with primaryUserOnly flag set, when current user is not the owner.
     *
     * @return filtered list
     */
    private List<ResolveInfo> filterIfNotPrimaryUser(List<ResolveInfo> resolveInfos, int userId) {
        if (userId == UserHandle.USER_OWNER) {
            return resolveInfos;
        }
        for (int i = resolveInfos.size() - 1; i >= 0; i--) {
            ResolveInfo info = resolveInfos.get(i);
            if ((info.activityInfo.flags & ActivityInfo.FLAG_PRIMARY_USER_ONLY) != 0) {
                resolveInfos.remove(i);
            }
        }
        return resolveInfos;
    }
    private ResolveInfo querySkipCurrentProfileIntents(
            List<CrossProfileIntentFilter> matchingFilters, Intent intent, String resolvedType,
            int flags, int sourceUserId) {