1 /*
2  * Copyright (C) 2007 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.stk;
18 
19 import com.android.internal.telephony.cat.AppInterface;
20 import com.android.internal.telephony.uicc.IccRefreshResponse;
21 import com.android.internal.telephony.cat.CatLog;
22 import android.content.BroadcastReceiver;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.os.Bundle;
26 
27 import com.android.internal.telephony.cat.AppInterface;
28 
29 /**
30  * Receiver class to get STK intents, broadcasted by telephony layer.
31  *
32  */
33 public class StkCmdReceiver extends BroadcastReceiver {
34 
35     @Override
onReceive(Context context, Intent intent)36     public void onReceive(Context context, Intent intent) {
37         String action = intent.getAction();
38 
39         if (action.equals(AppInterface.CAT_CMD_ACTION)) {
40             handleAction(context, intent, StkAppService.OP_CMD);
41         } else if (action.equals(AppInterface.CAT_SESSION_END_ACTION)) {
42             handleAction(context, intent, StkAppService.OP_END_SESSION);
43         } else if (action.equals(AppInterface.CAT_ICC_STATUS_CHANGE)) {
44             handleAction(context, intent, StkAppService.OP_CARD_STATUS_CHANGED);
45         } else if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
46             handleLocaleChange(context);
47         } else if (action.equals(AppInterface.CAT_ALPHA_NOTIFY_ACTION)) {
48             handleAction(context, intent, StkAppService.OP_ALPHA_NOTIFY);
49         } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
50             handleIdleScreen(context);
51         }
52     }
53 
handleAction(Context context, Intent intent, int op)54     private void handleAction(Context context, Intent intent, int op) {
55         Bundle args = new Bundle();
56         int slot_id = intent.getIntExtra(StkAppService.SLOT_ID, 0);
57 
58         args.putInt(StkAppService.OPCODE, op);
59         args.putInt(StkAppService.SLOT_ID, slot_id);
60 
61         if (StkAppService.OP_CMD == op) {
62             args.putParcelable(StkAppService.CMD_MSG, intent
63                     .getParcelableExtra(StkAppService.STK_CMD));
64         } else if (StkAppService.OP_CARD_STATUS_CHANGED == op) {
65             // If the Card is absent then check if the StkAppService is even
66             // running before starting it to stop it right away
67             if ((intent.getBooleanExtra(AppInterface.CARD_STATUS, false) == false)
68                     && StkAppService.getInstance() == null) {
69                 return;
70             }
71 
72             args.putBoolean(AppInterface.CARD_STATUS,
73                     intent.getBooleanExtra(AppInterface.CARD_STATUS, true));
74             args.putInt(AppInterface.REFRESH_RESULT,
75                     intent.getIntExtra(AppInterface.REFRESH_RESULT,
76                     IccRefreshResponse.REFRESH_RESULT_FILE_UPDATE));
77         } else if (StkAppService.OP_ALPHA_NOTIFY == op) {
78             String alphaString = intent.getStringExtra(AppInterface.ALPHA_STRING);
79             args.putString(AppInterface.ALPHA_STRING, alphaString);
80         }
81 
82         CatLog.d("StkCmdReceiver", "handleAction, op: " + op +
83                 "args: " + args + ", slot id: " + slot_id);
84         Intent toService = new Intent(context, StkAppService.class);
85         toService.putExtras(args);
86         context.startService(toService);
87     }
88 
handleLocaleChange(Context context)89     private void handleLocaleChange(Context context) {
90         Bundle args = new Bundle();
91         args.putInt(StkAppService.OPCODE, StkAppService.OP_LOCALE_CHANGED);
92         context.startService(new Intent(context, StkAppService.class)
93                 .putExtras(args));
94     }
95 
handleIdleScreen(Context context)96     private void handleIdleScreen(Context context) {
97         Bundle args = new Bundle();
98         args.putInt(StkAppService.OPCODE, StkAppService.OP_IDLE_SCREEN);
99         context.startService(new Intent(context, StkAppService.class)
100                 .putExtras(args));
101     }
102 }
103