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


    一、背景

    存在运营商需求:当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
    1. /**
    2. * A handler that processes messages on the main thread in the phone process. Since many
    3. * of the Phone calls are not thread safe this is needed to shuttle the requests from the
    4. * inbound binder threads to the main thread in the phone process. The Binder thread
    5. * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
    6. * on, which will be notified when the operation completes and will contain the result of the
    7. * request.
    8. *
    9. *

      If a MainThreadRequest object is provided in the msg.obj field,

    10. * note that request.result must be set to something non-null for the calling thread to
    11. * unblock.
    12. */
    13. private final class MainThreadHandler extends Handler {
    14. @Override
    15. public void handleMessage(Message msg) {
    16. MainThreadRequest request;
    17. Message onCompleted;
    18. AsyncResult ar;
    19. UiccPort uiccPort;
    20. IccAPDUArgument iccArgument;
    21. final Phone defaultPhone = getDefaultPhone();
    22. switch (msg.what) {
    23. case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
    24. //obj参数保存了一个AsyncResult对象
    25. ar = (AsyncResult) msg.obj;
    26. //userObj参数保存了一个MainThreadRequest对象
    27. request = (MainThreadRequest) ar.userObj;
    28. if (ar.exception != null) { //异步请求异常,设置结果unknown
    29. request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
    30. } else { //根据异步请求结果设置网络选择模式
    31. int mode = ((int[]) ar.result)[0];
    32. if (mode == 0) { //mode0自动搜网
    33. request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
    34. } else { //mode1手动搜网
    35. request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
    36. }
    37. }
    38. notifyRequester(request); //通知请求异步操作的结果
    39. break;
    40. default:
    41. Lo
  • 相关阅读:
    【Redis】Zset 有序集合内部编码方式
    【JavaEE】SpringBoot 拦截器详解 (统⼀功能处理)
    大白话讲清搞好就能“年薪百万”的SpringCloud微服务
    【概率论与数理统计】计算机保研复习
    【OpenGL】纹理(Texture)的使用
    如何系统地自学RPA? RPA要怎么学?
    链表【数据结构与算法Java】
    Java面试宝典
    WEB自动化_强制等待与智能等待(显示等待、隐式等待)
    51单片机直流电机PID速度控制正反转控制(红外光电测速)LCD1602 L298N
  • 原文地址:https://blog.csdn.net/qq_38666896/article/details/136628357