android13(T) 网络比分机制

网络比分核心类

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);
    }

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;

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());
        }
	

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);
		}
	}
	

你可能感兴趣的:(Android12-13,源码修改,网络比分)