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 package com.android.ons;
17 
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.telephony.TelephonyManager;
22 import android.util.Log;
23 
24 /**
25  * ONSProfileResultReceiver triggered when an async requests such as download subscription,
26  * activate subscription, delete subscription and switch to multi-SIM mode are processed.
27  *
28  * Received intent is forwarded to either {@link ONSProfileConfigurator} or
29  * {@link ONSProfileDownloader} based on component name param stored in Intent.
30  *
31  * BroadcastReceiver.goAsync and PendingResult.finish() methods are used to asynchronously process
32  * the received intent.
33  */
34 public class ONSProfileResultReceiver extends BroadcastReceiver {
35 
36     private static final String TAG = ONSProfileResultReceiver.class.getName();
37     public static final String EXTRA_RESULT_CODE = "ResultCode";
38 
39     @Override
onReceive(Context context, Intent intent)40     public void onReceive(Context context, Intent intent) {
41         String action = intent.getAction();
42         if (action == null) {
43             return;
44         }
45 
46         if (action.equals(TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED)) {
47             int simCount = intent.getIntExtra(TelephonyManager.EXTRA_ACTIVE_SIM_SUPPORTED_COUNT, 0);
48             Log.d(TAG, "Mutli-SIM configed for " + simCount + "SIMs");
49         } else {
50             Intent serviceIntent = new Intent(context, OpportunisticNetworkService.class);
51             serviceIntent.setAction(intent.getAction());
52             serviceIntent.putExtra(EXTRA_RESULT_CODE, getResultCode());
53             serviceIntent.putExtra(Intent.EXTRA_INTENT, intent);
54             context.startService(serviceIntent);
55             Log.d(TAG, "Service Started:" + serviceIntent.toString());
56         }
57     }
58 }
59