statusbar_SIM卡信号强度

时间:2021-08-26 04:34:29

4.3

CT模式SIM卡信号刷新——信号柱强度( mMSimPhoneSignalIconId):

1:

//信号更新
    private final void updateTelephonySignalStrength(int subscription) {

        //服务状态(对应语音服务状态)是无服务或者 紧急呼叫,同时数据服务状态是无服务
    if ((!hasService(subscription) || mMSimServiceState[subscription].getState() == ServiceState.STATE_EMERGENCY_ONLY) &&
                (mMSimDataServiceState[subscription] != ServiceState.STATE_IN_SERVICE)) {
            if (DEBUG) Slog.d(TAG, " No service");
            for (int i = 0; i < SIGNAL_ICON_NUM; i++) {
                mMSimPhoneSignalIconId[subscription][i] = R.drawable.stat_sys_signal_null;
            }
            mMSimQSPhoneSignalIconId[subscription] = R.drawable.ic_qs_signal_no_signal;
            mMSimDataSignalIconId[subscription] = R.drawable.stat_sys_signal_null;
        } 

         //否则

        else {

            //SIM卡信号强度或者服务状态是null
            if (mMSimSignalStrength[subscription] == null
                    || (mMSimServiceState[subscription] == null)) {
                if (DEBUG) {
                    Slog.d(TAG, " Null object, mMSimSignalStrength= "
                            + mMSimSignalStrength[subscription]
                            + " mMSimServiceState " + mMSimServiceState[subscription]);
                }
                for (int i = 0; i < SIGNAL_ICON_NUM; i++) {
                    mMSimPhoneSignalIconId[subscription][i] = R.drawable.stat_sys_signal_null;
                }
                mMSimDataSignalIconId[subscription] = R.drawable.stat_sys_signal_null;
                mMSimQSPhoneSignalIconId[subscription] = R.drawable.ic_qs_signal_no_signal;
                mMSimContentDescriptionPhoneSignal[subscription] = mContext.getString(
                        AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0]);
            }

               //否则

               else {
                int iconLevel;
                int[] iconList;

                //判断是否漫游
                if (((MSimTelephonyManager) mPhone).isNetworkRoaming(subscription)) {

                    // 漫游时根据数据是否连接使用mInetCondition取得对应的强度组图(4张)
                    iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_ROAMING[mInetCondition];
                    mIsRoaming[subscription] = true;
                    if (DEBUG) {
                        Slog.d(TAG, "The sub" + subscription + " is in roaming state.");
                    }
                } else {
                    mIsRoaming[subscription] = false;

                   //非漫游时根据数据是否连接使用mInetCondition取得对应的强度组图(4张)

                    iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH[mInetCondition];  
                }

              /* TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH 和 TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_ROAMING图组一样*/

                //CT模式特殊处理
                // As isNetworkRoaming() is for GSM purposes, check CDMA roaming here.
                if (PhoneStatusBar.STATUSBAR_STYLE == PhoneStatusBar.STATUSBAR_STYLE_CT) {
                    if (isCdma(subscription) && isCdmaEri(subscription)) {
                        iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_ROAMING[mInetCondition];
                        mIsRoaming[subscription] = true;
                        if (DEBUG) {
                            Slog.d(TAG, "The sub" + subscription + " is in CDMA roaming state.");
                        }
                    }
                }

                //cdma信号
                if (isCdma(subscription)) {

                    //mAlwaysShowCdmaRssi = true始终显示为cdma1X,信号图标见附图2
                    if (mAlwaysShowCdmaRssi) {
                        iconLevel = mMSimSignalStrength[subscription].getCdmaLevel();
                        mLastSignalLevel = iconLevel;


                        //根据卡槽subscription和信号强度具体值赋值当前信号强度应该更新哪一张图mMSimPhoneSignalIconId
                        mMSimPhoneSignalIconId[subscription][FIRST_SIGNAL_ICON] = iconList[iconLevel];

                       //第二个值赋值0备用
                        mMSimPhoneSignalIconId[subscription][SECOND_SIGNAL_ICON] = 0;
                    } else {
                        int cdmaLevel = mMSimSignalStrength[subscription].getCdmaLevel();//获取cdma信号强度
                        int evdoLevel = mMSimSignalStrength[subscription].getEvdoLevel();//一个CDMA载频上只支持数据传输
                        if (DEBUG) {
                        Slog.i(TAG, "updateTelephonySignalStrength cdmaLevel="
                                + cdmaLevel + " evdoLevel=" + evdoLevel);
                        }
                        // Though mPhone is a Manager, this call is not an IPC
                    

                              //根据卡槽subscription和cdma信号强度具体值赋值当前信号强度应该更新哪一张图mMSimPhoneSignalIconId
                             mMSimPhoneSignalIconId[subscription][FIRST_SIGNAL_ICON]  =   iconList[cdmaLevel];

                             // //第二个值赋值evdo信号强度
                             mMSimPhoneSignalIconId[subscription][SECOND_SIGNAL_ICON] = iconList[evdoLevel];
                             iconLevel = (evdoLevel != 0) ? evdoLevel : cdmaLevel;
                    }
                    if (DEBUG) {
                        Slog.d(TAG, "mAlwaysShowCdmaRssi = " + mAlwaysShowCdmaRssi
                                + " set to cdmaLevel= "
                                + mMSimSignalStrength[subscription].getCdmaLevel()
                                + " instead of level= "
                                + mMSimSignalStrength[subscription].getLevel());
                    }
                }

                    //not  cdma信号

                     else {
                    mLastSignalLevel = iconLevel = mMSimSignalStrength[subscription].getLevel();
                    mMSimPhoneSignalIconId[subscription][FIRST_SIGNAL_ICON] = iconList[iconLevel];
                    mMSimPhoneSignalIconId[subscription][SECOND_SIGNAL_ICON] = 0;
                }


                mMSimQSPhoneSignalIconId[subscription] =
                        TelephonyIcons.QS_TELEPHONY_SIGNAL_STRENGTH[mInetCondition][iconLevel];


                mMSimContentDescriptionPhoneSignal[subscription] = mContext.getString(
                        AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[iconLevel]);


                mMSimDataSignalIconId[subscription] = TelephonyIcons
                        .DATA_SIGNAL_STRENGTH[mInetCondition][iconLevel];
            }
        }
    }
    
    2:刷新使用接口传递信号值
     protected void refreshViews(int subscription) {
     .............................
    if (!mHasMobileDataFeature) {
            mMSimDataSignalIconId[subscription] = 0;
            mMSimQSPhoneSignalIconId[subscription] = 0;
            for (int i = 0; i < SIGNAL_ICON_NUM; i++) {
                mMSimPhoneSignalIconId[subscription][i] = 0;
            }
            mobileLabel = "";
        } else {
    }
        
        .................................
        if (mAirplaneMode &&
                (mMSimServiceState[subscription] == null || (!hasService(subscription)
                    && !mMSimServiceState[subscription].isEmergencyOnly()))) {
            // Only display the flight-mode icon if not in "emergency calls only" mode.


            // look again; your radios are now airplanes
            mMSimContentDescriptionPhoneSignal[subscription] = mContext.getString(
                    R.string.accessibility_airplane_mode);
            mAirplaneIconId = R.drawable.stat_sys_signal_flightmode;
            for (int i = 0; i < SIGNAL_ICON_NUM; i++) {
                mMSimPhoneSignalIconId[subscription][i] = 0;
            }
            mMSimDataSignalIconId[subscription] = 0;
            mMSimDataTypeIconId[subscription] = 0;
            mNoMSimIconId[subscription] = 0;
            mMSimQSPhoneSignalIconId[subscription] = 0;
            mMSimQSDataTypeIconId[subscription] = 0;
       }
            ............................
            
                    // mMSimcombinedActivityIconId is not in use, change it to mMSimDataDirectionIconId
        if (mMSimLastPhoneSignalIconId[subscription][FIRST_SIGNAL_ICON]
                != mMSimPhoneSignalIconId[subscription][FIRST_SIGNAL_ICON]
                || mMSimLastPhoneSignalIconId[subscription][SECOND_SIGNAL_ICON]
                        != mMSimPhoneSignalIconId[subscription][SECOND_SIGNAL_ICON]
                || mLastDataDirectionOverlayIconId != mMSimcombinedActivityIconId[subscription]
                || mLastWifiIconId != mWifiIconId
                || mLastWimaxIconId != mWimaxIconId
                || mMSimLastDataTypeIconId[subscription] != mMSimDataTypeIconId[subscription]
                || mLastAirplaneMode != mAirplaneMode
                || mIsLastRoaming[subscription] != mIsRoaming[subscription]
                || mMSimLastSimIconId[subscription]!= mNoMSimIconId[subscription]
                || mMSimLastDataConnected[subscription]!= mMSimDataConnected[subscription]
                || mMSimLastServiceState[subscription] != mMSimServiceState[subscription]) {
            // NB: the mLast*s will be updated later
            for (MSimSignalCluster cluster : mSimSignalClusters) {
                cluster.setWifiIndicators(
                        mWifiEnabled && (mWifiConnected || !mHasMobileDataFeature  || mAppopsStrictEnabled),
                        mWifiIconId,
                        mWifiActivityIconId,
                        mContentDescriptionWifi);

                //调用接口传递信号强度值
                cluster.setMobileDataIndicators(
                        mHasMobileDataFeature,
                        mMSimPhoneSignalIconId[subscription],
                        mMSimMobileActivityIconId[subscription],
                        mMSimDataTypeIconId[subscription],
                        mMSimContentDescriptionPhoneSignal[subscription],
                        mMSimContentDescriptionDataType[subscription],
                        mNoMSimIconId[subscription], subscription,
                        mMSimServiceState[subscription],
                        mIsRoaming[subscription],
                        mMSimDataConnected[subscription]);
                cluster.setIsAirplaneMode(mAirplaneMode,mAirplaneIconId);
            }
            for (NetworkSignalChangedCallback cb : mSignalsChangedCallbacks) {
                notifySignalsChangedCallbacks(cb);
            }
            for (NetworkSignalChangedCallback cb : mSignalsChangedCallbacks) {
                notifySignalsChangedCallbacks(cb);
            }
        }
   }




