tencent cloud

Plug-In Network Interface Card Acceleration

Download
フォーカスモード
フォントサイズ
最終更新日: 2026-05-21 11:47:04
Currently, Multiple Network Acceleration Android SDK supports acceleration for three types of network interface cards: WIFI, MOBILE, and ETH. You can add the network interface card you want to accelerate by calling the setAccLinks method. If you want to add an unsupported network interface card type, you can dynamically add a custom network interface card by using the addNetworkPlugin function to add a network interface card plug-in.

Example code:

package com.android.tencentvpn.plugin;

import com.android.linkboost.multi.AccConfig;
import com.android.linkboost.multi.MpNetworkPlugin;
import com.android.linkboost.multi.MpNetworkPluginManager;
import com.android.linkboost.multi.log.MpAccLog;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import androidx.annotation.NonNull;

/**
* Network interface card plugin implementation class
* When acceleration needs to be triggered, add via {@link AccConfig#addNetworkPlugin(String)}
accConfig.addNetworkPlugin("com.android.tencentvpn.plugin.MpNetworkPluginImpl");
*/
public class MpNetworkPluginImpl extends MpNetworkPlugin {
private static final String TAG = "MpNetworkPluginImpl";
private static final String ETH0 = "eth0";
private final ConnectivityManager mConnectivityManager;
private final MpNetworkPluginManager mMpNetworkPluginManager;
private final InnerCallback mInnerCallback;
private Network mNetwork;

public MpNetworkPluginImpl(Context context) {
super(context);
mConnectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
mMpNetworkPluginManager = new MpNetworkPluginManager(context);
mInnerCallback = new InnerCallback();
}
//Business needs to implement the specific activation logic of the network interface card itself
@Override public void requestNetwork() {
MpAccLog.i(TAG, "requestNetwork");
NetworkRequest.Builder req = new NetworkRequest.Builder();
req.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
req.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
mConnectivityManager.requestNetwork(req.build(), mInnerCallback);
}

@Override public void releaseNetwork() {
MpAccLog.i(TAG, "releaseNetwork");
mConnectivityManager.unregisterNetworkCallback(mInnerCallback);
mMpNetworkPluginManager.onLost(mNetwork);
}

class InnerCallback extends ConnectivityManager.NetworkCallback {
@Override public void onLinkPropertiesChanged(@NonNull Network network,
@NonNull LinkProperties linkProperties) {
super.onLinkPropertiesChanged(network, linkProperties);
int type = 101;
// Different type values are passed for different network interface card names in linkProperties.getInterfaceName()
// if (ETH0.equals(linkProperties.getInterfaceName())) {
// type = 101;// type() Custom type greater than 100 and less than 1000 (100-1000), avoid conflict with other system network interface cards
// }
// if (ETH1.equals(linkProperties.getInterfaceName())) {
// type = 102;
// }
mNetwork = network;
MpAccLog.i(TAG, "onLinkPropertiesChanged:"
+ network
+ " ifname:"
+ linkProperties.getInterfaceName());
mMpNetworkPluginManager.onLinkPropertiesChanged(type, network, linkProperties);
}

@Override public void onLost(@NonNull Network network) {
super.onLost(network);
MpAccLog.i(TAG, "onLost:" + network);
mMpNetworkPluginManager.onLost(network);
}
}
}


Note:
Trigger acceleration by adding the plug-in via addNetworkPlugin.
accConfig.addNetworkPlugin(MpNetworkPluginImpl.class.getName());
//...acceleration mode, routing rule settings
mMpAccClient.startAcc(accConfig);


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック