Home | History | Annotate | Download | only in stk
      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 
     22 import android.content.BroadcastReceiver;
     23 import android.content.Context;
     24 import android.content.Intent;
     25 import android.os.Bundle;
     26 
     27 /**
     28  * Receiver class to get STK intents, broadcasted by telephony layer.
     29  *
     30  */
     31 public class StkCmdReceiver extends BroadcastReceiver {
     32 
     33     @Override
     34     public void onReceive(Context context, Intent intent) {
     35         String action = intent.getAction();
     36 
     37         if (action.equals(AppInterface.CAT_CMD_ACTION)) {
     38             handleCommandMessage(context, intent);
     39         } else if (action.equals(AppInterface.CAT_SESSION_END_ACTION)) {
     40             handleSessionEnd(context, intent);
     41         } else if (action.equals(AppInterface.CAT_ICC_STATUS_CHANGE)) {
     42             handleCardStatusChange(context, intent);
     43         }
     44     }
     45 
     46     private void handleCommandMessage(Context context, Intent intent) {
     47         Bundle args = new Bundle();
     48         args.putInt(StkAppService.OPCODE, StkAppService.OP_CMD);
     49         args.putParcelable(StkAppService.CMD_MSG, intent
     50                 .getParcelableExtra("STK CMD"));
     51         context.startService(new Intent(context, StkAppService.class)
     52                 .putExtras(args));
     53     }
     54 
     55     private void handleSessionEnd(Context context, Intent intent) {
     56         Bundle args = new Bundle();
     57         args.putInt(StkAppService.OPCODE, StkAppService.OP_END_SESSION);
     58         context.startService(new Intent(context, StkAppService.class)
     59                 .putExtras(args));
     60     }
     61 
     62     private void handleCardStatusChange(Context context, Intent intent) {
     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         Bundle args = new Bundle();
     70         args.putInt(StkAppService.OPCODE, StkAppService.OP_CARD_STATUS_CHANGED);
     71         args.putBoolean(AppInterface.CARD_STATUS,
     72                 intent.getBooleanExtra(AppInterface.CARD_STATUS, true));
     73         args.putInt(AppInterface.REFRESH_RESULT,
     74                 intent.getIntExtra(AppInterface.REFRESH_RESULT,
     75                 IccRefreshResponse.REFRESH_RESULT_FILE_UPDATE));
     76         context.startService(new Intent(context, StkAppService.class)
     77                 .putExtras(args));
     78     }
     79 }
     80