ApplicationFeatureProvider.java revision 09955c38659ec6e0420f90b89292585ededf6d44
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
17package com.android.settings.applications;
18
19import com.android.settings.applications.instantapps.InstantAppButtonsController;
20
21import android.app.Fragment;
22import android.content.Intent;
23import android.view.View;
24
25import java.util.Set;
26
27public interface ApplicationFeatureProvider {
28
29    /**
30     * Returns a new {@link AppHeaderController} instance to customize app header.
31     */
32    AppHeaderController newAppHeaderController(Fragment fragment, View appHeader);
33
34    /**
35     *
36     *  Returns a new {@link InstantAppButtonsController} instance for showing buttons
37     *  only relevant to instant apps.
38     */
39    InstantAppButtonsController newInstantAppButtonsController(Fragment fragment,
40            View view);
41
42    /**
43     * Calculates the total number of apps installed on the device via policy across all users
44     * and managed profiles.
45     *
46     * @param async Whether to count asynchronously in a background thread
47     * @param callback The callback to invoke with the result
48     */
49    void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback);
50
51    /**
52     * Asynchronously calculates the total number of apps installed on the device, across all users
53     * and managed profiles, that have been granted one or more of the given permissions by the
54     * admin.
55     *
56     * @param permissions Only consider apps that have been granted one or more of these permissions
57     *        by the admin, either at run-time or install-time
58     * @param async Whether to count asynchronously in a background thread
59     * @param callback The callback to invoke with the result
60     */
61    void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions, boolean async,
62            NumberOfAppsCallback callback);
63
64    /**
65     * Return the persistent preferred activities configured by the admin for the current user and
66     * all its managed profiles. A persistent preferred activity is an activity that the admin
67     * configured to always handle a given intent (e.g. open browser), even if the user has other
68     * apps installed that would also be able to handle the intent.
69     *
70     * @param intent The intents for which to find persistent preferred activities
71     *
72     * @return the persistent preferred activites for the given intent
73     */
74    Set<PersistentPreferredActivityInfo> findPersistentPreferredActivities(Intent[] intents);
75
76    /**
77     * Callback that receives the number of packages installed on the device.
78     */
79    interface NumberOfAppsCallback {
80        void onNumberOfAppsResult(int num);
81    }
82
83    public static class PersistentPreferredActivityInfo {
84        public final String packageName;
85        public final int userId;
86
87        public PersistentPreferredActivityInfo(String packageName, int userId) {
88            this.packageName = packageName;
89            this.userId = userId;
90        }
91
92        @Override
93        public boolean equals(Object other) {
94            if (!(other instanceof PersistentPreferredActivityInfo)) {
95                return false;
96            }
97            final PersistentPreferredActivityInfo otherActivityInfo
98                    = (PersistentPreferredActivityInfo) other;
99            return otherActivityInfo.packageName.equals(packageName)
100                    && otherActivityInfo.userId == userId;
101        }
102
103        @Override
104        public int hashCode() {
105            return packageName.hashCode() ^ userId;
106        }
107    }
108}
109