1 /*
2  * Copyright (C) 2023 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 
17 package com.android.car.carlauncher.recents;
18 
19 import android.app.Activity;
20 import android.content.ComponentName;
21 import android.content.Intent;
22 import android.graphics.Bitmap;
23 import android.graphics.Rect;
24 import android.graphics.drawable.Drawable;
25 
26 import androidx.annotation.NonNull;
27 import androidx.annotation.Nullable;
28 
29 import java.util.List;
30 
31 public interface RecentTasksProviderInterface {
32     /**
33      * Loads recent tasks, icons and thumbnails from the system asynchronously and calls
34      * {@link RecentsDataChangeListener} callbacks to communicate the result.
35      */
getRecentTasksAsync()36     void getRecentTasksAsync();
37 
38     /**
39      * @return list of {@code taskId} for recent tasks synchronously. An empty list is
40      * returned if the tasks were never fetched from the system.
41      */
42     @NonNull
getRecentTaskIds()43     List<Integer> getRecentTaskIds();
44 
45     /**
46      * @return {@link ComponentName} for the requested {@code taskId} or null.
47      */
48     @Nullable
getRecentTaskComponentName(int taskId)49     ComponentName getRecentTaskComponentName(int taskId);
50 
51     /**
52      * @return the base intent used to launch the task for the requested {@code taskId} or null.
53      */
54     @Nullable
getRecentTaskBaseIntent(int taskId)55     Intent getRecentTaskBaseIntent(int taskId);
56 
57     /**
58      * @return {@link Drawable} icon for the requested {@code taskId} or null.
59      */
60     @Nullable
getRecentTaskIcon(int taskId)61     Drawable getRecentTaskIcon(int taskId);
62 
63     /**
64      * @return {@link Bitmap} thumbnail for the requested {@code taskId} or null.
65      */
66     @Nullable
getRecentTaskThumbnail(int taskId)67     Bitmap getRecentTaskThumbnail(int taskId);
68 
69     /**
70      * @return thumbnail insets for the requested {@code taskId} or new Rect object.
71      */
72     @NonNull
getRecentTaskInsets(int taskId)73     Rect getRecentTaskInsets(int taskId);
74 
75     /**
76      * @param taskId The {@code taskId} of the recent task to be opened.
77      * @return if the recent task with {@code taskId} was successfully opened.
78      */
openRecentTask(int taskId)79     boolean openRecentTask(int taskId);
80 
81     /**
82      * Attempts to open the top running task after {@code recentsActivity} for the given display id.
83      * For instance, For {@code recentsActivity} R and other tasks A and B in this order: R,A,B;
84      * this method will attempt to open A.
85      * If the display associated with the given {@code displayId} doesn't contain the
86      * {@code recentsActivity} in the top running tasks, the method will not attempt to open the top
87      * task and return false.
88      *
89      * @param recentsActivity {@link Activity} that is responsible to show recent tasks.
90      * @param displayId       the display's id where {@code recentsActivity} is drawn.
91      * @return if the top task was found and opened.
92      */
openTopRunningTask(@onNull Class<? extends Activity> recentsActivity, int displayId)93     boolean openTopRunningTask(@NonNull Class<? extends Activity> recentsActivity, int displayId);
94 
95     /**
96      * @param taskId the {@code taskId} of the recent task to be removed from recents.
97      */
removeTaskFromRecents(int taskId)98     void removeTaskFromRecents(int taskId);
99 
100     /**
101      * Removes all tasks from recents and clears cached data by calling {@link #clearCache}.
102      */
removeAllRecentTasks()103     void removeAllRecentTasks();
104 
105     /**
106      * clears cached data.
107      */
clearCache()108     void clearCache();
109 
110     /**
111      * @param listener to notify changes to. Set it to null to remove the listener.
112      */
setRecentsDataChangeListener(@ullable RecentsDataChangeListener listener)113     void setRecentsDataChangeListener(@Nullable RecentsDataChangeListener listener);
114 
115     /**
116      * Listener used to convey changes to the task list or task properties.
117      */
118     interface RecentsDataChangeListener {
119         /**
120          * Notifies the tasks were fetched/loaded from the system.
121          */
recentTasksFetched()122         void recentTasksFetched();
123 
124         /**
125          * Notifies the task's thumbnail was fetched/loaded from the system.
126          *
127          * @param taskId the {@code taskId} of the task whose thumbnail changed.
128          */
recentTaskThumbnailChange(int taskId)129         void recentTaskThumbnailChange(int taskId);
130 
131         /**
132          * Notifies the task's icon was fetched/loaded from the system.
133          *
134          * @param taskId the {@code taskId} of the Task whose icon changed.
135          */
recentTaskIconChange(int taskId)136         void recentTaskIconChange(int taskId);
137     }
138 }
139