• 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.settings.safetycenter;
18 
19 import android.content.ActivityNotFoundException;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.text.TextUtils;
23 import android.util.Log;
24 
25 import androidx.preference.Preference;
26 
27 import com.android.settings.core.BasePreferenceController;
28 
29 /** Controller for the SafetyCenter entry in top level Settings. */
30 public class TopLevelSafetyCenterEntryPreferenceController extends BasePreferenceController {
31 
32     private static final String TAG = "TopLevelSafetyCenterEntryPreferenceController";
33 
TopLevelSafetyCenterEntryPreferenceController(Context context, String preferenceKey)34     public TopLevelSafetyCenterEntryPreferenceController(Context context, String preferenceKey) {
35         super(context, preferenceKey);
36     }
37 
38     @Override
getAvailabilityStatus()39     public int getAvailabilityStatus() {
40         if (SafetyCenterManagerWrapper.get().isEnabled(mContext)) {
41             return AVAILABLE;
42         }
43         return CONDITIONALLY_UNAVAILABLE;
44     }
45 
46     @Override
handlePreferenceTreeClick(Preference preference)47     public boolean handlePreferenceTreeClick(Preference preference) {
48         if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
49             return super.handlePreferenceTreeClick(preference);
50         }
51 
52         try {
53             mContext.startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
54         } catch (ActivityNotFoundException e) {
55             Log.e(TAG, "Unable to open safety center", e);
56             return false;
57         }
58         return true;
59     }
60 }
61