From 5e451db3952c6a808d803b1b7b1f645dc4756d4d Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Thu, 21 Mar 2024 14:14:02 +0000 Subject: [PATCH] Disable PS entry point and Activity when PS is not allowed. In this change we disable: 1. Security Center Entry point 2. PrivateSpaceAuthenticationActivity when private profile is not present and cannot be added. Additionally, the intent exposing PrivateSpaceAuthenticationActivity is also non-exported and changed to a better name. Bug: 328578044 Test: Manual build and flash Change-Id: I13d298316c6d719d0b06e4969989ea1da83dd4c6 --- AndroidManifest.xml | 12 +++- .../PrivateSpaceAuthenticationActivity.java | 2 +- .../PrivateSpaceBroadcastReceiver.java | 55 +++++++++++++++++++ .../privatespace/PrivateSpaceMaintainer.java | 2 +- .../PrivateSpaceSafetySource.java | 24 ++++++-- 5 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 src/com/android/settings/privatespace/PrivateSpaceBroadcastReceiver.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 8730b421739..8a2ac6b0b36 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5103,9 +5103,9 @@ + android:exported="false"> - + @@ -5117,6 +5117,14 @@ android:exported="false"> + + + + + + + users = mUserManager.getProfiles(0); + List users = mUserManager.getProfiles(mContext.getUserId()); for (UserInfo user : users) { if (user.isPrivateProfile()) { mUserHandle = user.getUserHandle(); diff --git a/src/com/android/settings/privatespace/PrivateSpaceSafetySource.java b/src/com/android/settings/privatespace/PrivateSpaceSafetySource.java index 4e1741a7cda..3272f125756 100644 --- a/src/com/android/settings/privatespace/PrivateSpaceSafetySource.java +++ b/src/com/android/settings/privatespace/PrivateSpaceSafetySource.java @@ -44,11 +44,27 @@ public final class PrivateSpaceSafetySource { return; } - // Check the profile type - we don't want to show this for anything other than primary user. UserManager userManager = context.getSystemService(UserManager.class); - if (userManager != null && !userManager.isMainUser()) { - Log.i(TAG, "setSafetySourceData not main user"); - return; + PrivateSpaceMaintainer privateSpaceMaintainer = + PrivateSpaceMaintainer.getInstance(context); + if (android.multiuser.Flags.enablePrivateSpaceFeatures() + && android.multiuser.Flags.blockPrivateSpaceCreation()) { + // Do not add the entry point when + // -Private Profile is not present and + // -Private Profile cannot be added. + if (!privateSpaceMaintainer.doesPrivateSpaceExist() + && userManager != null + && !userManager.canAddPrivateProfile()) { + Log.i(TAG, "Private Space not allowed for user " + context.getUser()); + return; + } + } else { + // Check the profile type - we don't want to show this for anything other than primary + // user. + if (userManager != null && !userManager.isMainUser()) { + Log.i(TAG, "setSafetySourceData not main user"); + return; + } } if (!Flags.allowPrivateProfile()