Loading core/java/android/accounts/ChooseTypeAndAccountActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -407,7 +407,7 @@ public class ChooseTypeAndAccountActivity extends Activity mExistingAccounts = AccountManager.get(this).getAccountsForPackage(mCallingPackage, mCallingUid); intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intent, REQUEST_ADD_ACCOUNT); startActivityForResult(new Intent(intent), REQUEST_ADD_ACCOUNT); return; } } catch (OperationCanceledException e) { Loading services/core/java/com/android/server/am/ActivityManagerService.java +17 −14 Original line number Diff line number Diff line Loading @@ -4076,20 +4076,23 @@ public class ActivityManagerService extends IActivityManager.Stub finishForceStopPackageLocked(packageName, appInfo.uid); } } if (succeeded) { final Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null)); Uri.fromParts("package", packageName, null /* fragment */)); intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); intent.putExtra(Intent.EXTRA_UID, (appInfo != null) ? appInfo.uid : -1); intent.putExtra(Intent.EXTRA_USER_HANDLE, resolvedUserId); if (isInstantApp) { intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName); broadcastIntentInPackage("android", SYSTEM_UID, uid, pid, intent, null, null, 0, null, null, permission.ACCESS_INSTANT_APPS, null, false, false, resolvedUserId, false); } else { broadcastIntentInPackage("android", SYSTEM_UID, uid, pid, intent, null, null, 0, null, null, null, null, false, false, resolvedUserId, false); } broadcastIntentInPackage("android", SYSTEM_UID, uid, pid, intent, null /* resolvedType */, null /* resultTo */, 0 /* resultCode */, null /* resultData */, null /* resultExtras */, isInstantApp ? permission.ACCESS_INSTANT_APPS : null, null /* bOptions */, false /* serialized */, false /* sticky */, resolvedUserId, false /* allowBackgroundActivityStarts */); } if (observer != null) { Loading services/core/java/com/android/server/notification/NotificationManagerService.java +16 −1 Original line number Diff line number Diff line Loading @@ -3714,7 +3714,16 @@ public class NotificationManagerService extends SystemService { } enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule"); return mZenModeHelper.addAutomaticZenRule(pkg, automaticZenRule, // If the calling app is the system (from any user), take the package name from the // rule's owner rather than from the caller's package. String rulePkg = pkg; if (isCallingAppIdSystem()) { if (automaticZenRule.getOwner() != null) { rulePkg = automaticZenRule.getOwner().getPackageName(); } } return mZenModeHelper.addAutomaticZenRule(rulePkg, automaticZenRule, "addAutomaticZenRule"); } Loading Loading @@ -7606,6 +7615,12 @@ public class NotificationManagerService extends SystemService { return uid == Process.SYSTEM_UID; } protected boolean isCallingAppIdSystem() { final int uid = Binder.getCallingUid(); final int appid = UserHandle.getAppId(uid); return appid == Process.SYSTEM_UID; } protected boolean isUidSystemOrPhone(int uid) { final int appid = UserHandle.getAppId(uid); return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID || uid == 0); Loading services/core/java/com/android/server/notification/ZenModeHelper.java +1 −6 Original line number Diff line number Diff line Loading @@ -291,7 +291,7 @@ public class ZenModeHelper { public String addAutomaticZenRule(String pkg, AutomaticZenRule automaticZenRule, String reason) { if (!isSystemRule(automaticZenRule)) { if (!ZenModeConfig.SYSTEM_AUTHORITY.equals(pkg)) { PackageItemInfo component = getServiceInfo(automaticZenRule.getOwner()); if (component == null) { component = getActivityInfo(automaticZenRule.getConfigurationActivity()); Loading Loading @@ -532,11 +532,6 @@ public class ZenModeHelper { } } private boolean isSystemRule(AutomaticZenRule rule) { return rule.getOwner() != null && ZenModeConfig.SYSTEM_AUTHORITY.equals(rule.getOwner().getPackageName()); } private ServiceInfo getServiceInfo(ComponentName owner) { Intent queryIntent = new Intent(); queryIntent.setComponent(owner); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +66 −0 Original line number Diff line number Diff line Loading @@ -259,6 +259,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { private static class TestableNotificationManagerService extends NotificationManagerService { int countSystemChecks = 0; boolean isSystemUid = true; boolean isSystemAppId = true; int countLogSmartSuggestionsVisible = 0; @Nullable NotificationAssistantAccessGrantedCallback mNotificationAssistantAccessGrantedCallback; Loading @@ -273,6 +274,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return isSystemUid; } @Override protected boolean isCallingAppIdSystem() { countSystemChecks++; return isSystemUid || isSystemAppId; } @Override protected boolean isCallerSystemOrPhone() { countSystemChecks++; Loading Loading @@ -5187,6 +5194,65 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mBinderService.addAutomaticZenRule(rule, mContext.getPackageName()); } @Test public void testAddAutomaticZenRule_systemCallTakesPackageFromOwner() throws Exception { mService.isSystemUid = true; ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class); when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt())) .thenReturn(true); mService.setZenHelper(mockZenModeHelper); ComponentName owner = new ComponentName("android", "ProviderName"); ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build(); boolean isEnabled = true; AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class), zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled); mBinderService.addAutomaticZenRule(rule, "com.android.settings"); // verify that zen mode helper gets passed in a package name of "android" verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString()); } @Test public void testAddAutomaticZenRule_systemAppIdCallTakesPackageFromOwner() throws Exception { // The multi-user case: where the calling uid doesn't match the system uid, but the calling // *appid* is the system. mService.isSystemUid = false; mService.isSystemAppId = true; ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class); when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt())) .thenReturn(true); mService.setZenHelper(mockZenModeHelper); ComponentName owner = new ComponentName("android", "ProviderName"); ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build(); boolean isEnabled = true; AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class), zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled); mBinderService.addAutomaticZenRule(rule, "com.android.settings"); // verify that zen mode helper gets passed in a package name of "android" verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString()); } @Test public void testAddAutomaticZenRule_nonSystemCallTakesPackageFromArg() throws Exception { mService.isSystemUid = false; mService.isSystemAppId = false; ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class); when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt())) .thenReturn(true); mService.setZenHelper(mockZenModeHelper); ComponentName owner = new ComponentName("android", "ProviderName"); ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build(); boolean isEnabled = true; AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class), zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled); mBinderService.addAutomaticZenRule(rule, "another.package"); // verify that zen mode helper gets passed in the package name from the arg, not the owner verify(mockZenModeHelper).addAutomaticZenRule( eq("another.package"), eq(rule), anyString()); } @Test public void testAreNotificationsEnabledForPackage_crossUser() throws Exception { try { Loading Loading
core/java/android/accounts/ChooseTypeAndAccountActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -407,7 +407,7 @@ public class ChooseTypeAndAccountActivity extends Activity mExistingAccounts = AccountManager.get(this).getAccountsForPackage(mCallingPackage, mCallingUid); intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intent, REQUEST_ADD_ACCOUNT); startActivityForResult(new Intent(intent), REQUEST_ADD_ACCOUNT); return; } } catch (OperationCanceledException e) { Loading
services/core/java/com/android/server/am/ActivityManagerService.java +17 −14 Original line number Diff line number Diff line Loading @@ -4076,20 +4076,23 @@ public class ActivityManagerService extends IActivityManager.Stub finishForceStopPackageLocked(packageName, appInfo.uid); } } if (succeeded) { final Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null)); Uri.fromParts("package", packageName, null /* fragment */)); intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); intent.putExtra(Intent.EXTRA_UID, (appInfo != null) ? appInfo.uid : -1); intent.putExtra(Intent.EXTRA_USER_HANDLE, resolvedUserId); if (isInstantApp) { intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName); broadcastIntentInPackage("android", SYSTEM_UID, uid, pid, intent, null, null, 0, null, null, permission.ACCESS_INSTANT_APPS, null, false, false, resolvedUserId, false); } else { broadcastIntentInPackage("android", SYSTEM_UID, uid, pid, intent, null, null, 0, null, null, null, null, false, false, resolvedUserId, false); } broadcastIntentInPackage("android", SYSTEM_UID, uid, pid, intent, null /* resolvedType */, null /* resultTo */, 0 /* resultCode */, null /* resultData */, null /* resultExtras */, isInstantApp ? permission.ACCESS_INSTANT_APPS : null, null /* bOptions */, false /* serialized */, false /* sticky */, resolvedUserId, false /* allowBackgroundActivityStarts */); } if (observer != null) { Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +16 −1 Original line number Diff line number Diff line Loading @@ -3714,7 +3714,16 @@ public class NotificationManagerService extends SystemService { } enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule"); return mZenModeHelper.addAutomaticZenRule(pkg, automaticZenRule, // If the calling app is the system (from any user), take the package name from the // rule's owner rather than from the caller's package. String rulePkg = pkg; if (isCallingAppIdSystem()) { if (automaticZenRule.getOwner() != null) { rulePkg = automaticZenRule.getOwner().getPackageName(); } } return mZenModeHelper.addAutomaticZenRule(rulePkg, automaticZenRule, "addAutomaticZenRule"); } Loading Loading @@ -7606,6 +7615,12 @@ public class NotificationManagerService extends SystemService { return uid == Process.SYSTEM_UID; } protected boolean isCallingAppIdSystem() { final int uid = Binder.getCallingUid(); final int appid = UserHandle.getAppId(uid); return appid == Process.SYSTEM_UID; } protected boolean isUidSystemOrPhone(int uid) { final int appid = UserHandle.getAppId(uid); return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID || uid == 0); Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +1 −6 Original line number Diff line number Diff line Loading @@ -291,7 +291,7 @@ public class ZenModeHelper { public String addAutomaticZenRule(String pkg, AutomaticZenRule automaticZenRule, String reason) { if (!isSystemRule(automaticZenRule)) { if (!ZenModeConfig.SYSTEM_AUTHORITY.equals(pkg)) { PackageItemInfo component = getServiceInfo(automaticZenRule.getOwner()); if (component == null) { component = getActivityInfo(automaticZenRule.getConfigurationActivity()); Loading Loading @@ -532,11 +532,6 @@ public class ZenModeHelper { } } private boolean isSystemRule(AutomaticZenRule rule) { return rule.getOwner() != null && ZenModeConfig.SYSTEM_AUTHORITY.equals(rule.getOwner().getPackageName()); } private ServiceInfo getServiceInfo(ComponentName owner) { Intent queryIntent = new Intent(); queryIntent.setComponent(owner); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +66 −0 Original line number Diff line number Diff line Loading @@ -259,6 +259,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { private static class TestableNotificationManagerService extends NotificationManagerService { int countSystemChecks = 0; boolean isSystemUid = true; boolean isSystemAppId = true; int countLogSmartSuggestionsVisible = 0; @Nullable NotificationAssistantAccessGrantedCallback mNotificationAssistantAccessGrantedCallback; Loading @@ -273,6 +274,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return isSystemUid; } @Override protected boolean isCallingAppIdSystem() { countSystemChecks++; return isSystemUid || isSystemAppId; } @Override protected boolean isCallerSystemOrPhone() { countSystemChecks++; Loading Loading @@ -5187,6 +5194,65 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mBinderService.addAutomaticZenRule(rule, mContext.getPackageName()); } @Test public void testAddAutomaticZenRule_systemCallTakesPackageFromOwner() throws Exception { mService.isSystemUid = true; ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class); when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt())) .thenReturn(true); mService.setZenHelper(mockZenModeHelper); ComponentName owner = new ComponentName("android", "ProviderName"); ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build(); boolean isEnabled = true; AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class), zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled); mBinderService.addAutomaticZenRule(rule, "com.android.settings"); // verify that zen mode helper gets passed in a package name of "android" verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString()); } @Test public void testAddAutomaticZenRule_systemAppIdCallTakesPackageFromOwner() throws Exception { // The multi-user case: where the calling uid doesn't match the system uid, but the calling // *appid* is the system. mService.isSystemUid = false; mService.isSystemAppId = true; ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class); when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt())) .thenReturn(true); mService.setZenHelper(mockZenModeHelper); ComponentName owner = new ComponentName("android", "ProviderName"); ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build(); boolean isEnabled = true; AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class), zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled); mBinderService.addAutomaticZenRule(rule, "com.android.settings"); // verify that zen mode helper gets passed in a package name of "android" verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString()); } @Test public void testAddAutomaticZenRule_nonSystemCallTakesPackageFromArg() throws Exception { mService.isSystemUid = false; mService.isSystemAppId = false; ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class); when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt())) .thenReturn(true); mService.setZenHelper(mockZenModeHelper); ComponentName owner = new ComponentName("android", "ProviderName"); ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build(); boolean isEnabled = true; AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class), zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled); mBinderService.addAutomaticZenRule(rule, "another.package"); // verify that zen mode helper gets passed in the package name from the arg, not the owner verify(mockZenModeHelper).addAutomaticZenRule( eq("another.package"), eq(rule), anyString()); } @Test public void testAreNotificationsEnabledForPackage_crossUser() throws Exception { try { Loading