• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 package com.android.settings.enterprise;
15 
16 import static android.app.admin.DevicePolicyResources.Strings.Settings.NUMBER_OF_DEVICE_ADMINS_NONE;
17 
18 import android.app.admin.DevicePolicyManager;
19 import android.content.Context;
20 
21 import com.android.settings.R;
22 import com.android.settings.core.BasePreferenceController;
23 import com.android.settings.overlay.FeatureFactory;
24 
25 
26 public class ManageDeviceAdminPreferenceController extends BasePreferenceController {
27 
28     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
29     private final DevicePolicyManager mDevicePolicyManager;
30 
ManageDeviceAdminPreferenceController(Context context, String key)31     public ManageDeviceAdminPreferenceController(Context context, String key) {
32         super(context, key);
33         mFeatureProvider = FeatureFactory.getFactory(context)
34                 .getEnterprisePrivacyFeatureProvider(context);
35         mDevicePolicyManager =
36                 mContext.getSystemService(DevicePolicyManager.class);
37     }
38 
39     @Override
getSummary()40     public CharSequence getSummary() {
41         final int activeAdmins
42                 = mFeatureProvider.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile();
43 
44         if (activeAdmins == 0) {
45             return mDevicePolicyManager.getResources().getString(NUMBER_OF_DEVICE_ADMINS_NONE,
46                     () -> mContext.getResources().getString(R.string.number_of_device_admins_none));
47         }
48 
49         // TODO: override
50         return mContext.getResources().getQuantityString(R.plurals.number_of_device_admins,
51                         activeAdmins, activeAdmins);
52     }
53 
54     @Override
getAvailabilityStatus()55     public int getAvailabilityStatus() {
56         return mContext.getResources().getBoolean(R.bool.config_show_manage_device_admin)
57                 ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
58     }
59 
60 }
61