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

Commit 227ed7f0 authored by Sebastian Schmidt's avatar Sebastian Schmidt Committed by Steve Kondik
Browse files

Allow configuration of DHCP lease time in tethering

Make lease time for DHCP offers configurable via
Settings.Secure.TETHER_LEASE_TIME which is either the lease time in
seconds or Settings.Secure.TETHER_LEASE_TIME_DEFAULT for the default
lease time defined by netd.

This change depends on Ic65818fdb472a49c72fb56b1ad3ac33e4136a9a4 and
I0b369889f7f790f43f9c89da0c4e133a342debd7.

Change-Id: I2a83242bcacccb55780716845d4f67728612cc74
parent bd6eb47f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3166,6 +3166,12 @@ public final class Settings {
         */
        public static final String TETHER_DUN_APN = "tether_dun_apn";

        /** DHCP lease time for tethering in seconds {@hide} */
        public static final String TETHER_LEASE_TIME = "tether_lease_time";

        /** Default value for TETHER_LEASE_TIME {@hide} */
        public static final int TETHER_LEASE_TIME_DEFAULT = -1;

        /**
         * No longer supported.
         */
+23 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStats.UID_ALL;
import static android.net.TrafficStats.UID_TETHERING;
import static android.provider.Settings.Secure.NETSTATS_ENABLED;
import static android.provider.Settings.Secure.TETHER_LEASE_TIME;
import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED;

import android.content.Context;
@@ -90,6 +91,11 @@ public class NetworkManagementService extends INetworkManagementService.Stub
     */
    public static final String LIMIT_GLOBAL_ALERT = "globalAlert";

    /**
     * Constant representing the default DHCP lease time
     */
    public static final int DEFAULT_LEASE_TIME = -1;

    class NetdResponseCode {
        /* Keep in sync with system/netd/ResponseCode.h */
        public static final int InterfaceListResult       = 110;
@@ -731,15 +737,30 @@ public class NetworkManagementService extends INetworkManagementService.Stub

    public void startTethering(String[] dhcpRange)
            throws IllegalStateException {
        startTethering(dhcpRange, Settings.Secure.getInt(mContext.getContentResolver(),
            TETHER_LEASE_TIME, Settings.Secure.TETHER_LEASE_TIME_DEFAULT));
    }

    public void startTethering(String[] dhcpRange, int leaseTime)
             throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
        // cmd is "tether start first_start first_stop second_start second_stop ..."
        // an odd number of addrs will fail

        // cmd is "tether start first_start first_stop second_start second_stop ... [lease_time]"

        // Make sure CMD_ARGS_MAX in system/core/include/sysutils/FrameworkListener.h is big
        // enough to hold 2 (tether start) + dhcpRange.length (by default 14) + optionally
        // 1 (lease time) = (16/17) arguments.
        String cmd = "tether start";

        for (String d : dhcpRange) {
            cmd += " " + d;
        }

        if (leaseTime != Settings.Secure.TETHER_LEASE_TIME_DEFAULT) {
            cmd += " " + leaseTime;
        }

        try {
            mConnector.doCommand(cmd);
        } catch (NativeDaemonConnectorException e) {