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 com.android.settings.applications;
18 
19 import android.annotation.UserIdInt;
20 import android.content.Intent;
21 
22 import androidx.annotation.NonNull;
23 
24 import java.util.List;
25 import java.util.Set;
26 
27 public interface ApplicationFeatureProvider {
28 
29     /**
30      * Calculates the total number of apps installed on the device via policy in the current user
31      * and all its managed profiles.
32      *
33      * @param async    Whether to count asynchronously in a background thread
34      * @param callback The callback to invoke with the result
35      */
calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback)36     void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback);
37 
38     /**
39      * Asynchronously builds the list of apps installed on the device via policy in the current user
40      * and all its managed profiles.
41      *
42      * @param callback The callback to invoke with the result
43      */
listPolicyInstalledApps(ListOfAppsCallback callback)44     void listPolicyInstalledApps(ListOfAppsCallback callback);
45 
46     /**
47      * Asynchronously calculates the total number of apps installed in the current user and all its
48      * managed profiles that have been granted one or more of the given permissions by the admin.
49      *
50      * @param permissions Only consider apps that have been granted one or more of these
51      *                    permissions by the admin, either at run-time or install-time
52      * @param async       Whether to count asynchronously in a background thread
53      * @param callback    The callback to invoke with the result
54      */
calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions, boolean async, NumberOfAppsCallback callback)55     void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions, boolean async,
56             NumberOfAppsCallback callback);
57 
58     /**
59      * Asynchronously builds the list of apps installed in the current user and all its
60      * managed profiles that have been granted one or more of the given permissions by the admin.
61      *
62      * @param permissions Only consider apps that have been granted one or more of these
63      *                    permissions by the admin, either at run-time or install-time
64      * @param callback    The callback to invoke with the result
65      */
listAppsWithAdminGrantedPermissions(String[] permissions, ListOfAppsCallback callback)66     void listAppsWithAdminGrantedPermissions(String[] permissions, ListOfAppsCallback callback);
67 
68     /**
69      * Return the persistent preferred activities configured by the admin for the given user.
70      * A persistent preferred activity is an activity that the admin configured to always handle a
71      * given intent (e.g. open browser), even if the user has other apps installed that would also
72      * be able to handle the intent.
73      *
74      * @param userId  ID of the user for which to find persistent preferred activities
75      * @param intents The intents for which to find persistent preferred activities
76      * @return the persistent preferred activities for the given intents, ordered first by user id,
77      * then by package name
78      */
findPersistentPreferredActivities(@serIdInt int userId, Intent[] intents)79     List<UserAppInfo> findPersistentPreferredActivities(@UserIdInt int userId, Intent[] intents);
80 
81     /**
82      * Returns a list of package names that should be kept enabled.
83      */
getKeepEnabledPackages()84     Set<String> getKeepEnabledPackages();
85 
86     /**
87      * Returns a user readable text explaining how much time user has spent in an app at a
88      * pre-specified duration.
89      */
90     @NonNull
getTimeSpentInApp(String packageName)91     default CharSequence getTimeSpentInApp(String packageName) {
92         return "";
93     }
94 
95     /**
96      * @return {@code true} if the device supports the toggling of the long background task
97      * permission.
98      */
isLongBackgroundTaskPermissionToggleSupported()99     boolean isLongBackgroundTaskPermissionToggleSupported();
100 
101     /**
102      * Callback that receives the number of packages installed on the device.
103      */
104     interface NumberOfAppsCallback {
onNumberOfAppsResult(int num)105         void onNumberOfAppsResult(int num);
106     }
107 
108     /**
109      * Callback that receives the list of packages installed on the device.
110      */
111     interface ListOfAppsCallback {
onListOfAppsResult(List<UserAppInfo> result)112         void onListOfAppsResult(List<UserAppInfo> result);
113     }
114 }
115