diff options
| author | 2017-10-20 22:52:57 +0000 | |
|---|---|---|
| committer | 2017-10-20 22:52:57 +0000 | |
| commit | d2167ba99cbec712c988cc04a05d4a40602afd29 (patch) | |
| tree | a9c8260803ccb512d671bf6509d5f72f443a18ea | |
| parent | 59dc558e89ec20f1df49f28ed75ad48e2ab6ced3 (diff) | |
| parent | e4b5ac2f971b6697b41a5bc5d6e63770b4f0fcfe (diff) | |
Merge "Let SuggestionService receive suggestion-launched signal."
5 files changed, 72 insertions, 2 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index e33c8cf7c78c..007316fcf524 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -41102,6 +41102,7 @@ package android.service.settings.suggestions { method public android.os.IBinder onBind(android.content.Intent); method public abstract java.util.List<android.service.settings.suggestions.Suggestion> onGetSuggestions(); method public abstract void onSuggestionDismissed(android.service.settings.suggestions.Suggestion); + method public abstract void onSuggestionLaunched(android.service.settings.suggestions.Suggestion); } } diff --git a/core/java/android/service/settings/suggestions/ISuggestionService.aidl b/core/java/android/service/settings/suggestions/ISuggestionService.aidl index 423c507257c3..8dfa9c3193d3 100644 --- a/core/java/android/service/settings/suggestions/ISuggestionService.aidl +++ b/core/java/android/service/settings/suggestions/ISuggestionService.aidl @@ -17,4 +17,10 @@ interface ISuggestionService { * calls. */ void dismissSuggestion(in Suggestion suggestion) = 2; + + /** + * This is the opposite signal to {@link #dismissSuggestion}, indicating a suggestion has been + * launched. + */ + void launchSuggestion(in Suggestion suggestion) = 3; }
\ No newline at end of file diff --git a/core/java/android/service/settings/suggestions/SuggestionService.java b/core/java/android/service/settings/suggestions/SuggestionService.java index 2a4c84c2a1cf..ce9501d699ed 100644 --- a/core/java/android/service/settings/suggestions/SuggestionService.java +++ b/core/java/android/service/settings/suggestions/SuggestionService.java @@ -48,12 +48,20 @@ public abstract class SuggestionService extends Service { } @Override - public void dismissSuggestion(Suggestion suggestion) { + public void dismissSuggestion(Suggestion suggestion) { if (DEBUG) { Log.d(TAG, "dismissSuggestion() " + getPackageName()); } onSuggestionDismissed(suggestion); } + + @Override + public void launchSuggestion(Suggestion suggestion) { + if (DEBUG) { + Log.d(TAG, "launchSuggestion() " + getPackageName()); + } + onSuggestionLaunched(suggestion); + } }; } @@ -65,7 +73,12 @@ public abstract class SuggestionService extends Service { /** * Dismiss a suggestion. The suggestion will not be included in future * {@link #onGetSuggestions()} calls. - * @param suggestion */ public abstract void onSuggestionDismissed(Suggestion suggestion); + + /** + * This is the opposite signal to {@link #onSuggestionDismissed}, indicating a suggestion has + * been launched. + */ + public abstract void onSuggestionLaunched(Suggestion suggestion); } diff --git a/core/tests/coretests/src/android/service/settings/suggestions/MockSuggestionService.java b/core/tests/coretests/src/android/service/settings/suggestions/MockSuggestionService.java index c158b9f0bf71..ab541a15cdcc 100644 --- a/core/tests/coretests/src/android/service/settings/suggestions/MockSuggestionService.java +++ b/core/tests/coretests/src/android/service/settings/suggestions/MockSuggestionService.java @@ -16,11 +16,23 @@ package android.service.settings.suggestions; +import android.support.annotation.VisibleForTesting; + import java.util.ArrayList; import java.util.List; public class MockSuggestionService extends SuggestionService { + @VisibleForTesting + static boolean sOnSuggestionLaunchedCalled; + @VisibleForTesting + static boolean sOnSuggestionDismissedCalled; + + public static void reset() { + sOnSuggestionLaunchedCalled = false; + sOnSuggestionDismissedCalled = false; + } + @Override public List<Suggestion> onGetSuggestions() { final List<Suggestion> data = new ArrayList<>(); @@ -34,5 +46,11 @@ public class MockSuggestionService extends SuggestionService { @Override public void onSuggestionDismissed(Suggestion suggestion) { + sOnSuggestionDismissedCalled = true; + } + + @Override + public void onSuggestionLaunched(Suggestion suggestion) { + sOnSuggestionLaunchedCalled = true; } } diff --git a/core/tests/coretests/src/android/service/settings/suggestions/SuggestionServiceTest.java b/core/tests/coretests/src/android/service/settings/suggestions/SuggestionServiceTest.java index bc8823184417..dca8c096dc59 100644 --- a/core/tests/coretests/src/android/service/settings/suggestions/SuggestionServiceTest.java +++ b/core/tests/coretests/src/android/service/settings/suggestions/SuggestionServiceTest.java @@ -16,12 +16,17 @@ package android.service.settings.suggestions; +import static com.google.common.truth.Truth.assertThat; + import android.content.Intent; +import android.os.IBinder; +import android.os.RemoteException; import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; import android.support.test.rule.ServiceTestRule; import android.support.test.runner.AndroidJUnit4; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -45,9 +50,36 @@ public class SuggestionServiceTest { MockSuggestionService.class); } + @After + public void tearUp() { + MockSuggestionService.reset(); + } + @Test public void canStartService() throws TimeoutException { mServiceTestRule.startService(mMockServiceIntent); // Do nothing after starting service. } + + @Test + public void dismissSuggestion_shouldCallImplementation() + throws TimeoutException, RemoteException { + MockSuggestionService service = new MockSuggestionService(); + IBinder binder = mServiceTestRule.bindService(mMockServiceIntent); + ISuggestionService serviceBinder = ISuggestionService.Stub.asInterface(binder); + serviceBinder.dismissSuggestion(null); + + assertThat(service.sOnSuggestionDismissedCalled).isTrue(); + } + + @Test + public void launchSuggestion_shouldCallImplementation() + throws TimeoutException, RemoteException { + MockSuggestionService service = new MockSuggestionService(); + IBinder binder = mServiceTestRule.bindService(mMockServiceIntent); + ISuggestionService serviceBinder = ISuggestionService.Stub.asInterface(binder); + serviceBinder.launchSuggestion(null); + + assertThat(service.sOnSuggestionLaunchedCalled).isTrue(); + } } |