Telephony基础之UICC业务(Stk中广播来源)

总体框架: Stk的核心是1个服务,3个广播接收器
一,1个服务(StkAppService.java)

二,3个广播接收器(BootCompletedReceiver,StkCmdReceiver,StkIntentReceiver)
前面两个Receiver是AOSP原生的,为静态Reciver;最后一般是各个手机厂商订制开发新增,名字可能不同,具体实作也不同。

1,BootCompletedReceiver
注册:

<receiver android:name="com.android.stk.BootCompletedReceiver">
  <intent-filter>
  <action android:name="android.intent.action.BOOT_COMPLETED" />
  <action android:name="android.intent.action.USER_INITIALIZE" />
  </intent-filter>
</receiver>

实作:

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action == null) {
            return;
        }

        // make sure the app icon is removed every time the device boots.
        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
            Bundle args = new Bundle();
            args.putInt(StkAppService.OPCODE, StkAppService.OP_BOOT_COMPLETED);
            context.startService(new Intent(context, StkAppService.class)
                    .putExtras(args));
            CatLog.d(LOG_TAG, "[ACTION_BOOT_COMPLETED]");
        } else if(action.equals(Intent.ACTION_USER_INITIALIZE)) {
            // TODO: http://b/25155491
            if (!android.os.Process.myUserHandle().isSystem()) {
                //Disable package for all secondary users. Package is only required for device
                //owner.
                context.getPackageManager().setApplicationEnabledSetting(context.getPackageName(),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
                return;
            }
        }
    }

2,StkCmdReceiver
注册:

<receiver android:name="com.android.stk.StkCmdReceiver">
  <intent-filter>
    <action android:name= "com.android.internal.stk.command" />
    <action android:name= "com.android.internal.stk.session_end" />
    <action android:name= "com.android.internal.stk.icc_status_change" />
    <action android:name= "com.android.internal.stk.alpha_notify" />
    <action android:name= "android.intent.action.LOCALE_CHANGED" />
    <action android:name= "org.codeaurora.action.stk.idle_screen"/>
  </intent-filter>
</receiver>

实作:

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action == null) {
            return;
        }

        if (action.equals(AppInterface.CAT_CMD_ACTION)) {
            handleAction(context, intent, StkAppService.OP_CMD);
        } else if (action.equals(AppInterface.CAT_SESSION_END_ACTION)) {
            handleAction(context, intent, StkAppService.OP_END_SESSION);
        } else if (action.equals(AppInterface.CAT_ICC_STATUS_CHANGE)) {
            handleAction(context, intent, StkAppService.OP_CARD_STATUS_CHANGED);
        } else if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
            handleLocaleChange(context);
        } else if (action.equals(AppInterface.CAT_ALPHA_NOTIFY_ACTION)) {
            handleAction(context, intent, StkAppService.OP_ALPHA_NOTIFY);
        } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
            handleIdleScreen(context);
        }
    }

广播来源:在StkCmdReceiver中注册的广播主要是来自Framework UICC,包括:
AppInterface.CAT_CMD_ACTION:

CatService.java
    private void broadcastCatCmdIntent(CatCmdMessage cmdMsg) {
        Intent intent = new Intent(AppInterface.CAT_CMD_ACTION);
        intent.putExtra("STK CMD", cmdMsg);
        intent.putExtra("SLOT_ID", mSlotId);
        intent.setComponent(AppInterface.getDefaultSTKApplication());
        CatLog.d(this, "Sending CmdMsg: " + cmdMsg+ " on slotid:" + mSlotId);
        mContext.sendBroadcast(intent, AppInterface.STK_PERMISSION);
    }

AppInterface.CAT_SESSION_END_ACTION:

CatService.java
    private void handleSessionEnd() {
        CatLog.d(this, "SESSION END on "+ mSlotId);

        mCurrntCmd = mMenuCmd;
        Intent intent = new Intent(AppInterface.CAT_SESSION_END_ACTION);
        intent.putExtra("SLOT_ID", mSlotId);
        intent.setComponent(AppInterface.getDefaultSTKApplication());
        mContext.sendBroadcast(intent, AppInterface.STK_PERMISSION);
    }

AppInterface.CAT_ICC_STATUS_CHANGE:

CatService.java
    private void  broadcastCardStateAndIccRefreshResp(CardState cardState,
            IccRefreshResponse iccRefreshState) {
        Intent intent = new Intent(AppInterface.CAT_ICC_STATUS_CHANGE);
        boolean cardPresent = (cardState == CardState.CARDSTATE_PRESENT);

        if (iccRefreshState != null) {
            //This case is when MSG_ID_ICC_REFRESH is received.
            intent.putExtra(AppInterface.REFRESH_RESULT, iccRefreshState.refreshResult);
            CatLog.d(this, "Sending IccResult with Result: "
                    + iccRefreshState.refreshResult);
        }

        // This sends an intent with CARD_ABSENT (0 - false) /CARD_PRESENT (1 - true).
        intent.putExtra(AppInterface.CARD_STATUS, cardPresent);
        intent.setComponent(AppInterface.getDefaultSTKApplication());
        CatLog.d(this, "Sending Card Status: "
                + cardState + " " + "cardPresent: " + cardPresent);
        mContext.sendBroadcast(intent, AppInterface.STK_PERMISSION);
    }

AppInterface.CAT_ALPHA_NOTIFY_ACTION:

CatService.java
    private void broadcastAlphaMessage(String alphaString) {
        CatLog.d(this, "Broadcasting CAT Alpha message from card: " + alphaString);
        Intent intent = new Intent(AppInterface.CAT_ALPHA_NOTIFY_ACTION);
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        intent.putExtra(AppInterface.ALPHA_STRING, alphaString);
        intent.putExtra("SLOT_ID", mSlotId);
        intent.setComponent(AppInterface.getDefaultSTKApplication());
        mContext.sendBroadcast(intent, AppInterface.STK_PERMISSION);
    }

Intent.ACTION_LOCALE_CHANGED(略)
Intent.ACTION_SCREEN_OFF(略)

3,StkIntentReceiver(略)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值