1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.service.settings.suggestions;
18
19import android.annotation.SystemApi;
20import android.app.Service;
21import android.content.Intent;
22import android.os.IBinder;
23import android.util.Log;
24
25import java.util.List;
26
27/**
28 * This is the base class for implementing suggestion service. A suggestion service is responsible
29 * to provide a collection of {@link Suggestion}s for the current user when queried.
30 *
31 * @hide
32 */
33@SystemApi
34public abstract class SuggestionService extends Service {
35
36    private static final String TAG = "SuggestionService";
37    private static final boolean DEBUG = false;
38
39    @Override
40    public IBinder onBind(Intent intent) {
41        return new ISuggestionService.Stub() {
42            @Override
43            public List<Suggestion> getSuggestions() {
44                if (DEBUG) {
45                    Log.d(TAG, "getSuggestions() " + getPackageName());
46                }
47                return onGetSuggestions();
48            }
49
50            @Override
51            public void dismissSuggestion(Suggestion suggestion) {
52                if (DEBUG) {
53                    Log.d(TAG, "dismissSuggestion() " + getPackageName());
54                }
55                onSuggestionDismissed(suggestion);
56            }
57
58            @Override
59            public void launchSuggestion(Suggestion suggestion) {
60                if (DEBUG) {
61                    Log.d(TAG, "launchSuggestion() " + getPackageName());
62                }
63                onSuggestionLaunched(suggestion);
64            }
65        };
66    }
67
68    /**
69     * Return all available suggestions.
70     */
71    public abstract List<Suggestion> onGetSuggestions();
72
73    /**
74     * Dismiss a suggestion. The suggestion will not be included in future
75     * {@link #onGetSuggestions()} calls.
76     */
77    public abstract void onSuggestionDismissed(Suggestion suggestion);
78
79    /**
80     * This is the opposite signal to {@link #onSuggestionDismissed}, indicating a suggestion has
81     * been launched.
82     */
83    public abstract void onSuggestionLaunched(Suggestion suggestion);
84}
85