Android9.0 SystemUI 屏蔽打开wifi时不显示4G图标的逻辑

Android 9.0 中打开wifi时,不显示4G图标,只有信号值,现项目需求在打开wifi时仍然显示4G图标。
排查及修改过程如下:
systemui/src/com/android/systemui/statusbar/StatusBarMobileView.java

private void updateState(MobileIconState state) {
  //省略部分代码
   if (mState.typeId != state.typeId) {
            if (state.typeId != 0) {
                if (!mStatusBarExt.disableHostFunction()) {
                    mMobileType.setContentDescription(state.typeContentDescription);
                    mMobileType.setImageResource(state.typeId);
                }
                mMobileType.setVisibility(View.VISIBLE);
            } else {
                mMobileType.setVisibility(View.GONE);
            }
        }
  //省略部分代码  
}

由此可见当state.typeId=0时,会隐藏mobile_type图标,往上追溯,谁调用了updateState()方法:

public void applyMobileState(MobileIconState state) {
        //省略部分代码
        if (!mState.equals(state)) {
            updateState(state.copy());
        }
    }

一步一步查看调用关系,追溯到
systemui/src/com/android/systemui/statusbar/policy/MobileSignalController.java的notifyListeners()方法:

@Override
    public void notifyListeners(SignalCallback callback) {
    //省略部分代码
     // Show icon in QS when we are connected or data is disabled.
     boolean showDataIcon = mCurrentState.dataConnected || dataDisabled;
    //省略部分代码
    showDataIcon &= mCurrentState.isDefault || dataDisabled;
     int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.mDataType : 0;
   //省略部分代码
  callback.setMobileDataIndicators(statusIcon, qsIcon, typeIcon, networkIcon, volteIcon,
                qsTypeIcon,activityIn, activityOut, dataContentDescription, description,
                 icons.mIsWide, mSubscriptionInfo.getSubscriptionId(), mCurrentState.roaming,
                 mCurrentState.isDefaultData); 
   //省略部分代码
}

代码中有个配置:

mConfig.alwaysShowDataRatIcon

跟进去到NetworkControllerImpl.java的内部类Config:

 @VisibleForTesting
    public static class Config {
        public boolean showAtLeast3G = false;
        public boolean alwaysShowCdmaRssi = false;
        public boolean show4gForLte = false;
        public boolean hideLtePlus = false;
        public boolean hspaDataDistinguishable;
        public boolean inflateSignalStrengths = false;
        public boolean alwaysShowDataRatIcon = false;

        static Config readConfig(Context context) {
            Config config = new Config();
            //省略部分代码
            CarrierConfigManager configMgr = (CarrierConfigManager)
                    context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
            PersistableBundle b = configMgr.getConfig();
            if (b != null) {
                config.alwaysShowDataRatIcon = b.getBoolean(
                        CarrierConfigManager.KEY_ALWAYS_SHOW_DATA_RAT_ICON_BOOL);
            }
            return config;
        }
    }

然后跟踪到framework代码CarrierConfigManager.java中:

  /**
     * Boolean indicating if show data RAT icon on status bar even when data is disabled
     * @hide
     */
    public static final String KEY_ALWAYS_SHOW_DATA_RAT_ICON_BOOL =
            "always_show_data_rat_icon_bool";

  //默认值给的false
  sDefaults.putBoolean(KEY_ALWAYS_SHOW_DATA_RAT_ICON_BOOL, false);

所以修改策略为将此默认值改为true.

修改carrier_config可参考链接:
https://www.cnblogs.com/kunkka/p/8436151.html

另外可以用命令

adb shell dumpsys carrier_config

查看配置信息,配置信息如图:


aHR0cHM6Ly91cGxvYWQtaW1hZ2VzLmppYW5zaHUuaW8vdXBsb2FkX2ltYWdlcy8xODM4OTUyNC00NzE1OWE4ODJmZGQ1NDZlLnBuZw.png

你可能感兴趣的:(Android9.0 SystemUI 屏蔽打开wifi时不显示4G图标的逻辑)