您的位置:首页 > 移动开发

Stk APP中广播来源

2017-11-19 12:49 92 查看
总体框架: 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(略)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  stk