1 /*
2  * Copyright (C) 2016 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 android.content.pm;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.UserIdInt;
22 import android.appwidget.AppWidgetProviderInfo;
23 import android.content.ComponentName;
24 import android.content.Intent;
25 import android.content.IntentFilter;
26 import android.content.IntentSender;
27 import android.content.LocusId;
28 import android.content.pm.LauncherApps.ShortcutQuery;
29 import android.os.Bundle;
30 import android.os.ParcelFileDescriptor;
31 
32 import com.android.internal.infra.AndroidFuture;
33 
34 import java.util.List;
35 
36 /**
37  * Entry points used by {@link LauncherApps}.
38  *
39  * <p>No permission / argument checks will be performed inside.
40  * Callers must check the calling app permission and the calling package name.
41  * @hide
42  */
43 public abstract class ShortcutServiceInternal {
44     public interface ShortcutChangeListener {
onShortcutChanged(@onNull String packageName, @UserIdInt int userId)45         void onShortcutChanged(@NonNull String packageName, @UserIdInt int userId);
46     }
47 
48     public abstract List<ShortcutInfo>
getShortcuts(int launcherUserId, @NonNull String callingPackage, long changedSince, @Nullable String packageName, @Nullable List<String> shortcutIds, @Nullable List<LocusId> locusIds, @Nullable ComponentName componentName, @ShortcutQuery.QueryFlags int flags, int userId, int callingPid, int callingUid)49             getShortcuts(int launcherUserId,
50             @NonNull String callingPackage, long changedSince,
51             @Nullable String packageName, @Nullable List<String> shortcutIds,
52             @Nullable List<LocusId> locusIds, @Nullable ComponentName componentName,
53             @ShortcutQuery.QueryFlags int flags, int userId, int callingPid, int callingUid);
54 
55     /**
56      * Retrieves shortcuts asynchronously. Query will go through persistence layer (thus making the
57      * call async) if querying by shortcutIds in a specific package; otherwise it's effectively the
58      * same as calling {@link #getShortcuts}.
59      */
60     public abstract void
getShortcutsAsync(int launcherUserId, @NonNull String callingPackage, long changedSince, @Nullable String packageName, @Nullable List<String> shortcutIds, @Nullable List<LocusId> locusIds, @Nullable ComponentName componentName, @ShortcutQuery.QueryFlags int flags, int userId, int callingPid, int callingUid, AndroidFuture<List<ShortcutInfo>> cb)61             getShortcutsAsync(int launcherUserId,
62             @NonNull String callingPackage, long changedSince,
63             @Nullable String packageName, @Nullable List<String> shortcutIds,
64             @Nullable List<LocusId> locusIds, @Nullable ComponentName componentName,
65             @ShortcutQuery.QueryFlags int flags, int userId, int callingPid, int callingUid,
66             AndroidFuture<List<ShortcutInfo>> cb);
67 
68     public abstract boolean
isPinnedByCaller(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String id, int userId)69             isPinnedByCaller(int launcherUserId, @NonNull String callingPackage,
70             @NonNull String packageName, @NonNull String id, int userId);
71 
pinShortcuts(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull List<String> shortcutIds, int userId)72     public abstract void pinShortcuts(int launcherUserId,
73             @NonNull String callingPackage, @NonNull String packageName,
74             @NonNull List<String> shortcutIds, int userId);
75 
createShortcutIntents( int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId, int callingPid, int callingUid)76     public abstract Intent[] createShortcutIntents(
77             int launcherUserId, @NonNull String callingPackage,
78             @NonNull String packageName, @NonNull String shortcutId, int userId,
79             int callingPid, int callingUid);
80 
81     /**
82      * Retrieves the intents from a specified shortcut asynchronously.
83      */
createShortcutIntentsAsync( int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId, int callingPid, int callingUid, @NonNull AndroidFuture<Intent[]> cb)84     public abstract void createShortcutIntentsAsync(
85             int launcherUserId, @NonNull String callingPackage,
86             @NonNull String packageName, @NonNull String shortcutId, int userId,
87             int callingPid, int callingUid, @NonNull AndroidFuture<Intent[]> cb);
88 
addListener(@onNull ShortcutChangeListener listener)89     public abstract void addListener(@NonNull ShortcutChangeListener listener);
90 
addShortcutChangeCallback( @onNull LauncherApps.ShortcutChangeCallback callback)91     public abstract void addShortcutChangeCallback(
92             @NonNull LauncherApps.ShortcutChangeCallback callback);
93 
getShortcutIconResId(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId)94     public abstract int getShortcutIconResId(int launcherUserId, @NonNull String callingPackage,
95             @NonNull String packageName, @NonNull String shortcutId, int userId);
96 
97     /**
98      * Get the theme res ID of the starting window, it can be 0 if not specified.
99      */
getShortcutStartingThemeResName(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId)100     public abstract @Nullable String getShortcutStartingThemeResName(int launcherUserId,
101             @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId,
102             int userId);
103 
getShortcutIconFd(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId)104     public abstract ParcelFileDescriptor getShortcutIconFd(int launcherUserId,
105             @NonNull String callingPackage,
106             @NonNull String packageName, @NonNull String shortcutId, int userId);
107 
108     /**
109      * Retrieves a file descriptor from the icon in a specified shortcut asynchronously.
110      */
getShortcutIconFdAsync(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId, @NonNull AndroidFuture<ParcelFileDescriptor> cb)111     public abstract void getShortcutIconFdAsync(int launcherUserId, @NonNull String callingPackage,
112             @NonNull String packageName, @NonNull String shortcutId, int userId,
113             @NonNull AndroidFuture<ParcelFileDescriptor> cb);
114 
hasShortcutHostPermission(int launcherUserId, @NonNull String callingPackage, int callingPid, int callingUid)115     public abstract boolean hasShortcutHostPermission(int launcherUserId,
116             @NonNull String callingPackage, int callingPid, int callingUid);
117 
118     /**
119      * Returns whether or not Shortcuts are supported on Launcher Home Screen.
120      */
areShortcutsSupportedOnHomeScreen(@serIdInt int userId)121     public abstract boolean areShortcutsSupportedOnHomeScreen(@UserIdInt int userId);
122 
setShortcutHostPackage(@onNull String type, @Nullable String packageName, int userId)123     public abstract void setShortcutHostPackage(@NonNull String type, @Nullable String packageName,
124             int userId);
125 
requestPinAppWidget(@onNull String callingPackage, @NonNull AppWidgetProviderInfo appWidget, @Nullable Bundle extras, @Nullable IntentSender resultIntent, int userId)126     public abstract boolean requestPinAppWidget(@NonNull String callingPackage,
127             @NonNull AppWidgetProviderInfo appWidget, @Nullable Bundle extras,
128             @Nullable IntentSender resultIntent, int userId);
129 
isRequestPinItemSupported(int callingUserId, int requestType)130     public abstract boolean isRequestPinItemSupported(int callingUserId, int requestType);
131 
isForegroundDefaultLauncher(@onNull String callingPackage, int callingUid)132     public abstract boolean isForegroundDefaultLauncher(@NonNull String callingPackage,
133             int callingUid);
134 
cacheShortcuts(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull List<String> shortcutIds, int userId, int cacheFlags)135     public abstract void cacheShortcuts(int launcherUserId,
136             @NonNull String callingPackage, @NonNull String packageName,
137             @NonNull List<String> shortcutIds, int userId, int cacheFlags);
uncacheShortcuts(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull List<String> shortcutIds, int userId, int cacheFlags)138     public abstract void uncacheShortcuts(int launcherUserId,
139             @NonNull String callingPackage, @NonNull String packageName,
140             @NonNull List<String> shortcutIds, int userId, int cacheFlags);
141 
142     /**
143      * Retrieves all of the direct share targets that match the given IntentFilter for the specified
144      * user.
145      */
getShareTargets( @onNull String callingPackage, @NonNull IntentFilter intentFilter, int userId)146     public abstract List<ShortcutManager.ShareShortcutInfo> getShareTargets(
147             @NonNull String callingPackage, @NonNull IntentFilter intentFilter, int userId);
148 
149     /**
150      * Returns the icon Uri of the shortcut, and grants Uri read permission to the caller.
151      */
getShortcutIconUri(int launcherUserId, @NonNull String launcherPackage, @NonNull String packageName, @NonNull String shortcutId, int userId)152     public abstract String getShortcutIconUri(int launcherUserId, @NonNull String launcherPackage,
153             @NonNull String packageName, @NonNull String shortcutId, int userId);
154 
155     /**
156      * Retrieves the icon Uri of the shortcut asynchronously, and grants Uri read permission to the
157      * caller.
158      */
getShortcutIconUriAsync(int launcherUserId, @NonNull String launcherPackage, @NonNull String packageName, @NonNull String shortcutId, int userId, @NonNull AndroidFuture<String> cb)159     public abstract void getShortcutIconUriAsync(int launcherUserId,
160             @NonNull String launcherPackage, @NonNull String packageName,
161             @NonNull String shortcutId, int userId, @NonNull AndroidFuture<String> cb);
162 
isSharingShortcut(int callingUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId, @NonNull IntentFilter filter)163     public abstract boolean isSharingShortcut(int callingUserId, @NonNull String callingPackage,
164             @NonNull String packageName, @NonNull String shortcutId, int userId,
165             @NonNull IntentFilter filter);
166 }
167