Merge "Allow Device Owners/Profile Owners to set the interruption filter." into pi-dev am: a668c66301

am: 591ed6c7fe

Change-Id: I857c4273eb70826bd7754f859620eee0ee38ec1a
This commit is contained in:
Jason Parks
2018-04-13 13:36:39 -07:00
committed by android-build-merger
2 changed files with 19 additions and 6 deletions

View File

@@ -98,6 +98,8 @@ import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.app.PendingIntent;
import android.app.StatusBarManager;
import android.app.admin.DeviceAdminInfo;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.backup.BackupManager;
import android.app.usage.UsageEvents;
import android.app.usage.UsageStatsManagerInternal;
@@ -366,6 +368,7 @@ public class NotificationManagerService extends SystemService {
private AppOpsManager mAppOps;
private UsageStatsManagerInternal mAppUsageStats;
private DevicePolicyManagerInternal mDpm;
private Archive mArchive;
@@ -1355,7 +1358,7 @@ public class NotificationManagerService extends SystemService {
ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper,
NotificationUsageStats usageStats, AtomicFile policyFile,
ActivityManager activityManager, GroupHelper groupHelper, IActivityManager am,
UsageStatsManagerInternal appUsageStats) {
UsageStatsManagerInternal appUsageStats, DevicePolicyManagerInternal dpm) {
Resources resources = getContext().getResources();
mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(),
Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE,
@@ -1374,6 +1377,8 @@ public class NotificationManagerService extends SystemService {
mActivityManager = activityManager;
mDeviceIdleController = IDeviceIdleController.Stub.asInterface(
ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
mDpm = dpm;
try {
mPermissionOwner = mAm.newUriPermissionOwner("notification");
} catch (RemoteException e) {
@@ -1512,7 +1517,8 @@ public class NotificationManagerService extends SystemService {
new AtomicFile(new File(systemDir, "notification_policy.xml"), "notification-policy"),
(ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE),
getGroupHelper(), ActivityManager.getService(),
LocalServices.getService(UsageStatsManagerInternal.class));
LocalServices.getService(UsageStatsManagerInternal.class),
LocalServices.getService(DevicePolicyManagerInternal.class));
// register for various Intents
IntentFilter filter = new IntentFilter();
@@ -3090,8 +3096,8 @@ public class NotificationManagerService extends SystemService {
private boolean checkPolicyAccess(String pkg) {
try {
int uid = getContext().getPackageManager().getPackageUidAsUser(
pkg, UserHandle.getCallingUserId());
int uid = getContext().getPackageManager().getPackageUidAsUser(pkg,
UserHandle.getCallingUserId());
if (PackageManager.PERMISSION_GRANTED == ActivityManager.checkComponentPermission(
android.Manifest.permission.MANAGE_NOTIFICATIONS, uid,
-1, true)) {
@@ -3100,7 +3106,11 @@ public class NotificationManagerService extends SystemService {
} catch (NameNotFoundException e) {
return false;
}
return checkPackagePolicyAccess(pkg) || mListeners.isComponentEnabledForPackage(pkg);
return checkPackagePolicyAccess(pkg)
|| mListeners.isComponentEnabledForPackage(pkg)
|| (mDpm != null &&
mDpm.isActiveAdminWithPolicy(Binder.getCallingUid(),
DeviceAdminInfo.USES_POLICY_PROFILE_OWNER));
}
@Override

View File

@@ -68,6 +68,8 @@ import android.app.Notification.MessagingStyle.Message;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.app.admin.DeviceAdminInfo;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.usage.UsageStatsManagerInternal;
import android.companion.ICompanionDeviceManager;
import android.content.ComponentName;
@@ -265,7 +267,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mPackageManager, mPackageManagerClient, mockLightsManager,
mListeners, mAssistants, mConditionProviders,
mCompanionMgr, mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager,
mGroupHelper, mAm, mock(UsageStatsManagerInternal.class));
mGroupHelper, mAm, mock(UsageStatsManagerInternal.class),
mock(DevicePolicyManagerInternal.class));
} catch (SecurityException e) {
if (!e.getMessage().contains("Permission Denial: not allowed to send broadcast")) {
throw e;