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.content.Intent;
21 import android.os.Bundle;
22 
23 import androidx.annotation.VisibleForTesting;
24 import androidx.fragment.app.FragmentActivity;
25 
26 import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
27 
28 /**
29  * Shows a dialog explaining that an action is not enabled due to restrictions imposed by an active
30  * device administrator.
31  */
32 // TODO(b/186905050): add unit tests
33 public final class ActionDisabledByAdminActivity extends FragmentActivity {
34 
35     @VisibleForTesting
36     static final String FRAGMENT_TAG =
37             "ActionDisabledByAdminActivity.ActionDisabledByAdminDialogFragment";
38 
39     @Override
onCreate(Bundle savedInstanceState)40     protected void onCreate(Bundle savedInstanceState) {
41         super.onCreate(savedInstanceState);
42 
43         getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
44 
45         String restriction = getRestrictionFromIntent(getIntent());
46         ActionDisabledByAdminDialogFragment fragment =
47                 EnterpriseUtils.getActionDisabledByAdminDialog(this, restriction);
48         fragment.setDismissListener(res -> {
49             if (!isChangingConfigurations()) {
50                 finish();
51             }
52         });
53         fragment.show(getSupportFragmentManager(), FRAGMENT_TAG);
54     }
55 
getRestrictionFromIntent(Intent intent)56     private String getRestrictionFromIntent(Intent intent) {
57         if (intent == null) return null;
58         return intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION);
59     }
60 }
61