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.Activity;
20 import android.content.Context;
21 
22 import androidx.annotation.VisibleForTesting;
23 
24 import com.android.car.settings.R;
25 import com.android.car.settings.common.Logger;
26 import com.android.car.settings.common.SettingsFragment;
27 
28 /** Displays privacy information about the device owner.*/
29 public final class EnterprisePrivacySettingsFragment extends SettingsFragment {
30 
31     private final Logger mLogger = new Logger(getClass());
32 
33     @Override
getPreferenceScreenResId()34     protected int getPreferenceScreenResId() {
35         return R.xml.enterprise_privacy_settings_fragment;
36     }
37 
38     @Override
onAttach(Context context)39     public void onAttach(Context context) {
40         super.onAttach(context);
41 
42         // Split in 2 as it would be hard to mock requireActivity();
43         onAttach(context, requireActivity());
44     }
45 
46     @VisibleForTesting
onAttach(Context context, Activity activity)47     void onAttach(Context context, Activity activity) {
48         if (!EnterpriseUtils.hasDeviceOwner(context)) {
49             mLogger.d("finishing " + activity + " because there is no device owner");
50             activity.finish();
51             return;
52         }
53     }
54 }
55