Don't call ConnectivityService when holding ActivityManagerService lock.

Exclude system server thread from the threads on which we call updateHttpProxy() from the Activity Manager.

Test: atest HostsideVpnTests
Bug: 128465980
Change-Id: Ia2b2c6de8a01a264bfb09393144641d91ee2c164
This commit is contained in:
Irina Dumitrescu
2019-04-15 19:20:38 +01:00
parent 1c9cde6c1d
commit 34a27c4c45
3 changed files with 25 additions and 18 deletions

View File

@@ -1073,9 +1073,8 @@ public final class ActivityThread extends ClientTransactionHandler {
}
public void updateHttpProxy() {
final ConnectivityManager cm = ConnectivityManager.from(
ActivityThread.updateHttpProxy(
getApplication() != null ? getApplication() : getSystemContext());
Proxy.setHttpProxySystemProperty(cm.getDefaultProxy());
}
public void processInBackground() {
@@ -6948,6 +6947,11 @@ public final class ActivityThread extends ClientTransactionHandler {
return thread;
}
public static void updateHttpProxy(@NonNull Context context) {
final ConnectivityManager cm = ConnectivityManager.from(context);
Proxy.setHttpProxySystemProperty(cm.getDefaultProxy());
}
@UnsupportedAppUsage
public final void installSystemProviders(List<ProviderInfo> providers) {
if (providers != null) {

View File

@@ -1635,9 +1635,7 @@ public class ActivityManagerService extends IActivityManager.Stub
}
} break;
case UPDATE_HTTP_PROXY_MSG: {
synchronized (ActivityManagerService.this) {
mProcessList.setAllHttpProxyLocked();
}
mProcessList.setAllHttpProxy();
} break;
case PROC_START_TIMEOUT_MSG: {
ProcessRecord app = (ProcessRecord)msg.obj;
@@ -1826,7 +1824,7 @@ public class ActivityManagerService extends IActivityManager.Stub
} break;
}
}
};
}
static final int COLLECT_PSS_BG_MSG = 1;

View File

@@ -46,6 +46,7 @@ import static com.android.server.am.ActivityManagerService.TAG_PSS;
import static com.android.server.am.ActivityManagerService.TAG_UID_OBSERVERS;
import android.app.ActivityManager;
import android.app.ActivityThread;
import android.app.AppGlobals;
import android.app.AppProtoEnums;
import android.app.IApplicationThread;
@@ -2485,21 +2486,25 @@ public final class ProcessList {
}
}
@GuardedBy("mService")
void setAllHttpProxyLocked() {
for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
ProcessRecord r = mLruProcesses.get(i);
// Don't dispatch to isolated processes as they can't access
// ConnectivityManager and don't have network privileges anyway.
if (r.thread != null && !r.isolated) {
try {
r.thread.updateHttpProxy();
} catch (RemoteException ex) {
Slog.w(TAG, "Failed to update http proxy for: " +
r.info.processName);
void setAllHttpProxy() {
// Update the HTTP proxy for each application thread.
synchronized (mService) {
for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
ProcessRecord r = mLruProcesses.get(i);
// Don't dispatch to isolated processes as they can't access ConnectivityManager and
// don't have network privileges anyway. Exclude system server and update it
// separately outside the AMS lock, to avoid deadlock with Connectivity Service.
if (r.pid != ActivityManagerService.MY_PID && r.thread != null && !r.isolated) {
try {
r.thread.updateHttpProxy();
} catch (RemoteException ex) {
Slog.w(TAG, "Failed to update http proxy for: "
+ r.info.processName);
}
}
}
}
ActivityThread.updateHttpProxy(mService.mContext);
}
@GuardedBy("mService")