• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         if (action == null) {
39             return;
40         }
41 
42         if (action.equals(AppInterface.CAT_CMD_ACTION)) {
43             handleAction(context, intent, StkAppService.OP_CMD);
44         } else if (action.equals(AppInterface.CAT_SESSION_END_ACTION)) {
45             handleAction(context, intent, StkAppService.OP_END_SESSION);
46         } else if (action.equals(AppInterface.CAT_ICC_STATUS_CHANGE)) {
47             handleAction(context, intent, StkAppService.OP_CARD_STATUS_CHANGED);
48         } else if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
49             handleLocaleChange(context);
50         } else if (action.equals(AppInterface.CAT_ALPHA_NOTIFY_ACTION)) {
51             handleAction(context, intent, StkAppService.OP_ALPHA_NOTIFY);
52         } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
53             handleIdleScreen(context);
54         }
55     }
56 
handleAction(Context context, Intent intent, int op)57     private void handleAction(Context context, Intent intent, int op) {
58         Bundle args = new Bundle();
59         int slot_id = intent.getIntExtra(StkAppService.SLOT_ID, 0);
60 
61         args.putInt(StkAppService.OPCODE, op);
62         args.putInt(StkAppService.SLOT_ID, slot_id);
63 
64         if (StkAppService.OP_CMD == op) {
65             args.putParcelable(StkAppService.CMD_MSG, intent
66                     .getParcelableExtra(StkAppService.STK_CMD));
67         } else if (StkAppService.OP_CARD_STATUS_CHANGED == op) {
68             // If the Card is absent then check if the StkAppService is even
69             // running before starting it to stop it right away
70             if ((intent.getBooleanExtra(AppInterface.CARD_STATUS, false) == false)
71                     && StkAppService.getInstance() == null) {
72                 return;
73             }
74 
75             args.putBoolean(AppInterface.CARD_STATUS,
76                     intent.getBooleanExtra(AppInterface.CARD_STATUS, true));
77             args.putInt(AppInterface.REFRESH_RESULT,
78                     intent.getIntExtra(AppInterface.REFRESH_RESULT,
79                     IccRefreshResponse.REFRESH_RESULT_FILE_UPDATE));
80         } else if (StkAppService.OP_ALPHA_NOTIFY == op) {
81             String alphaString = intent.getStringExtra(AppInterface.ALPHA_STRING);
82             args.putString(AppInterface.ALPHA_STRING, alphaString);
83         }
84 
85         CatLog.d("StkCmdReceiver", "handleAction, op: " + op +
86                 "args: " + args + ", slot id: " + slot_id);
87         Intent toService = new Intent(context, StkAppService.class);
88         toService.putExtras(args);
89         context.startService(toService);
90     }
91 
handleLocaleChange(Context context)92     private void handleLocaleChange(Context context) {
93         Bundle args = new Bundle();
94         args.putInt(StkAppService.OPCODE, StkAppService.OP_LOCALE_CHANGED);
95         context.startService(new Intent(context, StkAppService.class)
96                 .putExtras(args));
97     }
98 
handleIdleScreen(Context context)99     private void handleIdleScreen(Context context) {
100         Bundle args = new Bundle();
101         args.putInt(StkAppService.OPCODE, StkAppService.OP_IDLE_SCREEN);
102         context.startService(new Intent(context, StkAppService.class)
103                 .putExtras(args));
104     }
105 }
106