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

Commit 82f8521d authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Migrate legacy VPN arguments to system_server.

Generate the racoon and mtpd daemon arguments in system_server,
instead of accepting them from Settings.

Bug: 5756357
Change-Id: I42c1a644f6add477fe4222342640d7db15982cb8
parent c268f0b1
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.ParcelFileDescriptor;

import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnProfile;

/**
 * Interface that answers queries about, and allows changing, the
@@ -118,7 +119,7 @@ interface IConnectivityManager

    ParcelFileDescriptor establishVpn(in VpnConfig config);

    void startLegacyVpn(in VpnConfig config, in String[] racoon, in String[] mtpd);
    void startLegacyVpn(in VpnProfile profile);

    LegacyVpnInfo getLegacyVpnInfo();
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.internal.net;

parcelable VpnProfile;
+28 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.internal.net;

import android.os.Parcel;
import android.os.Parcelable;

import java.nio.charset.Charsets;

/**
@@ -27,7 +30,7 @@ import java.nio.charset.Charsets;
 *
 * @hide
 */
public class VpnProfile implements Cloneable {
public class VpnProfile implements Cloneable, Parcelable {
    // Match these constants with R.array.vpn_types.
    public static final int TYPE_PPTP = 0;
    public static final int TYPE_L2TP_IPSEC_PSK = 1;
@@ -120,4 +123,28 @@ public class VpnProfile implements Cloneable {
        builder.append('\0').append(ipsecServerCert);
        return builder.toString().getBytes(Charsets.UTF_8);
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(key);
        out.writeByteArray(encode());
    }

    public static final Creator<VpnProfile> CREATOR = new Creator<VpnProfile>() {
        @Override
        public VpnProfile createFromParcel(Parcel in) {
            final String key = in.readString();
            return decode(key, in.createByteArray());
        }

        @Override
        public VpnProfile[] newArray(int size) {
            return new VpnProfile[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -123,8 +123,12 @@ public class ManageDialog extends AlertActivity implements
            if (which == DialogInterface.BUTTON_POSITIVE) {
                mConfig.configureIntent.send();
            } else if (which == DialogInterface.BUTTON_NEUTRAL) {
                if (mConfig.legacy) {
                    mService.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN);
                } else {
                    mService.prepareVpn(mConfig.user, VpnConfig.LEGACY_VPN);
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "onClick", e);
            finish();
+16 −6
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import static android.net.ConnectivityManager.isNetworkTypeValid;
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.bluetooth.BluetoothTetheringDataTracker;
import android.content.ContentResolver;
import android.content.Context;
@@ -78,6 +80,7 @@ import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Settings;
import android.security.KeyStore;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.Slog;
@@ -85,8 +88,10 @@ import android.util.SparseIntArray;

import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnProfile;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.util.Preconditions;
import com.android.server.am.BatteryStatsService;
import com.android.server.connectivity.Tethering;
import com.android.server.connectivity.Vpn;
@@ -137,6 +142,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    private Tethering mTethering;
    private boolean mTetheringConfigValid = false;

    private final KeyStore mKeyStore;

    private Vpn mVpn;
    private VpnCallback mVpnCallback = new VpnCallback();

@@ -371,6 +378,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        mContext = checkNotNull(context, "missing Context");
        mNetd = checkNotNull(netManager, "missing INetworkManagementService");
        mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager");
        mKeyStore = KeyStore.getInstance();

        try {
            mPolicyManager.registerListener(mPolicyListener);
@@ -3124,14 +3132,16 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    }

    /**
     * Start legacy VPN and return an intent to VpnDialogs. This method is
     * used by VpnSettings and not available in ConnectivityManager.
     * Permissions are checked in Vpn class.
     * @hide
     * Start legacy VPN, controlling native daemons as needed. Creates a
     * secondary thread to perform connection work, returning quickly.
     */
    @Override
    public void startLegacyVpn(VpnConfig config, String[] racoon, String[] mtpd) {
        mVpn.startLegacyVpn(config, racoon, mtpd);
    public void startLegacyVpn(VpnProfile profile) {
        final LinkProperties egress = getActiveLinkProperties();
        if (egress == null) {
            throw new IllegalStateException("Missing active network connection");
        }
        mVpn.startLegacyVpn(profile, mKeyStore, egress);
    }

    /**
Loading