• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 import android.telephony.SubscriptionInfo;
21 import android.telephony.TelephonyManager;
22 import android.util.Log;
23 
24 import androidx.annotation.NonNull;
25 
26 import com.android.internal.telephony.flags.FeatureFlags;
27 import com.android.internal.telephony.flags.FeatureFlagsImpl;
28 import com.android.settings.core.BasePreferenceController;
29 import com.android.settings.network.SubscriptionUtil;
30 
31 import java.util.List;
32 
33 /**
34  * {@link BasePreferenceController} for visibility of Encryption divider on Cellular Security
35  * settings page.
36  */
37 public class CellularSecurityEncryptionDividerController extends
38                 BasePreferenceController {
39 
40     private static final String LOG_TAG = "CellularSecurityEncryptionDividerController";
41 
42     private TelephonyManager mTelephonyManager;
43 
44     protected final FeatureFlags mFeatureFlags = new FeatureFlagsImpl();
45 
46     /**
47      * Class constructor of "Cellular Security" preference.
48      *
49      * @param context of settings
50      * @param prefKey assigned within UI entry of XML file
51      */
CellularSecurityEncryptionDividerController( @onNull Context context, @NonNull String prefKey)52     public CellularSecurityEncryptionDividerController(
53             @NonNull Context context, @NonNull String prefKey) {
54         super(context, prefKey);
55         mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
56     }
57 
58     @Override
getAvailabilityStatus()59     public int getAvailabilityStatus() {
60         if (mTelephonyManager == null) {
61             Log.w(LOG_TAG, "Telephony manager not yet initialized.");
62             mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
63         }
64 
65         // Check there are valid SIM cards which can be displayed to the user, otherwise this
66         // settings should not be shown.
67         List<SubscriptionInfo> availableSubs = SubscriptionUtil.getAvailableSubscriptions(mContext);
68         if (availableSubs.isEmpty()) {
69             return CONDITIONALLY_UNAVAILABLE;
70         }
71 
72         try {
73             mTelephonyManager.isNullCipherAndIntegrityPreferenceEnabled();
74         } catch (UnsupportedOperationException e) {
75             Log.i(LOG_TAG, "Null cipher enablement is unsupported, hiding divider: "
76                     + e.getMessage());
77             return UNSUPPORTED_ON_DEVICE;
78         } catch (Exception e) {
79             Log.e(LOG_TAG,
80                     "Failed isNullCipherAndIntegrityEnabled. Setting availability to "
81                             + "CONDITIONALLY_UNAVAILABLE. Exception: "
82                             + e.getMessage());
83             return CONDITIONALLY_UNAVAILABLE;
84         }
85         return AVAILABLE;
86     }
87 }
88