StkCmdReceiver.java revision c46d8a06f810a3b5b570e43e7e0ed8b36efd23e5
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.gsm.stk.AppInterface;
20
21import android.content.BroadcastReceiver;
22import android.content.Context;
23import android.content.Intent;
24import android.os.Bundle;
25
26/**
27 * Receiver class to get STK intents, broadcasted by telephony layer.
28 *
29 */
30public class StkCmdReceiver extends BroadcastReceiver {
31
32    @Override
33    public void onReceive(Context context, Intent intent) {
34        String action = intent.getAction();
35
36        if (action.equals(AppInterface.STK_CMD_ACTION)) {
37            handleCommandMessage(context, intent);
38        } else if (action.equals(AppInterface.STK_SESSION_END_ACTION)) {
39            handleSessionEnd(context, intent);
40        }
41    }
42
43    private void handleCommandMessage(Context context, Intent intent) {
44        Bundle args = new Bundle();
45        args.putInt(StkAppService.OPCODE, StkAppService.OP_CMD);
46        args.putParcelable(StkAppService.CMD_MSG, intent
47                .getParcelableExtra("STK CMD"));
48        context.startService(new Intent(context, StkAppService.class)
49                .putExtras(args));
50    }
51
52    private void handleSessionEnd(Context context, Intent intent) {
53        Bundle args = new Bundle();
54        args.putInt(StkAppService.OPCODE, StkAppService.OP_END_SESSION);
55        context.startService(new Intent(context, StkAppService.class)
56                .putExtras(args));
57    }
58}
59