3:接口实现是

    //  int[] strengthIcon 是长度为2的一维数组
    public void setMobileDataIndicators(boolean visible, int[] strengthIcon, int activityIcon,
            int typeIcon, String contentDescription, String typeContentDescription,
            int noSimIcon, int subscription, ServiceState simServiceState, boolean isRoaming,
            boolean dataConnect) {
        if (DEBUG) {
            Log.i(TAG, "setMobileDataIndicators subscription=" + subscription);
        }
        mMobileVisible = visible;
        isSimRoam[subscription] = isRoaming;
        dataConnected[subscription] = dataConnect;

        //卡槽2,非电信卡
        if (subscription == MSimConstants.SUB2) {
            mMobileStrengthId[subscription][0] = getSub1SignalId(strengthIcon[0], isRoaming);
            mMobileStrengthId[subscription][1] = 0;
        } else {
            //电信卡槽  显示见图3

            //hasEvdo 标示evdo是否有信号且有强度(信号在使用)
            boolean hasEvdo = (strengthIcon[1] != R.drawable.stat_sys_signal_0)
                    && (strengthIcon[1] != R.drawable.stat_sys_signal_0_fully)
                    && (strengthIcon[1] != 0);

            // mMobileStrengthId根据卡槽是变为长度为2的一维数组
            mMobileStrengthId[subscription][0] = getSub0SignalId(strengthIcon[0], hasEvdo, false,
                    isRoaming);
            mMobileStrengthId[subscription][1] = hasEvdo ? getSub0SignalId(strengthIcon[1],
                    hasEvdo, true, isRoaming) : 0;
        }
        if (DEBUG) {
            Log.i(TAG, "setMobileDataIndicators mMobileStrengthId[0]="
                    + mMobileStrengthId[subscription][0]
                    + " mMobileStrengthId[1]=" + mMobileStrengthId[subscription][1]);
        }


        mMobileActivityId[subscription] =
                getAcitivyTypeIconId(typeIcon, activityIcon, subscription, isRoaming);
        mMobileDescription[subscription] = contentDescription;
        mMobileTypeDescription = typeContentDescription;
        mNoSimIconId[subscription] = convertNoSimIconIdToCT(subscription);
        mServiceState[subscription] = simServiceState;


        if (noSimIcon != 0) {
            mMNoSimIconVisible[subscription] = true;
            mSignalIconVisible[subscription] = false;
        } else {
            mMNoSimIconVisible[subscription] = false;
            mSignalIconVisible[subscription] = true;
        }


        if (DEBUG)
            Log.i(TAG, "SetMobileDataIndicators MNoSimIconVisible " + subscription + "="
                    + mMNoSimIconVisible[subscription]);


        applySubscription(subscription);
    }
    
    
    4: //非电信卡槽信号赋值
        private int getSub1SignalId(int originalId, boolean isRoaming) {
        switch (originalId) {
            case R.drawable.stat_sys_signal_0:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[0][0];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[0][0];
            case R.drawable.stat_sys_signal_1:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[0][1];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[0][1];
            case R.drawable.stat_sys_signal_2:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[0][2];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[0][2];
            case R.drawable.stat_sys_signal_3:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[0][3];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[0][3];
            case R.drawable.stat_sys_signal_4:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[0][4];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[0][4];
            case R.drawable.stat_sys_signal_0_fully:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[1][0];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[1][0];
            case R.drawable.stat_sys_signal_1_fully:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[1][1];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[1][1];
            case R.drawable.stat_sys_signal_2_fully:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[1][2];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[1][2];
            case R.drawable.stat_sys_signal_3_fully:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[1][3];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[1][3];
            case R.drawable.stat_sys_signal_4_fully:
                if (isRoaming) {
                    return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_R_CT[1][4];
                }
                return TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_G_CT[1][4];
            case R.drawable.stat_sys_signal_null:
                return convertSignalNullIconIdToCT(1);
            default:
                return originalId;
        }
    }
    
    5:
        //GSM/UMTS
    static final int[][] TELEPHONY_SIGNAL_STRENGTH = {
        { R.drawable.stat_sys_signal_0,
          R.drawable.stat_sys_signal_1,
          R.drawable.stat_sys_signal_2,
          R.drawable.stat_sys_signal_3,
          R.drawable.stat_sys_signal_4 },
        { R.drawable.stat_sys_signal_0_fully,
          R.drawable.stat_sys_signal_1_fully,
          R.drawable.stat_sys_signal_2_fully,
          R.drawable.stat_sys_signal_3_fully,
          R.drawable.stat_sys_signal_4_fully }
    };
    
        static final int[][] TELEPHONY_SIGNAL_STRENGTH_ROAMING = {
        { R.drawable.stat_sys_signal_0,
          R.drawable.stat_sys_signal_1,
          R.drawable.stat_sys_signal_2,
          R.drawable.stat_sys_signal_3,
          R.drawable.stat_sys_signal_4 },
        { R.drawable.stat_sys_signal_0_fully,
          R.drawable.stat_sys_signal_1_fully,
          R.drawable.stat_sys_signal_2_fully,
          R.drawable.stat_sys_signal_3_fully,
          R.drawable.stat_sys_signal_4_fully }
    };


图2:

statusbar_SIM卡信号强度



图3:

statusbar_SIM卡信号强度


other:

statusbar_SIM卡信号强度