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

Commit bddfb803 authored by Himanshu Gupta's avatar Himanshu Gupta Committed by Android (Google) Code Review
Browse files

Merge changes I6e4a0037,Ie15e0672 into main

* changes:
  Restricitng ACTION_SESSION_COMMITTED broadcast for hidden profiles.
  Blocking home screen items for Private Profile
parents 2796bd76 91dbf7d0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -115,6 +115,11 @@ public abstract class ShortcutServiceInternal {
    public abstract boolean hasShortcutHostPermission(int launcherUserId,
            @NonNull String callingPackage, int callingPid, int callingUid);

    /**
     * Returns whether or not Shortcuts are supported on Launcher Home Screen.
     */
    public abstract boolean areShortcutsSupportedOnHomeScreen(@UserIdInt int userId);

    public abstract void setShortcutHostPackage(@NonNull String type, @Nullable String packageName,
            int userId);

+7 −0
Original line number Diff line number Diff line
@@ -156,3 +156,10 @@ flag {
    description: "Set power mode during a user switch."
    bug: "325249845"
}

flag {
    name: "disable_private_space_items_on_home"
    namespace: "profile_experiences"
    description: "Disables adding items belonging to Private Space on Home Screen manually as well as automatically"
    bug: "287975131"
}
+10 −0
Original line number Diff line number Diff line
@@ -2413,6 +2413,16 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
        }

        AppWidgetProviderInfo info = createPartialProviderInfo(providerId, ri, existing);

        if (android.os.Flags.allowPrivateProfile()
                && android.multiuser.Flags.disablePrivateSpaceItemsOnHome()) {
            // Do not add widget providers for profiles with items restricted on home screen.
            if (mUserManager
                    .getUserProperties(info.getProfile()).areItemsRestrictedOnHomeScreen()) {
                return false;
            }
        }

        if (info != null) {
            if (existing != null) {
                if (existing.zombie && !mSafeMode) {
+33 −2
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ import android.content.Intent;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.pm.UserProperties;
import android.multiuser.Flags;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -361,14 +363,13 @@ public final class BroadcastHelper {
        final UserInfo parent = ums.getProfileParent(userId);
        final int launcherUserId = (parent != null) ? parent.id : userId;
        final ComponentName launcherComponent = snapshot.getDefaultHomeActivity(launcherUserId);
        if (launcherComponent != null) {
        if (launcherComponent != null && canLauncherAccessProfile(launcherComponent, userId)) {
            Intent launcherIntent = new Intent(PackageInstaller.ACTION_SESSION_COMMITTED)
                    .putExtra(PackageInstaller.EXTRA_SESSION, sessionInfo)
                    .putExtra(Intent.EXTRA_USER, UserHandle.of(userId))
                    .setPackage(launcherComponent.getPackageName());
            mContext.sendBroadcastAsUser(launcherIntent, UserHandle.of(launcherUserId));
        }
        // TODO(b/122900055) Change/Remove this and replace with new permission role.
        if (appPredictionServicePackage != null) {
            Intent predictorIntent = new Intent(PackageInstaller.ACTION_SESSION_COMMITTED)
                    .putExtra(PackageInstaller.EXTRA_SESSION, sessionInfo)
@@ -378,6 +379,36 @@ public final class BroadcastHelper {
        }
    }

    /**
     * A Profile is accessible to launcher in question if:
     * - It's not hidden for API visibility.
     * - Hidden, but launcher application has either
     *      {@link Manifest.permission.ACCESS_HIDDEN_PROFILES_FULL} or
     *      {@link Manifest.permission.ACCESS_HIDDEN_PROFILES}
     *   granted.
     */
    boolean canLauncherAccessProfile(ComponentName launcherComponent, int userId) {
        if (android.os.Flags.allowPrivateProfile()
                && Flags.enablePermissionToAccessHiddenProfiles()) {
            if (mUmInternal.getUserProperties(userId).getProfileApiVisibility()
                    != UserProperties.PROFILE_API_VISIBILITY_HIDDEN) {
                return true;
            }
            if (mContext.getPackageManager().checkPermission(
                            Manifest.permission.ACCESS_HIDDEN_PROFILES_FULL,
                            launcherComponent.getPackageName())
                    == PackageManager.PERMISSION_GRANTED) {
                return true;
            }
            // TODO(b/122900055) Change/Remove this and replace with new permission role.
            return mContext.getPackageManager().checkPermission(
                            Manifest.permission.ACCESS_HIDDEN_PROFILES,
                            launcherComponent.getPackageName())
                        == PackageManager.PERMISSION_GRANTED;
        }
        return true;
    }

    void sendPreferredActivityChangedBroadcast(int userId) {
        mHandler.post(() -> {
            final IActivityManager am = ActivityManager.getService();
+12 −0
Original line number Diff line number Diff line
@@ -798,6 +798,10 @@ public class LauncherAppsService extends SystemService {
        public ParceledListSlice getShortcutConfigActivities(
                String callingPackage, String packageName, UserHandle user)
                throws RemoteException {
            // Not supported for user-profiles with items restricted on home screen.
            if (!mShortcutServiceInternal.areShortcutsSupportedOnHomeScreen(user.getIdentifier())) {
                return null;
            }
            return queryActivitiesForUser(callingPackage,
                    new Intent(Intent.ACTION_CREATE_SHORTCUT).setPackage(packageName), user);
        }
@@ -1256,6 +1260,14 @@ public class LauncherAppsService extends SystemService {
        @Override
        public void pinShortcuts(String callingPackage, String packageName, List<String> ids,
                UserHandle targetUser) {
            if (!mShortcutServiceInternal
                    .areShortcutsSupportedOnHomeScreen(targetUser.getIdentifier())) {
                // Requires strict ACCESS_SHORTCUTS permission for user-profiles with items
                // restricted on home screen.
                ensureStrictAccessShortcutsPermission(callingPackage);
            } else {
                ensureShortcutPermission(callingPackage);
            }
            ensureShortcutPermission(callingPackage);
            if (!canAccessProfile(targetUser.getIdentifier(), "Cannot pin shortcuts")) {
                return;
Loading