summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-04-10 22:22:33 (GMT)
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-04-10 22:22:33 (GMT)
commite4c6ce23af53637fb0a8b41b5d567bbff3e5768c (patch)
treea35b315aae9931564ec8b22647cf2ee6803cb142
parent406229f0c84d4086c3f62019d356ca92a4864621 (diff)
parent63846a7093ca7c6d89b73fc77bdff267b3ecb4ef (diff)
downloadframeworks_base-e4c6ce23af53637fb0a8b41b5d567bbff3e5768c.zip
frameworks_base-e4c6ce23af53637fb0a8b41b5d567bbff3e5768c.tar.gz
frameworks_base-e4c6ce23af53637fb0a8b41b5d567bbff3e5768c.tar.bz2
Merge "Add cross user permission check - areNotificationsEnabledForPackage" into pi-dev
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java5
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java19
2 files changed, 24 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 82363d1..1928cb7 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2186,6 +2186,11 @@ public class NotificationManagerService extends SystemService {
@Override
public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
checkCallerIsSystemOrSameApp(pkg);
+ if (UserHandle.getCallingUserId() != UserHandle.getUserId(uid)) {
+ getContext().enforceCallingPermission(
+ android.Manifest.permission.INTERACT_ACROSS_USERS,
+ "canNotifyAsPackage for uid " + uid);
+ }
return mRankingHelper.getImportance(pkg, uid) != IMPORTANCE_NONE;
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index f02c3f0..5622622 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -34,6 +34,7 @@ import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
import static android.content.pm.PackageManager.FEATURE_WATCH;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.Build.VERSION_CODES.O_MR1;
import static android.os.Build.VERSION_CODES.P;
@@ -106,6 +107,7 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableContext;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
+import android.testing.TestablePermissions;
import android.text.Html;
import android.util.ArrayMap;
import android.util.AtomicFile;
@@ -3145,4 +3147,21 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
assertEquals(0, captor.getValue().getNotification().flags);
}
+
+ @Test
+ public void testAreNotificationsEnabledForPackage_crossUser() throws Exception {
+ try {
+ mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(),
+ mUid + UserHandle.PER_USER_RANGE);
+ fail("Cannot call cross user without permission");
+ } catch (SecurityException e) {
+ // pass
+ }
+
+ // cross user, with permission, no problem
+ TestablePermissions perms = mContext.getTestablePermissions();
+ perms.setPermission(android.Manifest.permission.INTERACT_ACROSS_USERS, PERMISSION_GRANTED);
+ mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(),
+ mUid + UserHandle.PER_USER_RANGE);
+ }
}