Merge "Have NetworkPolicyManagerService create MultipathPolicyTracker" am: a34d9a7af1 am: 8f96256d85 am: 27ace52564
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1519960 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I023815a53f01a0459b94033b7e2fa2ed91cca86a
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package android.net;
|
||||
|
||||
import android.net.INetworkPolicyListener;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.NetworkQuotaInfo;
|
||||
import android.net.NetworkState;
|
||||
@@ -67,6 +68,8 @@ interface INetworkPolicyManager {
|
||||
void setDeviceIdleMode(boolean enabled);
|
||||
void setWifiMeteredOverride(String networkId, int meteredOverride);
|
||||
|
||||
int getMultipathPreference(in Network network);
|
||||
|
||||
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
|
||||
NetworkQuotaInfo getNetworkQuotaInfo(in NetworkState state);
|
||||
|
||||
|
||||
@@ -432,6 +432,17 @@ public class NetworkPolicyManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multipath preference for the given network.
|
||||
*/
|
||||
public int getMultipathPreference(Network network) {
|
||||
try {
|
||||
return mService.getMultipathPreference(network);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
@Deprecated
|
||||
public static Iterator<Pair<ZonedDateTime, ZonedDateTime>> cycleIterator(NetworkPolicy policy) {
|
||||
|
||||
@@ -201,7 +201,6 @@ import com.android.server.connectivity.IpConnectivityMetrics;
|
||||
import com.android.server.connectivity.KeepaliveTracker;
|
||||
import com.android.server.connectivity.LingerMonitor;
|
||||
import com.android.server.connectivity.MockableSystemProperties;
|
||||
import com.android.server.connectivity.MultipathPolicyTracker;
|
||||
import com.android.server.connectivity.NetworkAgentInfo;
|
||||
import com.android.server.connectivity.NetworkDiagnostics;
|
||||
import com.android.server.connectivity.NetworkNotificationManager;
|
||||
@@ -441,11 +440,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
*/
|
||||
private static final int EVENT_EXPIRE_NET_TRANSITION_WAKELOCK = 24;
|
||||
|
||||
/**
|
||||
* Used internally to indicate the system is ready.
|
||||
*/
|
||||
private static final int EVENT_SYSTEM_READY = 25;
|
||||
|
||||
/**
|
||||
* used to add a network request with a pending intent
|
||||
* obj = NetworkRequestInfo
|
||||
@@ -660,9 +654,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
@VisibleForTesting
|
||||
final MultinetworkPolicyTracker mMultinetworkPolicyTracker;
|
||||
|
||||
@VisibleForTesting
|
||||
final MultipathPolicyTracker mMultipathPolicyTracker;
|
||||
|
||||
@VisibleForTesting
|
||||
final Map<IBinder, ConnectivityDiagnosticsCallbackInfo> mConnectivityDiagnosticsCallbacks =
|
||||
new HashMap<>();
|
||||
@@ -1167,8 +1158,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
mContext, mHandler, () -> rematchForAvoidBadWifiUpdate());
|
||||
mMultinetworkPolicyTracker.start();
|
||||
|
||||
mMultipathPolicyTracker = new MultipathPolicyTracker(mContext, mHandler);
|
||||
|
||||
mDnsManager = new DnsManager(mContext, mDnsResolver);
|
||||
registerPrivateDnsSettingsCallbacks();
|
||||
}
|
||||
@@ -2315,10 +2304,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void systemReadyInternal() {
|
||||
// Let PermissionMonitor#startMonitoring() running in the beginning of the systemReady
|
||||
// before MultipathPolicyTracker.start(). Since mApps in PermissionMonitor needs to be
|
||||
// populated first to ensure that listening network request which is sent by
|
||||
// MultipathPolicyTracker won't be added NET_CAPABILITY_FOREGROUND capability.
|
||||
// Since mApps in PermissionMonitor needs to be populated first to ensure that
|
||||
// listening network request which is sent by MultipathPolicyTracker won't be added
|
||||
// NET_CAPABILITY_FOREGROUND capability. Thus, MultipathPolicyTracker.start() must
|
||||
// be called after PermissionMonitor#startMonitoring().
|
||||
// Calling PermissionMonitor#startMonitoring() in systemReadyInternal() and the
|
||||
// MultipathPolicyTracker.start() is called in NetworkPolicyManagerService#systemReady()
|
||||
// to ensure the tracking will be initialized correctly.
|
||||
mPermissionMonitor.startMonitoring();
|
||||
mProxyTracker.loadGlobalProxy();
|
||||
registerNetdEventCallback();
|
||||
@@ -2337,8 +2329,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
// Create network requests for always-on networks.
|
||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_CONFIGURE_ALWAYS_ON_NETWORKS));
|
||||
|
||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_READY));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2638,7 +2628,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
dumpAvoidBadWifiSettings(pw);
|
||||
|
||||
pw.println();
|
||||
mMultipathPolicyTracker.dump(pw);
|
||||
|
||||
if (ArrayUtils.contains(args, SHORT_ARG) == false) {
|
||||
pw.println();
|
||||
@@ -4186,11 +4175,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
return ConnectivityManager.MULTIPATH_PREFERENCE_UNMETERED;
|
||||
}
|
||||
|
||||
Integer networkPreference = mMultipathPolicyTracker.getMultipathPreference(network);
|
||||
if (networkPreference != null) {
|
||||
final NetworkPolicyManager netPolicyManager =
|
||||
mContext.getSystemService(NetworkPolicyManager.class);
|
||||
|
||||
final int networkPreference = netPolicyManager.getMultipathPreference(network);
|
||||
if (networkPreference != 0) {
|
||||
return networkPreference;
|
||||
}
|
||||
|
||||
return mMultinetworkPolicyTracker.getMeteredMultipathPreference();
|
||||
}
|
||||
|
||||
@@ -4294,10 +4285,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
mKeepaliveTracker.handleStopKeepalive(nai, slot, reason);
|
||||
break;
|
||||
}
|
||||
case EVENT_SYSTEM_READY: {
|
||||
mMultipathPolicyTracker.start();
|
||||
break;
|
||||
}
|
||||
case EVENT_REVALIDATE_NETWORK: {
|
||||
handleReportNetworkConnectivity((Network) msg.obj, msg.arg1, toBool(msg.arg2));
|
||||
break;
|
||||
|
||||
@@ -236,6 +236,7 @@ import com.android.server.EventLogTags;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.ServiceThread;
|
||||
import com.android.server.SystemConfig;
|
||||
import com.android.server.connectivity.MultipathPolicyTracker;
|
||||
import com.android.server.usage.AppStandbyInternal;
|
||||
import com.android.server.usage.AppStandbyInternal.AppIdleStateChangeListener;
|
||||
|
||||
@@ -413,6 +414,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
private final Clock mClock;
|
||||
private final UserManager mUserManager;
|
||||
private final CarrierConfigManager mCarrierConfigManager;
|
||||
private final MultipathPolicyTracker mMultipathPolicyTracker;
|
||||
|
||||
private IConnectivityManager mConnManager;
|
||||
private PowerManagerInternal mPowerManagerInternal;
|
||||
@@ -653,7 +655,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
mPolicyFile = new AtomicFile(new File(systemDir, "netpolicy.xml"), "net-policy");
|
||||
|
||||
mAppOps = context.getSystemService(AppOpsManager.class);
|
||||
|
||||
mMultipathPolicyTracker = new MultipathPolicyTracker(mContext, mHandler);
|
||||
// Expose private service for system components to use.
|
||||
LocalServices.addService(NetworkPolicyManagerInternal.class,
|
||||
new NetworkPolicyManagerInternalImpl());
|
||||
@@ -921,6 +923,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
if (!initCompleteSignal.await(30, TimeUnit.SECONDS)) {
|
||||
throw new IllegalStateException("Service " + TAG +" init timeout");
|
||||
}
|
||||
mMultipathPolicyTracker.start();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Service " + TAG + " init interrupted", e);
|
||||
@@ -3454,6 +3457,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multipath preference value for the given network.
|
||||
*/
|
||||
public int getMultipathPreference(Network network) {
|
||||
final Integer preference = mMultipathPolicyTracker.getMultipathPreference(network);
|
||||
if (preference != null) {
|
||||
return preference;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
|
||||
if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) return;
|
||||
@@ -3674,6 +3688,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
mLogger.dumpLogs(fout);
|
||||
}
|
||||
}
|
||||
fout.println();
|
||||
mMultipathPolicyTracker.dump(fout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4742,11 +4742,9 @@ public class ConnectivityServiceTest {
|
||||
|
||||
@Test
|
||||
public void testNetworkCallbackMaximum() {
|
||||
// We can only have 99 callbacks, because MultipathPolicyTracker is
|
||||
// already one of them.
|
||||
final int MAX_REQUESTS = 99;
|
||||
final int MAX_REQUESTS = 100;
|
||||
final int CALLBACKS = 89;
|
||||
final int INTENTS = 10;
|
||||
final int INTENTS = 11;
|
||||
assertEquals(MAX_REQUESTS, CALLBACKS + INTENTS);
|
||||
|
||||
NetworkRequest networkRequest = new NetworkRequest.Builder().build();
|
||||
|
||||
Reference in New Issue
Block a user