Merge "Have connectivity self-register manager classes" am: 4ad0fdc5c9 am: 98c48f7101

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1552657

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I512f95a45ab23d4b7e03c196850d0dab75223620
This commit is contained in:
Treehugger Robot
2021-02-02 06:07:13 +00:00
committed by Automerger Merge Worker
4 changed files with 111 additions and 60 deletions

View File

@@ -10,6 +10,10 @@ package android.app {
package android.net {
public final class ConnectivityFrameworkInitializer {
method public static void registerServiceWrappers();
}
public class ConnectivityManager {
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void requestBackgroundNetwork(@NonNull android.net.NetworkRequest, @Nullable android.os.Handler, @NonNull android.net.ConnectivityManager.NetworkCallback);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_TEST_NETWORKS, android.Manifest.permission.NETWORK_STACK}) public void simulateDataStall(int, long, @NonNull android.net.Network, @NonNull android.os.PersistableBundle);

View File

@@ -111,21 +111,16 @@ import android.media.tv.ITvInputManager;
import android.media.tv.TvInputManager;
import android.media.tv.tunerresourcemanager.ITunerResourceManager;
import android.media.tv.tunerresourcemanager.TunerResourceManager;
import android.net.ConnectivityDiagnosticsManager;
import android.net.ConnectivityManager;
import android.net.ConnectivityFrameworkInitializer;
import android.net.EthernetManager;
import android.net.IConnectivityManager;
import android.net.IEthernetManager;
import android.net.IIpSecService;
import android.net.INetworkPolicyManager;
import android.net.ITestNetworkManager;
import android.net.IpSecManager;
import android.net.NetworkPolicyManager;
import android.net.NetworkScoreManager;
import android.net.NetworkWatchlistManager;
import android.net.TestNetworkManager;
import android.net.TetheringManager;
import android.net.VpnManager;
import android.net.lowpan.ILowpanManager;
import android.net.lowpan.LowpanManager;
import android.net.nsd.INsdManager;
@@ -154,7 +149,6 @@ import android.os.IUserManager;
import android.os.IncidentManager;
import android.os.PowerManager;
import android.os.RecoverySystem;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.StatsFrameworkInitializer;
@@ -349,15 +343,6 @@ public final class SystemServiceRegistry {
// (which extends it).
SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE);
registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class,
new StaticApplicationContextServiceFetcher<ConnectivityManager>() {
@Override
public ConnectivityManager createService(Context context) throws ServiceNotFoundException {
IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE);
IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
return new ConnectivityManager(context, service);
}});
registerService(Context.NETD_SERVICE, IBinder.class, new StaticServiceFetcher<IBinder>() {
@Override
public IBinder createService() throws ServiceNotFoundException {
@@ -391,50 +376,6 @@ public final class SystemServiceRegistry {
return new IpSecManager(ctx, service);
}});
registerService(Context.VPN_MANAGEMENT_SERVICE, VpnManager.class,
new CachedServiceFetcher<VpnManager>() {
@Override
public VpnManager createService(ContextImpl ctx) throws ServiceNotFoundException {
IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
return new VpnManager(ctx, service);
}});
registerService(Context.CONNECTIVITY_DIAGNOSTICS_SERVICE,
ConnectivityDiagnosticsManager.class,
new CachedServiceFetcher<ConnectivityDiagnosticsManager>() {
@Override
public ConnectivityDiagnosticsManager createService(ContextImpl ctx)
throws ServiceNotFoundException {
// ConnectivityDiagnosticsManager is backed by ConnectivityService
IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE);
IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
return new ConnectivityDiagnosticsManager(ctx, service);
}});
registerService(
Context.TEST_NETWORK_SERVICE,
TestNetworkManager.class,
new StaticApplicationContextServiceFetcher<TestNetworkManager>() {
@Override
public TestNetworkManager createService(Context context)
throws ServiceNotFoundException {
IBinder csBinder =
ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE);
IConnectivityManager csMgr =
IConnectivityManager.Stub.asInterface(csBinder);
final IBinder tnBinder;
try {
tnBinder = csMgr.startOrGetTestNetworkService();
} catch (RemoteException e) {
throw new ServiceNotFoundException(Context.TEST_NETWORK_SERVICE);
}
ITestNetworkManager tnMgr = ITestNetworkManager.Stub.asInterface(tnBinder);
return new TestNetworkManager(tnMgr);
}
});
registerService(Context.COUNTRY_DETECTOR, CountryDetector.class,
new StaticServiceFetcher<CountryDetector>() {
@Override
@@ -1355,6 +1296,7 @@ public final class SystemServiceRegistry {
try {
// Note: the following functions need to be @SystemApis, once they become mainline
// modules.
ConnectivityFrameworkInitializer.registerServiceWrappers();
JobSchedulerFrameworkInitializer.registerServiceWrappers();
BlobStoreManagerFrameworkInitializer.initialize();
TelephonyFrameworkInitializer.registerServiceWrappers();

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
import android.annotation.SystemApi;
import android.app.SystemServiceRegistry;
import android.content.Context;
/**
* Class for performing registration for all core connectivity services.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public final class ConnectivityFrameworkInitializer {
private ConnectivityFrameworkInitializer() {}
/**
* Called by {@link SystemServiceRegistry}'s static initializer and registers all core
* connectivity services to {@link Context}, so that {@link Context#getSystemService} can
* return them.
*
* @throws IllegalStateException if this is called anywhere besides
* {@link SystemServiceRegistry}.
*/
public static void registerServiceWrappers() {
// registerContextAwareService will throw if this is called outside of SystemServiceRegistry
// initialization.
SystemServiceRegistry.registerContextAwareService(
Context.CONNECTIVITY_SERVICE,
ConnectivityManager.class,
(context, serviceBinder) -> {
IConnectivityManager icm = IConnectivityManager.Stub.asInterface(serviceBinder);
return new ConnectivityManager(context, icm);
}
);
// TODO: move outside of the connectivity JAR
SystemServiceRegistry.registerContextAwareService(
Context.VPN_MANAGEMENT_SERVICE,
VpnManager.class,
(context) -> {
final ConnectivityManager cm = context.getSystemService(
ConnectivityManager.class);
return cm.createVpnManager();
}
);
SystemServiceRegistry.registerContextAwareService(
Context.CONNECTIVITY_DIAGNOSTICS_SERVICE,
ConnectivityDiagnosticsManager.class,
(context) -> {
final ConnectivityManager cm = context.getSystemService(
ConnectivityManager.class);
return cm.createDiagnosticsManager();
}
);
SystemServiceRegistry.registerContextAwareService(
Context.TEST_NETWORK_SERVICE,
TestNetworkManager.class,
context -> {
final ConnectivityManager cm = context.getSystemService(
ConnectivityManager.class);
return cm.startOrGetTestNetworkManager();
}
);
}
}

View File

@@ -4823,6 +4823,28 @@ public class ConnectivityManager {
}
}
/** @hide */
public TestNetworkManager startOrGetTestNetworkManager() {
final IBinder tnBinder;
try {
tnBinder = mService.startOrGetTestNetworkService();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
return new TestNetworkManager(ITestNetworkManager.Stub.asInterface(tnBinder));
}
/** @hide */
public VpnManager createVpnManager() {
return new VpnManager(mContext, mService);
}
/** @hide */
public ConnectivityDiagnosticsManager createDiagnosticsManager() {
return new ConnectivityDiagnosticsManager(mContext, mService);
}
/**
* Simulates a Data Stall for the specified Network.
*