Android Wi-Fi StatusBar(状态栏)流量上下行图标显示流程

 

android 8.0

android/base/packages/SystemUI/src/com/android/systemui/

statusbar/SignalClusterView.java

 

android 9.0

statusbar/StatusBarWifiView.java


与手机信号栏的控制一致, 由 

NetworkControllerImpl  和 WifiSignalControll


NetworkControllerImpl.java{
    
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) ||
            action.equals(ConnectivityManager.INET_CONDITION_ACTION)) {
           updateConnectivity();

      .........

      } else {
          // No sub id, must be for the wifi.
          mWifiSignalController.handleBroadcast(intent);
    }
}

/**
 * Update the Inet conditions and what network we are connected to.
 */
//更新 inet
private void updateConnectivity() {
mConnectedTransports.clear();
mValidatedTransports.clear();

    //获取当前网络功能接口, 得到当前连接的网络类型以及是否有效  ------查看具体api
    for (NetworkCapabilities nc :mConnectivityManager.getDefaultNetworkCapabilitiesForUser(mCurrentUserId)) {
    for (int transportType : nc.getTransportTypes()) {
                 //验证传输是否连接
                 mConnectedTransports.set(transportType);
            if (nc.hasCapability(NET_CAPABILITY_VALIDATED)) {
                    // 验证传输是否有效
                    mValidatedTransports.set(transportType);
            }
        }
    }

if (CHATTY) {
        Log.d(TAG, "updateConnectivity: mConnectedTransports=" + mConnectedTransports);
Log.d(TAG, "updateConnectivity: mValidatedTransports=" + mValidatedTransports);
}
mInetCondition = !mValidatedTransports.isEmpty();
pushConnectivityToSignals();
}


/**
 * Pushes the current connectivity state to all SignalControllers.
 */
private void pushConnectivityToSignals() {
// We want to update all the icons, all at once, for any condition change
    for (int i = 0; i < mMobileSignalControllers.size(); i++) {
         MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i);
         mobileSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports);
     }
    mWifiSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports);
    mEthernetSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports);
   }
}

 

        /frameworks/base/services/core/java/com/android/server/ConnectivityService.java

/**
 * Update the NetworkCapabilities for {
      @code networkAgent} to {
      @code networkCapabilities}
 * augmented with any stateful capabilities implied from {
      @code networkAgent}
 * (e.g., validated status and captive portal status).
 *
 * @param oldScore score of the network before any of the changes that prompted us
 *                 to call this function.
 * @param nai the network having its capabilities updated.
 * @param networkCapabilities the new network capabilities.
 */
private void updateCapabilities(
int oldScore, NetworkAgentInfo nai, NetworkCapabilities networkCapabilities) {
// Once a NetworkAgent is connected, complain if some immutable capabilities are removed.
if (nai.everConnected && !nai.networkCapabilities.satisfiedByImmutableNetworkCapabilities(
            networkCapabilities)) {
// TODO: consider not complaining when a network agent degrade its capabilities if this
// does not cause any request (that is not a listen) currently matching that agent to
        // stop being matched by the updated agent.
String diff = nai.networkCapabilities.describeImmutableDifferences(networkCapabilities);
        if (!TextUtils.isEmpty(diff)) {
            Slog.wtf(TAG, "BUG: " + nai + " lost immutable capabilities:" + diff);
}
    }

// Don't modify caller's NetworkCapabilities.
networkCapabilities = new NetworkCapabilities(networkCapabilities);
    if (nai.lastValidated) {
        networkCapabilities.addCapability(NET_CAPABILITY_VALIDATED);
} else {
        networkCapabilities.removeCapability(NET_CAPABILITY_VALIDATED);
}
if (nai.lastCaptivePortalDetected) {
        networkCapabilities.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL);
} else {
        networkCapabilities.removeCapability(NET_CAPABILITY_CAPTIVE_PORTAL);
}
if (nai.isBackgroundNetwork()) {
        networkCapabilities.removeCapability(NET_CAPABILITY_FOREGROUND);
} else {
        networkCapabilities.addCapability(NET_CAPABILITY_FOREGROUND);
}

if (Objects.equals(nai.networkCapabilities, networkCapabilities)) return;

    final String oldPermission = getNetworkPermission(nai.networkCapabilities);
    final String newPermission = getNetworkPermission(networkCapabilities);
    if (!Objects.equals(oldPermission, newPermission) && nai.created && !nai.isVPN()) {
try {
mNetd.setNetworkPermission(nai.network.netId, newPermission);
} catch (RemoteException e) {
loge("Exception in setNetworkPermission: " + e);
}
    }

final NetworkCapabilities prevNc = nai.networkCapabilities;
    synchronized (nai) {
        nai.networkCapabilities = networkCapabilities;
}
if (nai.getCurrentScore() == oldScore &&
            networkCapabilities.equalRequestableCapabilities(prevNc)) {
// If the requestable capabilities haven't changed, and the score hasn't changed, then
        // the change we're processing can't affect any requests, it can only affect the listens
        // on this network. We might have been called by rematchNetworkAndRequests when a
        // network changed foreground state.
processListenRequests(nai, true);
} else {
// If the requestable capabilities have changed or the score changed, we can't have been
        // called by rematchNetworkAndRequests, so it's safe to start a rematch.
rematchAllNetworksAndRequests(nai, oldScore);
notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_CAP_CHANGED)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李磊LL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值