Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34a27c4c authored by Irina Dumitrescu's avatar Irina Dumitrescu
Browse files

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
parent 1c9cde6c
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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) {
+2 −4
Original line number Diff line number Diff line
@@ -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;
+17 −12
Original line number Diff line number Diff line
@@ -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() {
    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.
            if (r.thread != null && !r.isolated) {
                // 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);
                        Slog.w(TAG, "Failed to update http proxy for: "
                                + r.info.processName);
                    }
                }
            }
        }
        ActivityThread.updateHttpProxy(mService.mContext);
    }

    @GuardedBy("mService")