Android P StatusBar icon更新逻辑 (2) -- wifi icon

 

1.接收wifi变化广播,执行handleBroadcast,对rssi  level更新

//NetworkControllerImpl接收广播rssi变化之类的wifi广播后,调用handleBroadcast
@/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
@Override
public void onReceive(Context context, Intent intent) {
    if (CHATTY) {
        Log.d(TAG, "onReceive: intent=" + intent);
    }
    final String action = intent.getAction();
    if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
        ...
    } else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
        ...
    } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED)) {
        ...
    } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
        ...
    } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
        ...
    } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
        ...
    } else {
        int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            ...
        } else {
            // No sub id, must be for the wifi.
            mWifiSignalController.handleBroadcast(intent);    //here
        }
    }
}

//首先执行 mWifiTracker.handleBroadcast更新rssi level等,然后赋值给systemUI
@/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiSignalController.java
/**
 * Extract wifi state directly from broadcasts about changes in wifi state.
 */
public void handleBroadcast(Intent intent) {
    // Update the WifiStatusTracker with the new information and update the score cache.
    NetworkKey previousNetworkKey = mWifiTracker.networkKey;
    mWifiTracker.handleBroadcast(intent);
    updateScoreCacheIfNecessary(previousNetworkKey);

    mCurrentState.isTransient = mWifiTracker.state == WifiManager.WIFI_STATE_ENABLING
            || mWifiTracker.state == WifiManager.WIFI_AP_STATE_DISABLING
            || mWifiTracker.connecting;
    mCurrentState.enabled = mWifiTracker.enabled;
    mCurrentState.connected = mWifiTracker.connected;
    mCurrentState.ssid = mWifiTracker.ssid;
    mCurrentState.rssi = mWifiTracker.rssi;
    mCurrentState.level = mWifiTracker.level;
    mCurrentState.badgeEnum = getWifiBadgeEnum();
    notifyListenersIfNecessary();
}

2.level  rssi真正赋值位置

//update level rssi
@/frameworks/base/packages/SettingsLib/src/com/android/settingslib/wifi/WifiStatusTracker.java
public void handleBroadcast(Intent intent) {
    String action = intent.getAction();
    if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
        state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                WifiManager.WIFI_STATE_UNKNOWN);
        enabled = state == WifiManager.WIFI_STATE_ENABLED;
        enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED;
    } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
        final NetworkInfo networkInfo = (NetworkInfo)
                intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        connecting = networkInfo != null && !networkInfo.isConnected()
                && networkInfo.isConnectedOrConnecting();
        connected = networkInfo != null && networkInfo.isConnected();
        WifiInfo info = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO) != null
                ? (WifiInfo) intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO)
                : mWifiManager.getConnectionInfo();

        // If Connected grab the signal strength and ssid.
        if (connected && info != null) {
            ssid = getSsid(info);
            String bssid = info.getBSSID();
            if ((ssid != null) && (bssid != null)) {
                // Reuse existing network key object if possible.
                if ((networkKey == null)
                        || !networkKey.wifiKey.ssid.equals(ssid)
                        || !networkKey.wifiKey.bssid.equals(bssid)) {
                    try {
                        networkKey = new NetworkKey(
                                new WifiKey(ssid, bssid));
                    } catch (IllegalArgumentException e) {
                        Log.e(TAG, "Cannot create NetworkKey", e);
                    }
                }
            } else {
                networkKey = null;
            }
        } else {
            ssid = null;
            networkKey = null;
        }
    } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
        // Default to -200 as its below WifiManager.MIN_RSSI.
        rssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
        level = WifiManager.calculateSignalLevel(rssi, 5);
    }
}

3.通过setWifiIndicators来设置wifi显示图标

可参考: Android P StatusBar icon更新逻辑 (1)

notifyListenersIfNecessary  -- notifyListeners -- setWifiIndicators  -- apply
@/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiSignalController.java
public void notifyListeners(SignalCallback callback) {
    // only show wifi in the cluster if connected or if wifi-only
    boolean wifiVisible = mCurrentState.enabled
            && (mCurrentState.connected || !mHasMobileData);
    String wifiDesc = wifiVisible ? mCurrentState.ssid : null;
    boolean ssidPresent = wifiVisible && mCurrentState.ssid != null;
    String contentDescription = getStringIfExists(getContentDescription());
    if (mCurrentState.inetCondition == 0) {
        contentDescription +=
                ("," + mContext.getString(R.string.accessibility_quick_settings_no_internet));
    }

    IconState statusIcon = new IconState(wifiVisible, getCurrentIconId(),
            Utils.getWifiBadgeResource(mCurrentState.badgeEnum), contentDescription);
    IconState qsIcon = new IconState(
            mCurrentState.connected, getQsCurrentIconId(),
            Utils.getWifiBadgeResource(mCurrentState.badgeEnum), contentDescription);
    callback.setWifiIndicators(mCurrentState.enabled, statusIcon, qsIcon,
            ssidPresent && mCurrentState.activityIn, ssidPresent && mCurrentState.activityOut,
            wifiDesc, mCurrentState.isTransient);   //setWifiIndicators
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值