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