Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2167ba9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Let SuggestionService receive suggestion-launched signal."

parents 59dc558e e4b5ac2f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
  }
}
+6 −0
Original line number Diff line number Diff line
@@ -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
+15 −2
Original line number Diff line number Diff line
@@ -54,6 +54,14 @@ public abstract class SuggestionService extends Service {
                }
                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);
}
+18 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+32 −0
Original line number Diff line number Diff line
@@ -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();
    }
}