StkCmdReceiver.java revision b3d0e61b1666e77c6254c9f2e27771369ab3f8b1
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
17package com.android.stk;
18
19import com.android.internal.telephony.cat.AppInterface;
20import com.android.internal.telephony.uicc.IccRefreshResponse;
21import com.android.internal.telephony.cat.CatLog;
22import android.content.BroadcastReceiver;
23import android.content.Context;
24import android.content.Intent;
25import android.os.Bundle;
26
27import com.android.internal.telephony.cat.AppInterface;
28
29/**
30 * Receiver class to get STK intents, broadcasted by telephony layer.
31 *
32 */
33public class StkCmdReceiver extends BroadcastReceiver {
34
35    @Override
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        }
50    }
51
52    private void handleAction(Context context, Intent intent, int op) {
53        Bundle args = new Bundle();
54        int slot_id = intent.getIntExtra(StkAppService.SLOT_ID, 0);
55
56        args.putInt(StkAppService.OPCODE, op);
57        args.putInt(StkAppService.SLOT_ID, slot_id);
58
59        if (StkAppService.OP_CMD == op) {
60            args.putParcelable(StkAppService.CMD_MSG, intent
61                    .getParcelableExtra(StkAppService.STK_CMD));
62        } else if (StkAppService.OP_CARD_STATUS_CHANGED == op) {
63            // If the Card is absent then check if the StkAppService is even
64            // running before starting it to stop it right away
65            if ((intent.getBooleanExtra(AppInterface.CARD_STATUS, false) == false)
66                    && StkAppService.getInstance() == null) {
67                return;
68            }
69
70            args.putBoolean(AppInterface.CARD_STATUS,
71                    intent.getBooleanExtra(AppInterface.CARD_STATUS, true));
72            args.putInt(AppInterface.REFRESH_RESULT,
73                    intent.getIntExtra(AppInterface.REFRESH_RESULT,
74                    IccRefreshResponse.REFRESH_RESULT_FILE_UPDATE));
75        } else if (StkAppService.OP_ALPHA_NOTIFY == op) {
76            String alphaString = intent.getStringExtra(AppInterface.ALPHA_STRING);
77            args.putString(AppInterface.ALPHA_STRING, alphaString);
78        }
79
80        CatLog.d("StkCmdReceiver", "handleAction, op: " + op +
81                "args: " + args + ", slot id: " + slot_id);
82        Intent toService = new Intent(context, StkAppService.class);
83        toService.putExtras(args);
84        context.startService(toService);
85    }
86
87    private void handleLocaleChange(Context context) {
88        Bundle args = new Bundle();
89        args.putInt(StkAppService.OPCODE, StkAppService.OP_LOCALE_CHANGED);
90        context.startService(new Intent(context, StkAppService.class)
91                .putExtras(args));
92    }
93}
94