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

Commit dace9a77 authored by Wonguk Jeong's avatar Wonguk Jeong
Browse files

Update APN proxy beforer network agent created.



When APN proxy setting exists, proxy is not properly
applied to network agent often.

When state is chagned to ActiveState in DataConnection,
1) DcTracker sets http proxy into LinkProperty (by event),
2) and NetworkAgent is created with current LinkProperty.
But the thing is the sequence of 1), 2) is not deterministic.

Therefore,
- Move proxy setting logic from DcTracker to DataConnection
- Update proxy setting just before NetworkAgent is created

Test: manually tested on emulator behind proxy server
Test: step1. create new APN with proxy
Test: step2. turn on/off flight mode
Test: step3. connect to google.com using webview
Bug: 156527346

Change-Id: I7ecaa9eaaca419b75b7645ae7523dafa4de8c0be
Signed-off-by: default avatarWonguk Jeong <wonguk.jeong@samsung.com>
parent 9d7ed998
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -454,8 +454,26 @@ public class DataConnection extends StateMachine {
        return mApnSetting;
    }

    void setLinkPropertiesHttpProxy(ProxyInfo proxy) {
    /**
     * Update http proxy of link properties based on current apn setting
     */
    private void updateLinkPropertiesHttpProxy() {
        if (mApnSetting == null
                || TextUtils.isEmpty(mApnSetting.getProxyAddressAsString())) {
            return;
        }
        try {
            int port = mApnSetting.getProxyPort();
            if (port == -1) {
                port = 8080;
            }
            ProxyInfo proxy = ProxyInfo.buildDirectProxy(
                    mApnSetting.getProxyAddressAsString(), port);
            mLinkProperties.setHttpProxy(proxy);
        } catch (NumberFormatException e) {
            loge("onDataSetupComplete: NumberFormatException making ProxyProperties ("
                    + mApnSetting.getProxyPort() + "): " + e);
        }
    }

    public static class UpdateLinkPropertyResult {
@@ -2189,7 +2207,7 @@ public class DataConnection extends StateMachine {
                final NetworkProvider provider = (null == factory) ? null : factory.getProvider();

                mDisabledApnTypeBitMask |= getDisallowedApnTypes();

                updateLinkPropertiesHttpProxy();
                mNetworkAgent = new DcNetworkAgent(DataConnection.this,
                        mPhone, mNetworkInfo, mScore, configBuilder.build(), provider,
                        mTransportType);
+0 −15
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import android.net.NetworkAgent;
import android.net.NetworkCapabilities;
import android.net.NetworkPolicyManager;
import android.net.NetworkRequest;
import android.net.ProxyInfo;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.AsyncResult;
@@ -2828,20 +2827,6 @@ public class DcTracker extends Handler {
                    log("onDataSetupComplete: success apn=" + (apn == null ? "unknown"
                            : apn.getApnName()));
                }
                if (apn != null && !TextUtils.isEmpty(apn.getProxyAddressAsString())) {
                    try {
                        int port = apn.getProxyPort();
                        if (port == -1) {
                            port = 8080;
                        }
                        ProxyInfo proxy = ProxyInfo.buildDirectProxy(
                                apn.getProxyAddressAsString(), port);
                        dataConnection.setLinkPropertiesHttpProxy(proxy);
                    } catch (NumberFormatException e) {
                        loge("onDataSetupComplete: NumberFormatException making ProxyProperties ("
                                + apn.getProxyPort() + "): " + e);
                    }
                }

                // everything is setup
                if (TextUtils.equals(apnContext.getApnType(), PhoneConstants.APN_TYPE_DEFAULT)