【开发方案】Android 双卡设备手动搜网功能适配

本文介绍了Android双卡设备手动搜网功能的适配过程,涉及Settings APP、Telephony Service和fw的源码逻辑,以及MTK平台的具体实现。在单卡逻辑实现中,通过BroadcastReceiver监听开机广播和SIM卡状态变化,而在MTK平台上,搜网功能由MtkSettings和EngineerMode协同完成,采用Handler机制进行异步操作。
摘要由CSDN通过智能技术生成

一、背景

存在运营商需求:当SIM卡设置中选择了自动搜网,那么在重启开机后要执行一次手动搜网。

若基于本身单卡的实现,只搜索卡槽0的,而且写成了单线程,那么就在适配双卡的过程中还需要调整设计模式。

二、源码逻辑

  1. Settings应用发送消息,Telephony 模块Handler回调方法
  2. TeleService 处理消息 EVENT_GET_NETWORK_SELECTION_MODE_DONE,并notifyRequester()
  3. TelephonyManager => MD

(一)Settings APP

packages/apps/Settings/src/com/android/settings/network/  界面

(二)Telephony Service

packages/services/Telephony/src/com/android/phone/PhoneInterfaceManager.java 业务逻辑

  • handleMessage -> notifyRequester
    /**
     * A handler that processes messages on the main thread in the phone process. Since many
     * of the Phone calls are not thread safe this is needed to shuttle the requests from the
     * inbound binder threads to the main thread in the phone process.  The Binder thread
     * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
     * on, which will be notified when the operation completes and will contain the result of the
     * request.
     *
     * <p>If a MainThreadRequest object is provided in the msg.obj field,
     * note that request.result must be set to something non-null for the calling thread to
     * unblock.
     */
    private final class MainThreadHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            MainThreadRequest request;  
            Message onCompleted;
            AsyncResult ar;
            UiccPort uiccPort;
            IccAPDUArgument iccArgument;
            final Phone defaultPhone = getDefaultPhone();
    
            switch (msg.what) {
                case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
                    //obj参数保存了一个AsyncResult对象
                    ar = (AsyncResult) msg.obj;
                    //userObj参数保存了一个MainThreadRequest对象
                    request = (MainThreadRequest) ar.userObj;
                    if (ar.exception != null) {  //异步请求异常,设置结果unknown
                        request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
                    } else {  //根据异步请求结果设置网络选择模式
                        int mode = ((int[]) ar.result)[0];
                        if (mode == 0) {  //mode0自动搜网
                            request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
                        } else {  //mode1手动搜网
                            request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
                        }
                    }
                    notifyRequester(request);  //通知请求异步操作的结果
                    break;
                default:
                    Log.w(LOG_TAG, "MainThreadH
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值