• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.car.settings.enterprise;
18 
19 import android.app.admin.DevicePolicyManager;
20 import android.car.drivingstate.CarUxRestrictions;
21 import android.content.ComponentName;
22 import android.content.Context;
23 
24 import androidx.preference.Preference;
25 
26 import com.android.car.settings.R;
27 import com.android.car.settings.common.FragmentController;
28 
29 /**
30  * Controller for the warning info preference the device admin details screen.
31  */
32 public final class DeviceAdminAddWarningPreferenceController
33         extends BaseDeviceAdminAddPreferenceController<Preference> {
34 
DeviceAdminAddWarningPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)35     public DeviceAdminAddWarningPreferenceController(Context context, String preferenceKey,
36             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
37         super(context, preferenceKey, fragmentController, uxRestrictions);
38     }
39 
40     @Override
updateState(Preference preferenceGroup)41     protected void updateState(Preference preferenceGroup) {
42         Context context = getContext();
43         ComponentName admin = mDeviceAdminInfo.getComponent();
44 
45         CharSequence title = null;
46         boolean isProfileOwner = admin.equals(mDpm.getProfileOwner());
47         if (isProfileOwner || admin.equals(mDpm.getDeviceOwnerComponentOnCallingUser())) {
48             // Profile owner in a user or device owner, user can't disable admin.
49             if (isProfileOwner) {
50                 // Show profile owner in a user description.
51                 title = context.getString(R.string.admin_profile_owner_user_message);
52             } else {
53                 // Show device owner description.
54                 if (isFinancedDevice()) {
55                     title = context.getString(R.string.admin_financed_message);
56                 } else {
57                     title = context.getString(R.string.admin_device_owner_message);
58                 }
59             }
60         } else {
61             int resId = mDpm.isAdminActive(admin) ? R.string.device_admin_status
62                     : R.string.device_admin_warning;
63             CharSequence label = mDeviceAdminInfo.getActivityInfo().applicationInfo.loadLabel(mPm);
64             title = context.getString(resId, label);
65         }
66         if (title == null) {
67             mLogger.v("no warning message");
68             return;
69         }
70 
71         preferenceGroup.setTitle(title);
72     }
73 
isFinancedDevice()74     private boolean isFinancedDevice() {
75         return mDpm.isDeviceManaged() && mDpm.getDeviceOwnerType(mDpm
76                 .getDeviceOwnerComponentOnAnyUser())
77                     == DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
78     }
79 }
80