1 /*
2  * Copyright (C) 2022 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.settingslib.enterprise;
18 
19 
20 import android.content.ComponentName;
21 import android.content.Context;
22 import android.content.DialogInterface;
23 import android.content.Intent;
24 import android.net.Uri;
25 import android.provider.Settings;
26 import android.text.TextUtils;
27 
28 import androidx.annotation.NonNull;
29 import androidx.annotation.Nullable;
30 
31 import com.android.settingslib.RestrictedLockUtils;
32 
33 
34 final class SupervisedDeviceActionDisabledByAdminController
35         extends BaseActionDisabledByAdminController {
36     private static final String TAG = "SupervisedDeviceActionDisabledByAdminController";
37     private final String mRestriction;
38 
SupervisedDeviceActionDisabledByAdminController( DeviceAdminStringProvider stringProvider, String restriction)39     SupervisedDeviceActionDisabledByAdminController(
40             DeviceAdminStringProvider stringProvider, String restriction) {
41         super(stringProvider);
42         mRestriction = restriction;
43     }
44 
45     @Override
setupLearnMoreButton(Context context)46     public void setupLearnMoreButton(Context context) {
47 
48     }
49 
50     @Override
getAdminSupportTitle(@ullable String restriction)51     public String getAdminSupportTitle(@Nullable String restriction) {
52         return mStringProvider.getDisabledBiometricsParentConsentTitle();
53     }
54 
55     @Override
getAdminSupportContentString(Context context, @Nullable CharSequence supportMessage)56     public CharSequence getAdminSupportContentString(Context context,
57             @Nullable CharSequence supportMessage) {
58         return mStringProvider.getDisabledByParentContent();
59     }
60 
61     @Nullable
62     @Override
getPositiveButtonListener(@onNull Context context, @NonNull RestrictedLockUtils.EnforcedAdmin enforcedAdmin)63     public DialogInterface.OnClickListener getPositiveButtonListener(@NonNull Context context,
64             @NonNull RestrictedLockUtils.EnforcedAdmin enforcedAdmin) {
65         if (enforcedAdmin.component == null
66                 || TextUtils.isEmpty(enforcedAdmin.component.getPackageName())) {
67             return null;
68         }
69 
70         final Intent intent = new Intent(Settings.ACTION_MANAGE_SUPERVISOR_RESTRICTED_SETTING)
71                 .setData(new Uri.Builder()
72                         .scheme("policy")
73                         .appendPath("user_restrictions")
74                         .appendPath(mRestriction)
75                         .build())
76                 .setPackage(enforcedAdmin.component.getPackageName());
77         ComponentName resolvedSupervisionActivity =
78                 intent.resolveActivity(context.getPackageManager());
79         if (resolvedSupervisionActivity == null) {
80             return null;
81         }
82         return (dialog, which) -> {
83             context.startActivity(intent);
84         };
85     }
86 }
87