Merge "Fix cross profile NLS notif event delivery" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
31d378dfbe
@@ -1786,8 +1786,8 @@ abstract public class ManagedServices {
|
|||||||
* from receiving events from the profile.
|
* from receiving events from the profile.
|
||||||
*/
|
*/
|
||||||
public boolean isPermittedForProfile(int userId) {
|
public boolean isPermittedForProfile(int userId) {
|
||||||
if (!mUserProfiles.canProfileUseBoundServices(userId)) {
|
if (!mUserProfiles.isProfileUser(userId)) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
DevicePolicyManager dpm =
|
DevicePolicyManager dpm =
|
||||||
(DevicePolicyManager) mContext.getSystemService(DEVICE_POLICY_SERVICE);
|
(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) {
|
synchronized (mCurrentProfiles) {
|
||||||
UserInfo user = mCurrentProfiles.get(userId);
|
UserInfo user = mCurrentProfiles.get(userId);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (user.isManagedProfile() || user.isCloneProfile()) {
|
if (user.isManagedProfile() || user.isCloneProfile()) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1828,7 +1828,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
} else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
|
} else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
|
||||||
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
|
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
|
||||||
mUserProfiles.updateCache(context);
|
mUserProfiles.updateCache(context);
|
||||||
if (mUserProfiles.canProfileUseBoundServices(userId)) {
|
if (!mUserProfiles.isProfileUser(userId)) {
|
||||||
// reload per-user settings
|
// reload per-user settings
|
||||||
mSettingsObserver.update(null);
|
mSettingsObserver.update(null);
|
||||||
// Refresh managed services
|
// Refresh managed services
|
||||||
@@ -1842,7 +1842,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
|
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
|
||||||
if (userId != USER_NULL) {
|
if (userId != USER_NULL) {
|
||||||
mUserProfiles.updateCache(context);
|
mUserProfiles.updateCache(context);
|
||||||
if (mUserProfiles.canProfileUseBoundServices(userId)) {
|
if (!mUserProfiles.isProfileUser(userId)) {
|
||||||
allowDefaultApprovedServices(userId);
|
allowDefaultApprovedServices(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1860,7 +1860,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
|
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
|
||||||
mUserProfiles.updateCache(context);
|
mUserProfiles.updateCache(context);
|
||||||
mAssistants.onUserUnlocked(userId);
|
mAssistants.onUserUnlocked(userId);
|
||||||
if (mUserProfiles.canProfileUseBoundServices(userId)) {
|
if (!mUserProfiles.isProfileUser(userId)) {
|
||||||
mConditionProviders.onUserUnlocked(userId);
|
mConditionProviders.onUserUnlocked(userId);
|
||||||
mListeners.onUserUnlocked(userId);
|
mListeners.onUserUnlocked(userId);
|
||||||
mZenModeHelper.onUserUnlocked(userId);
|
mZenModeHelper.onUserUnlocked(userId);
|
||||||
|
|||||||
@@ -1704,8 +1704,8 @@ public class ManagedServicesTest extends UiServiceTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfoIsPermittedForProfile_notAllowed() {
|
public void testInfoIsPermittedForProfile_notProfile() {
|
||||||
when(mUserProfiles.canProfileUseBoundServices(anyInt())).thenReturn(false);
|
when(mUserProfiles.isProfileUser(anyInt())).thenReturn(false);
|
||||||
|
|
||||||
IInterface service = mock(IInterface.class);
|
IInterface service = mock(IInterface.class);
|
||||||
when(service.asBinder()).thenReturn(mock(IBinder.class));
|
when(service.asBinder()).thenReturn(mock(IBinder.class));
|
||||||
@@ -1714,12 +1714,12 @@ public class ManagedServicesTest extends UiServiceTestCase {
|
|||||||
services.registerSystemService(service, null, 10, 1000);
|
services.registerSystemService(service, null, 10, 1000);
|
||||||
ManagedServices.ManagedServiceInfo info = services.checkServiceTokenLocked(service);
|
ManagedServices.ManagedServiceInfo info = services.checkServiceTokenLocked(service);
|
||||||
|
|
||||||
assertFalse(info.isPermittedForProfile(0));
|
assertTrue(info.isPermittedForProfile(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfoIsPermittedForProfile_allows() {
|
public void testInfoIsPermittedForProfile_profileAndDpmAllows() {
|
||||||
when(mUserProfiles.canProfileUseBoundServices(anyInt())).thenReturn(true);
|
when(mUserProfiles.isProfileUser(anyInt())).thenReturn(true);
|
||||||
when(mDpm.isNotificationListenerServicePermitted(anyString(), anyInt())).thenReturn(true);
|
when(mDpm.isNotificationListenerServicePermitted(anyString(), anyInt())).thenReturn(true);
|
||||||
|
|
||||||
IInterface service = mock(IInterface.class);
|
IInterface service = mock(IInterface.class);
|
||||||
@@ -1733,6 +1733,22 @@ public class ManagedServicesTest extends UiServiceTestCase {
|
|||||||
assertTrue(info.isPermittedForProfile(0));
|
assertTrue(info.isPermittedForProfile(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testUserProfiles_canProfileUseBoundServices_managedProfile() {
|
public void testUserProfiles_canProfileUseBoundServices_managedProfile() {
|
||||||
List<UserInfo> users = new ArrayList<>();
|
List<UserInfo> users = new ArrayList<>();
|
||||||
@@ -1750,9 +1766,9 @@ public class ManagedServicesTest extends UiServiceTestCase {
|
|||||||
ManagedServices.UserProfiles profiles = new ManagedServices.UserProfiles();
|
ManagedServices.UserProfiles profiles = new ManagedServices.UserProfiles();
|
||||||
profiles.updateCache(mContext);
|
profiles.updateCache(mContext);
|
||||||
|
|
||||||
assertTrue(profiles.canProfileUseBoundServices(ActivityManager.getCurrentUser()));
|
assertFalse(profiles.isProfileUser(ActivityManager.getCurrentUser()));
|
||||||
assertFalse(profiles.canProfileUseBoundServices(12));
|
assertTrue(profiles.isProfileUser(12));
|
||||||
assertFalse(profiles.canProfileUseBoundServices(13));
|
assertTrue(profiles.isProfileUser(13));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetComponentsAndPackages() {
|
private void resetComponentsAndPackages() {
|
||||||
|
|||||||
Reference in New Issue
Block a user