1 /*
2  * Copyright (C) 2020 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.network.telephony;
18 
19 import android.content.Context;
20 
21 import androidx.annotation.VisibleForTesting;
22 import androidx.preference.Preference;
23 import androidx.preference.PreferenceCategory;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.BasePreferenceController;
28 import com.android.settingslib.core.lifecycle.Lifecycle;
29 import com.android.settingslib.core.lifecycle.LifecycleObserver;
30 
31 /**
32  * Preference controller for "Wifi Calling"
33  */
34 public class NetworkProviderWifiCallingPreferenceController extends
35         BasePreferenceController implements LifecycleObserver{
36 
37     private static final String TAG = "NetworkProviderWfcController";
38     private static final String PREFERENCE_CATEGORY_KEY = "provider_model_calling_category";
39 
40     private NetworkProviderWifiCallingGroup mNetworkProviderWifiCallingGroup;
41     private PreferenceCategory mPreferenceCategory;
42     private PreferenceScreen mPreferenceScreen;
43 
NetworkProviderWifiCallingPreferenceController(Context context, String key)44     public NetworkProviderWifiCallingPreferenceController(Context context, String key) {
45         super(context, key);
46     }
47 
init(Lifecycle lifecycle)48     public void init(Lifecycle lifecycle) {
49         mNetworkProviderWifiCallingGroup = createWifiCallingControllerForSub(lifecycle);
50     }
51 
52     @VisibleForTesting
createWifiCallingControllerForSub( Lifecycle lifecycle)53     protected NetworkProviderWifiCallingGroup createWifiCallingControllerForSub(
54             Lifecycle lifecycle) {
55         return new NetworkProviderWifiCallingGroup(mContext, lifecycle, PREFERENCE_CATEGORY_KEY);
56     }
57 
58     @Override
getAvailabilityStatus()59     public int getAvailabilityStatus() {
60         if (mNetworkProviderWifiCallingGroup == null
61                 || !mNetworkProviderWifiCallingGroup.isAvailable()) {
62             return UNSUPPORTED_ON_DEVICE;
63         } else {
64             return AVAILABLE;
65         }
66     }
67 
68     @Override
displayPreference(PreferenceScreen screen)69     public void displayPreference(PreferenceScreen screen) {
70         super.displayPreference(screen);
71         mPreferenceScreen = screen;
72         mPreferenceCategory = screen.findPreference(PREFERENCE_CATEGORY_KEY);
73         mPreferenceCategory.setVisible(isAvailable());
74         mNetworkProviderWifiCallingGroup.displayPreference(screen);
75     }
76 }
77