• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (C) 2017 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6  * except in compliance with the License. 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 distributed under the
11  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12  * KIND, either express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 package com.android.settings.enterprise;
16 
17 import android.content.Context;
18 import android.os.UserHandle;
19 
20 import androidx.preference.Preference;
21 
22 import com.android.settings.R;
23 import com.android.settings.applications.ApplicationFeatureProvider;
24 import com.android.settings.applications.EnterpriseDefaultApps;
25 import com.android.settings.core.PreferenceControllerMixin;
26 import com.android.settings.overlay.FeatureFactory;
27 import com.android.settings.users.UserFeatureProvider;
28 import com.android.settingslib.core.AbstractPreferenceController;
29 
30 public class EnterpriseSetDefaultAppsPreferenceController
31         extends AbstractPreferenceController implements PreferenceControllerMixin {
32 
33     private static final String KEY_DEFAULT_APPS = "number_enterprise_set_default_apps";
34     private final ApplicationFeatureProvider mApplicationFeatureProvider;
35     private final UserFeatureProvider mUserFeatureProvider;
36 
EnterpriseSetDefaultAppsPreferenceController(Context context)37     public EnterpriseSetDefaultAppsPreferenceController(Context context) {
38         super(context);
39         final FeatureFactory factory = FeatureFactory.getFactory(context);
40         mApplicationFeatureProvider = factory.getApplicationFeatureProvider(context);
41         mUserFeatureProvider = factory.getUserFeatureProvider(context);
42     }
43 
44     @Override
updateState(Preference preference)45     public void updateState(Preference preference) {
46         final int num = getNumberOfEnterpriseSetDefaultApps();
47         preference.setSummary(mContext.getResources().getQuantityString(
48                 R.plurals.enterprise_privacy_number_packages, num, num));
49     }
50 
51     @Override
isAvailable()52     public boolean isAvailable() {
53         return getNumberOfEnterpriseSetDefaultApps() > 0;
54     }
55 
56     @Override
getPreferenceKey()57     public String getPreferenceKey() {
58         return KEY_DEFAULT_APPS;
59     }
60 
getNumberOfEnterpriseSetDefaultApps()61     private int getNumberOfEnterpriseSetDefaultApps() {
62         int num = 0;
63         for (UserHandle user : mUserFeatureProvider.getUserProfiles()) {
64             for (EnterpriseDefaultApps app : EnterpriseDefaultApps.values()) {
65                 num += mApplicationFeatureProvider
66                         .findPersistentPreferredActivities(user.getIdentifier(),
67                                 app.getIntents()).size();
68             }
69         }
70         return num;
71     }
72 }
73