• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.phone.otasp;
17 
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.PersistableBundle;
22 import android.telephony.CarrierConfigManager;
23 import android.telephony.PhoneStateListener;
24 import android.telephony.TelephonyManager;
25 import android.util.Log;
26 
27 import com.android.internal.telephony.Phone;
28 import com.android.phone.PhoneGlobals;
29 
30 public class OtaspSimStateReceiver extends BroadcastReceiver {
31     private static final String TAG = OtaspSimStateReceiver.class.getSimpleName();
32     private static final boolean DBG = true;
33     private Context mContext;
34 
35     private PhoneStateListener mPhoneStateListener = new PhoneStateListener(){
36         @Override
37         public void onOtaspChanged(int otaspMode) {
38             logd("onOtaspChanged: otaspMode=" + otaspMode);
39             if (otaspMode == TelephonyManager.OTASP_NEEDED) {
40                 logd("otasp activation required, start otaspActivationService");
41                 mContext.startService(new Intent(mContext, OtaspActivationService.class));
42             } else if (otaspMode == TelephonyManager.OTASP_NOT_NEEDED) {
43                 OtaspActivationService.updateActivationState(mContext, true);
44             }
45         }
46     };
47 
48     /**
49      * check if OTA service provisioning activation is supported by the current carrier
50      * @return true if otasp activation is needed, false otherwise
51      */
isCarrierSupported()52     private static boolean isCarrierSupported() {
53         final Phone phone = PhoneGlobals.getPhone();
54         final Context context = phone.getContext();
55         if (context != null) {
56             PersistableBundle b = null;
57             final CarrierConfigManager configManager = (CarrierConfigManager) context
58                     .getSystemService(Context.CARRIER_CONFIG_SERVICE);
59             if (configManager != null) {
60                 b = configManager.getConfig();
61             }
62             if (b != null && b.getBoolean(
63                     CarrierConfigManager.KEY_USE_OTASP_FOR_PROVISIONING_BOOL)) {
64                 return true;
65             }
66         }
67         logd("otasp activation not needed: no supported carrier");
68         return false;
69     }
70 
71     @Override
onReceive(Context context, Intent intent)72     public void onReceive(Context context, Intent intent) {
73         mContext = context;
74         if(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(intent.getAction())) {
75             if (DBG) logd("Received intent: " + intent.getAction());
76             if (PhoneGlobals.getPhone().getIccRecordsLoaded() && isCarrierSupported()) {
77                 final TelephonyManager telephonyManager = TelephonyManager.from(context);
78                 telephonyManager.listen(mPhoneStateListener,
79                         PhoneStateListener.LISTEN_OTASP_CHANGED);
80             }
81         }
82     }
83 
logd(String s)84     private static void logd(String s) {
85         Log.d(TAG, s);
86     }
87 }
88 
89