当前位置:   article > 正文

android13(T) 网络比分机制_wifi android 打分机制

wifi android 打分机制

网络比分核心类

packages\modules\Connectivity\framework\src\android\net\NetworkScore.java
packages\modules\Connectivity\framework\src\android\net\NetworkAgent.java
packages\modules\Connectivity\service\src\com\android\server\ConnectivityService.java

1、WIFI 默认分数 60

packages\modules\Wifi\service\java\com\android\server\wifi\WifiScoreReport.java

// Cache of the last score
private int mLegacyIntScore = ConnectedScore.WIFI_INITIAL_SCORE;//60
	
private NetworkScore.Builder getScoreBuilder() {
        // We should force keep connected for a MBB CMM which is not lingering.
        boolean shouldForceKeepConnected =
                mCurrentRole == ActiveModeManager.ROLE_CLIENT_SECONDARY_TRANSIENT
                        && !mShouldReduceNetworkScore;
        int keepConnectedReason =
                shouldForceKeepConnected
                        ? NetworkScore.KEEP_CONNECTED_FOR_HANDOVER
                        : NetworkScore.KEEP_CONNECTED_NONE;
        boolean exiting = SdkLevel.isAtLeastS() && mWifiConnectedNetworkScorerHolder != null
                ? !mIsUsable : mLegacyIntScore < ConnectedScore.WIFI_TRANSITION_SCORE;
        return new NetworkScore.Builder()
                .setLegacyInt(mShouldReduceNetworkScore ? LINGERING_SCORE : mLegacyIntScore)
                .setTransportPrimary(mCurrentRole == ActiveModeManager.ROLE_CLIENT_PRIMARY)
                .setExiting(exiting)
                .setKeepConnectedReason(keepConnectedReason);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

packages\modules\Wifi\service\java\com\android\server\wifi\ConnectedScore.java

 /** Maximum NetworkAgent score that should be generated by wifi */
    public static final int WIFI_MAX_SCORE = 60;

    /** Initial Wifi score when starting up NetworkAgent. */
    public static final int WIFI_INITIAL_SCORE = WIFI_MAX_SCORE;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2、4G 默认分数 50

frameworks\opt\telephony\src\java\com\android\internal\telephony\data\TelephonyNetworkFactory.java


private static final int TELEPHONY_NETWORK_SCORE = 50;

    public TelephonyNetworkFactory(Looper looper, Phone phone, PhoneSwitcher phoneSwitcher) {
        super(looper, phone.getContext(), "TelephonyNetworkFactory[" + phone.getPhoneId()
                + "]", null);
        mPhone = phone;
        mInternalHandler = new InternalHandler(looper);

        mSubscriptionController = SubscriptionController.getInstance();
        mAccessNetworksManager = mPhone.getAccessNetworksManager();

        setCapabilityFilter(makeNetworkFilter(mSubscriptionController, mPhone.getPhoneId()));
        setScoreFilter(TELEPHONY_NETWORK_SCORE);

        mPhoneSwitcher = phoneSwitcher;
		
		.......
	
    // apply or revoke requests if our active-ness changes
    private void onActivePhoneSwitch() {
        logl("onActivePhoneSwitch");
        if (mSubscriptionId == mSubscriptionController.getActiveDataSubscriptionId()) {
            logl("onActivePhoneSwitch: set primary flag for phoneId: " + mPhone.getPhoneId());
            setScoreFilter(new NetworkScore.Builder().setLegacyInt(TELEPHONY_NETWORK_SCORE)
                    .setTransportPrimary(true).build());
        } else {
            setScoreFilter(new NetworkScore.Builder().setLegacyInt(TELEPHONY_NETWORK_SCORE)
                    .setTransportPrimary(false).build());
        }
	
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

3、以太网 默认分数 Integer.MIN_VALUE

packages\modules\Connectivity\service-t\src\com\android\server\ethernet\EthernetNetworkFactory.java

 private static NetworkScore getBestNetworkScore() {
		 return new NetworkScore.Builder().build();
	}


 private void setCapabilities(@NonNull final NetworkCapabilities capabilities) {
		mCapabilities = new NetworkCapabilities(capabilities);
		mLegacyType = getLegacyType(mCapabilities);

		if (mLinkUp) {
			// registering a new network offer will update the existing one, not install a
			// new one.
			mNetworkProvider.registerNetworkOffer(getBestNetworkScore(),
					new NetworkCapabilities(capabilities), cmd -> mHandler.post(cmd),
					mNetworkOfferCallback);
		}
	}
	
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/527993
推荐阅读
相关标签
  

闽ICP备14008679号