Android 9.0 中打開wifi時(shí)尺铣,不顯示4G圖標(biāo),只有信號(hào)值争舞,現(xiàn)項(xiàng)目需求在打開wifi時(shí)仍然顯示4G圖標(biāo)凛忿。
排查及修改過程如下:
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);
}
}
//省略部分代碼
}
由此可見當(dāng)state.typeId=0時(shí),會(huì)隱藏mobile_type圖標(biāo)竞川,往上追溯店溢,誰調(diào)用了updateState()方法:
public void applyMobileState(MobileIconState state) {
//省略部分代碼
if (!mState.equals(state)) {
updateState(state.copy());
}
}
一步一步查看調(diào)用關(guān)系,追溯到
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);
//省略部分代碼
}
代碼中有個(gè)配置:
mConfig.alwaysShowDataRatIcon
跟進(jìn)去到NetworkControllerImpl.java的內(nèi)部類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";
//默認(rèn)值給的false
sDefaults.putBoolean(KEY_ALWAYS_SHOW_DATA_RAT_ICON_BOOL, false);
所以修改策略為將此默認(rèn)值改為true.
修改carrier_config可參考鏈接:
https://www.cnblogs.com/kunkka/p/8436151.html
另外可以用命令
adb shell dumpsys carrier_config
查看配置信息委乌,配置信息如圖: