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