Add pkg target to snoozing alarm

Test: SnoozeHelperTest
Bug: 174493336
Change-Id: I6aaf80a11dcae2eca41d4647411126ed41587027
(cherry picked from commit 6b5813b1f1)
This commit is contained in:
Julia Reynolds
2021-02-22 15:58:57 -05:00
parent 6628f4e7b8
commit 88854d15ef
2 changed files with 14 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.util.XmlUtils; import com.android.internal.util.XmlUtils;
import com.android.server.pm.PackageManagerService;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@@ -463,6 +464,7 @@ public class SnoozeHelper {
return PendingIntent.getBroadcast(mContext, return PendingIntent.getBroadcast(mContext,
REQUEST_CODE_REPOST, REQUEST_CODE_REPOST,
new Intent(REPOST_ACTION) new Intent(REPOST_ACTION)
.setPackage(PackageManagerService.PLATFORM_PACKAGE_NAME)
.setData(new Uri.Builder().scheme(REPOST_SCHEME).appendPath(key).build()) .setData(new Uri.Builder().scheme(REPOST_SCHEME).appendPath(key).build())
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND) .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
.putExtra(EXTRA_KEY, key) .putExtra(EXTRA_KEY, key)

View File

@@ -49,6 +49,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.FastXmlSerializer;
import com.android.server.UiServiceTestCase; import com.android.server.UiServiceTestCase;
import com.android.server.pm.PackageManagerService;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -256,6 +257,17 @@ public class SnoozeHelperTest extends UiServiceTestCase {
UserHandle.USER_SYSTEM, r.getSbn().getPackageName(), r.getKey())); UserHandle.USER_SYSTEM, r.getSbn().getPackageName(), r.getKey()));
} }
@Test
public void testSnoozeSentToAndroid() throws Exception {
NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);
mSnoozeHelper.snooze(r, 1000);
ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class);
verify(mAm, times(1)).setExactAndAllowWhileIdle(
anyInt(), anyLong(), captor.capture());
assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME,
captor.getValue().getIntent().getPackage());
}
@Test @Test
public void testSnooze() throws Exception { public void testSnooze() throws Exception {
NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);