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

Commit 6852f5bd authored by Pavel Grafov's avatar Pavel Grafov Committed by Automerger Merge Worker
Browse files

Merge "Connectivity: start PAC global proxy after reboot." am: 5ab4cc2a am: 77c58489

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

Change-Id: I5bb6267ca876df8aef0b2df630c058726b195352
parents 51c383fe 77c58489
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;
    }

    /**