diff options
| author | Remi NGUYEN VAN <reminv@google.com> | 2021-02-03 10:18:20 +0900 |
|---|---|---|
| committer | Remi NGUYEN VAN <reminv@google.com> | 2021-02-03 10:19:25 +0900 |
| commit | a26ffd97ee40e1561d62d4dae79a3ed97bbd5e79 (patch) | |
| tree | 544709f72dbf9bbac37e88f25960d54fd0114e56 /core | |
| parent | 9154c8febec6ef387d8d605e4f41729a8c02ff8b (diff) | |
Use formal API for ActivityThread to set proxy
Add getProxyForNetwork to the public API, and use ConnectivityManager
APIs from ActivityThread (instead of hidden APIs) to get/set the proxy
for an app process.
getProxyForNetwork allows clients to find which proxy applies, which can
be a global proxy setting or a per-network proxy.
The default proxy is now initialized with getDefaultProxy instead of
getProxyForNetwork(null); this should not make a difference, as nothing
should have called bindProcessToNetwork at that point yet.
Bug: 174436414
Test: m; device boots
Change-Id: Ifb516194ecde1567cea4b6806946091cdcf2f015
Diffstat (limited to 'core')
| -rw-r--r-- | core/api/module-lib-current.txt | 4 | ||||
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 41 |
2 files changed, 23 insertions, 22 deletions
diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt index e8650faad1f6..6b9a8c9618a4 100644 --- a/core/api/module-lib-current.txt +++ b/core/api/module-lib-current.txt @@ -182,6 +182,10 @@ package android.net { field public static final int TRANSPORT_TEST = 7; // 0x7 } + public final class Proxy { + method public static void setHttpProxyConfiguration(@Nullable android.net.ProxyInfo); + } + public final class TcpRepairWindow { ctor public TcpRepairWindow(int, int, int, int, int, int); field public final int maxWindow; diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 1f9cb6430a5d..e5a04c98b9e7 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -95,7 +95,6 @@ import android.media.MediaFrameworkInitializer; import android.media.MediaFrameworkPlatformInitializer; import android.media.MediaServiceManager; import android.net.ConnectivityManager; -import android.net.IConnectivityManager; import android.net.Proxy; import android.net.Uri; import android.os.AsyncTask; @@ -6576,25 +6575,6 @@ public final class ActivityThread extends ClientTransactionHandler { // Pass the current context to HardwareRenderer HardwareRenderer.setContextForInit(getSystemContext()); - /** - * Initialize the default http proxy in this process for the reasons we set the time zone. - */ - Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); - final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); - if (b != null) { - // In pre-boot mode (doing initial launch to collect password), not - // all system is up. This includes the connectivity service, so don't - // crash if we can't get it. - final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); - try { - Proxy.setHttpProxySystemProperty(service.getProxyForNetwork(null)); - } catch (RemoteException e) { - Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); - throw e.rethrowFromSystemServer(); - } - } - Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); - // Instrumentation info affects the class loader, so load it before // setting up the app context. final InstrumentationInfo ii; @@ -6608,6 +6588,23 @@ public final class ActivityThread extends ClientTransactionHandler { updateLocaleListFromAppContext(appContext, mResourcesManager.getConfiguration().getLocales()); + // Initialize the default http proxy in this process. + Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); + try { + // In pre-boot mode (doing initial launch to collect password), not all system is up. + // This includes the connectivity service, so trying to obtain ConnectivityManager at + // that point would return null. Check whether the ConnectivityService is available, and + // avoid crashing with a NullPointerException if it is not. + final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); + if (b != null) { + final ConnectivityManager cm = + appContext.getSystemService(ConnectivityManager.class); + Proxy.setHttpProxyConfiguration(cm.getDefaultProxy()); + } + } finally { + Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); + } + if (!Process.isIsolated()) { final int oldMask = StrictMode.allowThreadDiskWritesMask(); try { @@ -7522,8 +7519,8 @@ public final class ActivityThread extends ClientTransactionHandler { } public static void updateHttpProxy(@NonNull Context context) { - final ConnectivityManager cm = ConnectivityManager.from(context); - Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); + final ConnectivityManager cm = context.getSystemService(ConnectivityManager.class); + Proxy.setHttpProxyConfiguration(cm.getDefaultProxy()); } @UnsupportedAppUsage |
