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 private static final String LOG_TAG = 35 new Object(){}.getClass().getEnclosingClass().getSimpleName(); 36 37 @Override onReceive(Context context, Intent intent)38 public void onReceive(Context context, Intent intent) { 39 String action = intent.getAction(); 40 if (action == null) { 41 return; 42 } 43 44 if (action.equals(AppInterface.CAT_CMD_ACTION)) { 45 handleAction(context, intent, StkAppService.OP_CMD); 46 } else if (action.equals(AppInterface.CAT_SESSION_END_ACTION)) { 47 handleAction(context, intent, StkAppService.OP_END_SESSION); 48 } else if (action.equals(AppInterface.CAT_ICC_STATUS_CHANGE)) { 49 handleAction(context, intent, StkAppService.OP_CARD_STATUS_CHANGED); 50 } else if (action.equals(AppInterface.CAT_ALPHA_NOTIFY_ACTION)) { 51 handleAction(context, intent, StkAppService.OP_ALPHA_NOTIFY); 52 } 53 } 54 handleAction(Context context, Intent intent, int op)55 private void handleAction(Context context, Intent intent, int op) { 56 Bundle args = new Bundle(); 57 int slot_id = intent.getIntExtra(StkAppService.SLOT_ID, 0); 58 59 args.putInt(StkAppService.OPCODE, op); 60 args.putInt(StkAppService.SLOT_ID, slot_id); 61 62 if (StkAppService.OP_CMD == op) { 63 args.putParcelable(StkAppService.CMD_MSG, intent 64 .getParcelableExtra(StkAppService.STK_CMD)); 65 } else if (StkAppService.OP_CARD_STATUS_CHANGED == op) { 66 // If the Card is absent then check if the StkAppService is even 67 // running before starting it to stop it right away 68 if ((intent.getBooleanExtra(AppInterface.CARD_STATUS, false) == false) 69 && StkAppService.getInstance() == null) { 70 return; 71 } 72 73 args.putBoolean(AppInterface.CARD_STATUS, 74 intent.getBooleanExtra(AppInterface.CARD_STATUS, true)); 75 args.putInt(AppInterface.REFRESH_RESULT, 76 intent.getIntExtra(AppInterface.REFRESH_RESULT, 77 IccRefreshResponse.REFRESH_RESULT_FILE_UPDATE)); 78 } else if (StkAppService.OP_ALPHA_NOTIFY == op) { 79 String alphaString = intent.getStringExtra(AppInterface.ALPHA_STRING); 80 args.putString(AppInterface.ALPHA_STRING, alphaString); 81 } 82 83 CatLog.d(LOG_TAG, "handleAction, op: " + op + 84 "args: " + args + ", slot id: " + slot_id); 85 Intent toService = new Intent(context, StkAppService.class); 86 toService.putExtras(args); 87 context.startService(toService); 88 } 89 } 90