Add @Implementation for ShadowService#stopSelfResult.
PiperOrigin-RevId: 212471820
diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowServiceTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowServiceTest.java
index 8f65685..1bd003e 100644
--- a/robolectric/src/test/java/org/robolectric/shadows/ShadowServiceTest.java
+++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowServiceTest.java
@@ -121,6 +121,12 @@
assertThat(shadow.isStoppedBySelf()).isTrue();
}
+ @Test
+ public void shouldStopSelfResultWithId() {
+ service.stopSelfResult(1);
+ assertThat(shadow.isStoppedBySelf()).isTrue();
+ }
+
public static class MyService extends Service {
@Override
public void onDestroy() {
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowService.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowService.java
index 4b2023c..440e41c 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowService.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowService.java
@@ -21,24 +21,30 @@
private boolean notificationShouldRemoved;
@Implementation
- public void onDestroy() {
+ protected void onDestroy() {
removeForegroundNotification();
}
@Implementation
- public void stopSelf() {
+ protected void stopSelf() {
selfStopped = true;
}
@Implementation
- public void stopSelf(int id) {
+ protected void stopSelf(int id) {
selfStopped = true;
}
@Implementation
- public final void startForeground(int id, Notification notification) {
+ protected boolean stopSelfResult(int id) {
+ selfStopped = true;
+ return true;
+ }
+
+ @Implementation
+ protected final void startForeground(int id, Notification notification) {
foregroundStopped = false;
- lastForegroundNotificationId = id;
+ lastForegroundNotificationId = id;
lastForegroundNotification = notification;
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
NotificationManager nm = (NotificationManager)RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -46,7 +52,7 @@
}
@Implementation
- public void stopForeground(boolean removeNotification) {
+ protected void stopForeground(boolean removeNotification) {
foregroundStopped = true;
notificationShouldRemoved = removeNotification;
if (removeNotification) {
@@ -56,14 +62,14 @@
private void removeForegroundNotification() {
NotificationManager nm = (NotificationManager)RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
- nm.cancel(lastForegroundNotificationId);
+ nm.cancel(lastForegroundNotificationId);
lastForegroundNotification = null;
}
-
+
public int getLastForegroundNotificationId() {
return lastForegroundNotificationId;
}
-
+
public Notification getLastForegroundNotification() {
return lastForegroundNotification;
}