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

Commit c66a30c4 authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Connectivity: start PAC global proxy after reboot.

Previously, we read the global proxy settings from Settings.Global
database after reboot. This works for manual proxies, but not for
proxies based on PAC rules, as PacManager is never invoked when
ConnectivityService starts up. As a consequence, services required for
PAC-based proxies (PacService and ProxyService) are never started.

In this CL, we make sure PacManager is called during boot, so that PAC
rules will take effect.

Bug: 35943997
Test: set a PAC proxy and observe it still works after reboot
Change-Id: I69edb5fcd3e84663d338ff4b93c40fd5ee2c8c51
parent b86d989f
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -5,7 +5,9 @@
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:label="@string/app_name">
        android:label="@string/app_name"
        android:defaultToDeviceProtectedStorage="true"
        android:directBootAware="true">

        <service android:name=".PacService"
            android:exported="true">
+17 −5
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ public class ProxyTracker {
    @GuardedBy("mProxyLock")
    private boolean mDefaultProxyEnabled = true;

    private final Handler mConnectivityServiceHandler;

    // The object responsible for Proxy Auto Configuration (PAC).
    @NonNull
    private final PacManager mPacManager;
@@ -80,6 +82,7 @@ public class ProxyTracker {
    public ProxyTracker(@NonNull final Context context,
            @NonNull final Handler connectivityServiceInternalHandler, final int pacChangedEvent) {
        mContext = context;
        mConnectivityServiceHandler = connectivityServiceInternalHandler;
        mPacManager = new PacManager(context, connectivityServiceInternalHandler, pacChangedEvent);
    }

@@ -149,6 +152,9 @@ public class ProxyTracker {
     * Read the global proxy settings and cache them in memory.
     */
    public void loadGlobalProxy() {
        if (loadDeprecatedGlobalHttpProxy()) {
            return;
        }
        ContentResolver res = mContext.getContentResolver();
        String host = Settings.Global.getString(res, GLOBAL_HTTP_PROXY_HOST);
        int port = Settings.Global.getInt(res, GLOBAL_HTTP_PROXY_PORT, 0);
@@ -169,20 +175,24 @@ public class ProxyTracker {
            synchronized (mProxyLock) {
                mGlobalProxy = proxyProperties;
            }

            if (!TextUtils.isEmpty(pacFileUrl)) {
                mConnectivityServiceHandler.post(
                        () -> mPacManager.setCurrentProxyScriptUrl(proxyProperties));
            }
        }
        loadDeprecatedGlobalHttpProxy();
        // TODO : shouldn't this function call mPacManager.setCurrentProxyScriptUrl ?
    }

    /**
     * Read the global proxy from the deprecated Settings.Global.HTTP_PROXY setting and apply it.
     * Returns {@code true} when global proxy was set successfully from deprecated setting.
     */
    public void loadDeprecatedGlobalHttpProxy() {
    public boolean loadDeprecatedGlobalHttpProxy() {
        final String proxy = Settings.Global.getString(mContext.getContentResolver(), HTTP_PROXY);
        if (!TextUtils.isEmpty(proxy)) {
            String data[] = proxy.split(":");
            if (data.length == 0) {
                return;
                return false;
            }

            final String proxyHost = data[0];
@@ -191,12 +201,14 @@ public class ProxyTracker {
                try {
                    proxyPort = Integer.parseInt(data[1]);
                } catch (NumberFormatException e) {
                    return;
                    return false;
                }
            }
            final ProxyInfo p = new ProxyInfo(proxyHost, proxyPort, "");
            setGlobalProxy(p);
            return true;
        }
        return false;
    }

    /**