Restrict alarm broadcast
To android only Test: NotificationManagerTest, NotificationManagerServiceTest Bug: 175614289 Change-Id: I4f8e56729d90f8f5288d08881129b1c45d5790e7 Merged-In: I4f8e56729d90f8f5288d08881129b1c45d5790e7 (cherry picked from commitabf15b731a) (cherry picked from commit4056976f1e)
This commit is contained in:
2
services/core/java/com/android/server/notification/NotificationManagerService.java
Normal file → Executable file
2
services/core/java/com/android/server/notification/NotificationManagerService.java
Normal file → Executable file
@@ -5768,7 +5768,7 @@ public class NotificationManagerService extends SystemService {
|
||||
final PendingIntent pi = PendingIntent.getBroadcast(getContext(),
|
||||
REQUEST_CODE_TIMEOUT,
|
||||
new Intent(ACTION_NOTIFICATION_TIMEOUT)
|
||||
.setPackage("android")
|
||||
.setPackage(PackageManagerService.PLATFORM_PACKAGE_NAME)
|
||||
.setData(new Uri.Builder().scheme(SCHEME_TIMEOUT)
|
||||
.appendPath(record.getKey()).build())
|
||||
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
|
||||
|
||||
26
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
Normal file → Executable file
26
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
Normal file → Executable file
@@ -74,6 +74,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerInternal;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.IActivityManager;
|
||||
@@ -146,6 +147,7 @@ import com.android.server.lights.Light;
|
||||
import com.android.server.lights.LightsManager;
|
||||
import com.android.server.notification.NotificationManagerService.NotificationAssistants;
|
||||
import com.android.server.notification.NotificationManagerService.NotificationListeners;
|
||||
import com.android.server.pm.PackageManagerService;
|
||||
import com.android.server.uri.UriGrantsManagerInternal;
|
||||
import com.android.server.wm.WindowManagerInternal;
|
||||
|
||||
@@ -242,6 +244,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
mNotificationAssistantAccessGrantedCallback;
|
||||
@Mock
|
||||
UserManager mUm;
|
||||
@Mock
|
||||
AlarmManager mAlarmManager;
|
||||
|
||||
private final FakeSystemClock mSystemClock = new FakeSystemClock();
|
||||
|
||||
// Use a Testable subclass so we can simulate calls from the system without failing.
|
||||
@@ -360,6 +365,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
LocalServices.addService(WindowManagerInternal.class, mWindowManagerInternal);
|
||||
LocalServices.removeServiceForTest(ActivityManagerInternal.class);
|
||||
LocalServices.addService(ActivityManagerInternal.class, mAmi);
|
||||
mContext.addMockSystemService(Context.ALARM_SERVICE, mAlarmManager);
|
||||
|
||||
doNothing().when(mContext).sendBroadcastAsUser(any(), any(), any());
|
||||
|
||||
@@ -570,6 +576,26 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
.setIcon(Icon.createWithResource(mContext, android.R.drawable.sym_def_app_icon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLimitTimeOutBroadcast() {
|
||||
NotificationChannel channel = new NotificationChannel("id", "name",
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
Notification.Builder nb = new Notification.Builder(mContext, channel.getId())
|
||||
.setContentTitle("foo")
|
||||
.setSmallIcon(android.R.drawable.sym_def_app_icon)
|
||||
.setTimeoutAfter(1);
|
||||
|
||||
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0,
|
||||
nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
|
||||
NotificationRecord r = new NotificationRecord(mContext, sbn, channel);
|
||||
|
||||
mService.scheduleTimeoutLocked(r);
|
||||
ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class);
|
||||
verify(mAlarmManager).setExactAndAllowWhileIdle(anyInt(), anyLong(), captor.capture());
|
||||
assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME,
|
||||
captor.getValue().getIntent().getPackage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNotificationChannels_SingleChannel() throws Exception {
|
||||
final NotificationChannel channel =
|
||||
|
||||
Reference in New Issue
Block a user