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

Commit 488cc772 authored by Anna Malova's avatar Anna Malova Committed by Android (Google) Code Review
Browse files

Merge "Implement PacService using WebView's version of libpac."

parents f0c72dd6 29ed0cc4
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -269,6 +269,11 @@
         when there's no network connection. If the scan doesn't timeout, use zero -->
    <integer name="config_radioScanningTimeout">0</integer>

    <!-- When true, Android uses the PAC implementation included in WebView to handle
         networks with PAC scripts.
         When false, Android's own implementation of libpac is used.-->
    <bool name ="config_useWebViewPacProcessor">false</bool>

    <!-- XXXXX NOTE THE FOLLOWING RESOURCES USE THE WRONG NAMING CONVENTION.
         Please don't copy them, copy anything else. -->

+1 −0
Original line number Diff line number Diff line
@@ -286,6 +286,7 @@
  <java-symbol type="bool" name="config_duplicate_port_omadm_wappush" />
  <java-symbol type="bool" name="config_disableTransitionAnimation" />
  <java-symbol type="bool" name="config_enableAutoPowerModes" />
  <java-symbol type="bool" name="config_useWebViewPacProcessor" />
  <java-symbol type="integer" name="config_autoPowerModeThresholdAngle" />
  <java-symbol type="integer" name="config_autoPowerModeAnyMotionSensor" />
  <java-symbol type="bool" name="config_autoPowerModePreferWristTilt" />
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.pacprocessor;

/**
 * Common interface for both Android's and WebView's implementation of PAC processor.
 *
 * @hide
 */
interface LibpacInterface {
    default boolean startPacSupport() {
        return true;
    }

    default boolean stopPacSupport() {
        return true;
    }

    boolean setCurrentProxyScript(String script);
    String makeProxyRequest(String url, String host);
}
+11 −7
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import android.util.Log;
/**
 * @hide
 */
public class PacNative {
public class PacNative implements LibpacInterface {
    private static final String TAG = "PacProxy";

    private static final PacNative sInstance = new PacNative();
@@ -49,34 +49,38 @@ public class PacNative {
        return sInstance;
    }

    @Override
    public synchronized boolean startPacSupport() {
        if (createV8ParserNativeLocked()) {
            Log.e(TAG, "Unable to Create v8 Proxy Parser.");
            return true;
            return false;
        }
        mIsActive = true;
        return false;
        return true;
    }

    @Override
    public synchronized boolean stopPacSupport() {
        if (mIsActive) {
            if (destroyV8ParserNativeLocked()) {
                Log.e(TAG, "Unable to Destroy v8 Proxy Parser.");
                return true;
                return false;
            }
            mIsActive = false;
        }
        return false;
        return true;
    }

    @Override
    public synchronized boolean setCurrentProxyScript(String script) {
        if (setProxyScriptNativeLocked(script)) {
            Log.e(TAG, "Unable to parse proxy script.");
            return true;
        }
            return false;
        }
        return true;
    }

    @Override
    public synchronized String makeProxyRequest(String url, String host) {
        String ret = makeProxyRequestNativeLocked(url, host);
        if ((ret == null) || (ret.length() == 0)) {
+11 −6
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.pacprocessor;

import android.app.Service;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Binder;
import android.os.IBinder;
import android.os.Process;
@@ -30,19 +31,24 @@ import java.net.URL;

public class PacService extends Service {
    private static final String TAG = "PacService";
    private static final boolean sUseWebViewPacProcessor = Resources.getSystem().getBoolean(
            com.android.internal.R.bool.config_useWebViewPacProcessor);

    private final LibpacInterface mLibpac = sUseWebViewPacProcessor
            ? PacWebView.getInstance()
            : PacNative.getInstance();

    private PacNative mPacNative = PacNative.getInstance();
    private ProxyServiceStub mStub = new ProxyServiceStub();

    @Override
    public void onCreate() {
        super.onCreate();
        mPacNative.startPacSupport();
        mLibpac.startPacSupport();
    }

    @Override
    public void onDestroy() {
        mPacNative.stopPacSupport();
        mLibpac.stopPacSupport();
        super.onDestroy();
    }

@@ -52,7 +58,6 @@ public class PacService extends Service {
    }

    private class ProxyServiceStub extends IProxyService.Stub {

        @Override
        public String resolvePacFile(String host, String url) throws RemoteException {
            try {
@@ -69,7 +74,7 @@ public class PacService extends Service {
                        throw new IllegalArgumentException("Invalid host was passed");
                    }
                }
                return mPacNative.makeProxyRequest(url, host);
                return mLibpac.makeProxyRequest(url, host);
            } catch (MalformedURLException e) {
                throw new IllegalArgumentException("Invalid URL was passed");
            }
@@ -81,7 +86,7 @@ public class PacService extends Service {
                Log.e(TAG, "Only system user is allowed to call setPacFile");
                throw new SecurityException();
            }
            mPacNative.setCurrentProxyScript(script);
            mLibpac.setCurrentProxyScript(script);
        }

        @Override
Loading