summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2022-09-17 12:56:56 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2022-09-17 12:56:56 +0000
commitdc79591dcacc3a4833d08777e27c2cbde9ba4d99 (patch)
treef63e5162e0d4d8970176e73a9cf378b4bdcc8506
parentbc1eb56d825d4e3e62be417f731c84fc2f2dfd3a (diff)
parent1a2da0dbd388139c1062ec127ccb44b3ab5ae493 (diff)
Merge "Fix cross profile NLS notif event delivery" into tm-qpr-dev am: 31d378dfbe am: 1a2da0dbd3
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19969705 Change-Id: I5804d3c3f6f5fbceedd4ad53e740628076ed6b6c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--services/core/java/com/android/server/notification/ManagedServices.java10
-rwxr-xr-xservices/core/java/com/android/server/notification/NotificationManagerService.java6
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java32
3 files changed, 32 insertions, 16 deletions
diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java
index 0fac808fb13b..4d55d4e545ee 100644
--- a/services/core/java/com/android/server/notification/ManagedServices.java
+++ b/services/core/java/com/android/server/notification/ManagedServices.java
@@ -1786,8 +1786,8 @@ abstract public class ManagedServices {
* from receiving events from the profile.
*/
public boolean isPermittedForProfile(int userId) {
- if (!mUserProfiles.canProfileUseBoundServices(userId)) {
- return false;
+ if (!mUserProfiles.isProfileUser(userId)) {
+ return true;
}
DevicePolicyManager dpm =
(DevicePolicyManager) mContext.getSystemService(DEVICE_POLICY_SERVICE);
@@ -1862,16 +1862,16 @@ abstract public class ManagedServices {
}
}
- public boolean canProfileUseBoundServices(int userId) {
+ public boolean isProfileUser(int userId) {
synchronized (mCurrentProfiles) {
UserInfo user = mCurrentProfiles.get(userId);
if (user == null) {
return false;
}
if (user.isManagedProfile() || user.isCloneProfile()) {
- return false;
+ return true;
}
- return true;
+ return false;
}
}
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 5d64176fce03..4b18add39999 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1829,7 +1829,7 @@ public class NotificationManagerService extends SystemService {
} else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
mUserProfiles.updateCache(context);
- if (mUserProfiles.canProfileUseBoundServices(userId)) {
+ if (!mUserProfiles.isProfileUser(userId)) {
// reload per-user settings
mSettingsObserver.update(null);
// Refresh managed services
@@ -1843,7 +1843,7 @@ public class NotificationManagerService extends SystemService {
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
if (userId != USER_NULL) {
mUserProfiles.updateCache(context);
- if (mUserProfiles.canProfileUseBoundServices(userId)) {
+ if (!mUserProfiles.isProfileUser(userId)) {
allowDefaultApprovedServices(userId);
}
}
@@ -1861,7 +1861,7 @@ public class NotificationManagerService extends SystemService {
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
mUserProfiles.updateCache(context);
mAssistants.onUserUnlocked(userId);
- if (mUserProfiles.canProfileUseBoundServices(userId)) {
+ if (!mUserProfiles.isProfileUser(userId)) {
mConditionProviders.onUserUnlocked(userId);
mListeners.onUserUnlocked(userId);
mZenModeHelper.onUserUnlocked(userId);
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
index 49879efe4b51..798604306b43 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
@@ -1704,8 +1704,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
}
@Test
- public void testInfoIsPermittedForProfile_notAllowed() {
- when(mUserProfiles.canProfileUseBoundServices(anyInt())).thenReturn(false);
+ public void testInfoIsPermittedForProfile_notProfile() {
+ when(mUserProfiles.isProfileUser(anyInt())).thenReturn(false);
IInterface service = mock(IInterface.class);
when(service.asBinder()).thenReturn(mock(IBinder.class));
@@ -1714,12 +1714,12 @@ public class ManagedServicesTest extends UiServiceTestCase {
services.registerSystemService(service, null, 10, 1000);
ManagedServices.ManagedServiceInfo info = services.checkServiceTokenLocked(service);
- assertFalse(info.isPermittedForProfile(0));
+ assertTrue(info.isPermittedForProfile(0));
}
@Test
- public void testInfoIsPermittedForProfile_allows() {
- when(mUserProfiles.canProfileUseBoundServices(anyInt())).thenReturn(true);
+ public void testInfoIsPermittedForProfile_profileAndDpmAllows() {
+ when(mUserProfiles.isProfileUser(anyInt())).thenReturn(true);
when(mDpm.isNotificationListenerServicePermitted(anyString(), anyInt())).thenReturn(true);
IInterface service = mock(IInterface.class);
@@ -1734,6 +1734,22 @@ public class ManagedServicesTest extends UiServiceTestCase {
}
@Test
+ public void testInfoIsPermittedForProfile_profileAndDpmDenies() {
+ when(mUserProfiles.isProfileUser(anyInt())).thenReturn(true);
+ when(mDpm.isNotificationListenerServicePermitted(anyString(), anyInt())).thenReturn(false);
+
+ IInterface service = mock(IInterface.class);
+ when(service.asBinder()).thenReturn(mock(IBinder.class));
+ ManagedServices services = new TestManagedServices(getContext(), mLock, mUserProfiles,
+ mIpm, APPROVAL_BY_PACKAGE);
+ services.registerSystemService(service, null, 10, 1000);
+ ManagedServices.ManagedServiceInfo info = services.checkServiceTokenLocked(service);
+ info.component = new ComponentName("a","b");
+
+ assertFalse(info.isPermittedForProfile(0));
+ }
+
+ @Test
public void testUserProfiles_canProfileUseBoundServices_managedProfile() {
List<UserInfo> users = new ArrayList<>();
UserInfo profile = new UserInfo(ActivityManager.getCurrentUser(), "current", 0);
@@ -1750,9 +1766,9 @@ public class ManagedServicesTest extends UiServiceTestCase {
ManagedServices.UserProfiles profiles = new ManagedServices.UserProfiles();
profiles.updateCache(mContext);
- assertTrue(profiles.canProfileUseBoundServices(ActivityManager.getCurrentUser()));
- assertFalse(profiles.canProfileUseBoundServices(12));
- assertFalse(profiles.canProfileUseBoundServices(13));
+ assertFalse(profiles.isProfileUser(ActivityManager.getCurrentUser()));
+ assertTrue(profiles.isProfileUser(12));
+ assertTrue(profiles.isProfileUser(13));
}
private void resetComponentsAndPackages() {