Android7.1.2修改以太网静态设置

2023-11-07

如何设置以太网有线网络静态配置

从源码看设置以太网配置调用的是EthernetManager的setConfiguration方法,在这里插入图片描述
所以我们就只需要创建IpConfiguration这个实例,他的构造方法传入值是
在这里插入图片描述
最终配置的参数就是StaticIpConfiguration这个类来配置ipAddress,gateway,dnsServers这三个值
在这里插入图片描述
涉及的类主要有,但这些都是隐藏的apk无法调用,只能通过反射进行调用,但前提是你的apk是系统apk,不然没有权限。

    private static final String ClassName_EthernetManager = "android.net.EthernetManager";
    private static final String ClassName_StaticIpConfiguration = "android.net.StaticIpConfiguration";
    private static final String ClassName_IpConfiguration = "android.net.IpConfiguration";
    private static final String ClassName_IpAssignment = "android.net.IpConfiguration$IpAssignment";
    private static final String ClassName_ProxySettings = "android.net.IpConfiguration$ProxySettings";
    private static final String ClassName_ProxyInfo = "android.net.ProxyInfo";

通过反射设置以太网静态配置的值

import android.content.Context;
import android.net.LinkAddress;
import android.util.Log;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import com.das.function.reflection.ReflectionFunctions;

public class EthernetFunctions extends ReflectionFunctions{
    private static final String ClassName_EthernetManager = "android.net.EthernetManager";
    private static final String ClassName_StaticIpConfiguration = "android.net.StaticIpConfiguration";
    private static final String ClassName_IpConfiguration = "android.net.IpConfiguration";
    private static final String ClassName_IpAssignment = "android.net.IpConfiguration$IpAssignment";
    private static final String ClassName_ProxySettings = "android.net.IpConfiguration$ProxySettings";
    private static final String ClassName_ProxyInfo = "android.net.ProxyInfo";
    EthernetFunctions(Context context) {
        super(context);
        //设置信息
    }

    public void updateEthDevInfo(boolean dhcp, String ip, String gatewayConfig, String subnetmask, String[] dns) {
        //获取EthernetManager
        try {
            final Class<?> classEthernetManager = getClass(ClassName_EthernetManager);//获取EthernetManager
            Object IEthernetManager = getSystemServiceInstance("ethernet");//获取EthernetManager实例
            Method MSetEthEnabled = getMethod(classEthernetManager, "isAvailable");
            //获取StaticIpConfiguration
            final Class<?> classStaticIpConfiguration = getClass(ClassName_StaticIpConfiguration);

            Object IStaticIpConfiguration = getNewInstance(classStaticIpConfiguration);

            Field ipAddress = getField(classStaticIpConfiguration, "ipAddress"); //获取ipAddress
            Field gateway = getField(classStaticIpConfiguration, "gateway"); //获取gateway
            Field dnsServers = getField(classStaticIpConfiguration, "dnsServers"); //获取dnsServers

            Class clazz = null;

            clazz = Class.forName("android.net.LinkAddress");

            Class[] cl = new Class[]{InetAddress.class, int.class};
            Constructor cons = null;


            cons = clazz.getConstructor(cl);

            InetAddress ipAddressValue = InetAddress.getByName("192.168.249.5");
            Object[] x = {ipAddressValue, 16};
            setField(IStaticIpConfiguration, ipAddress, (LinkAddress) cons.newInstance(x));  //ipAddress赋值

            InetAddress gatewayValue = InetAddress.getByName("192.168.249.2");
            setField(IStaticIpConfiguration, gateway, gatewayValue);  //gateway赋值

            InetAddress dnsServersValue1 = InetAddress.getByName("192.168.249.3"); //dns1
            InetAddress dnsServersValue2 = InetAddress.getByName("192.168.249.4"); //dns2
            List<InetAddress> dnsValues = new ArrayList<>();
            dnsValues.add(dnsServersValue1);
            dnsValues.add(dnsServersValue2);

            setField(IStaticIpConfiguration, dnsServers, dnsValues);  //dnsServers赋值
            Method MToString = getMethod(classStaticIpConfiguration, "toString");
            Log.i("MSetIfName", "EthernetFunctions: " + MToString.invoke(IStaticIpConfiguration));

            //获取IpConfiguration

            final Class<?> classIpConfiguration = getClass(ClassName_IpConfiguration);
            final Class<?> classIpAssignment = getClass(ClassName_IpAssignment);
            final Class<?> classProxySettings = getClass(ClassName_ProxySettings);
            final Class<?> classProxyInfo = getClass(ClassName_ProxyInfo);

            Object[] assignments = classIpAssignment.getEnumConstants();  //获取枚举值
            Object[] proxySettings = classProxySettings.getEnumConstants(); //获取枚举值

            Constructor constructor = classIpConfiguration.getConstructor(classIpAssignment, classProxySettings, classStaticIpConfiguration, classProxyInfo);
            Object IIpConfiguration = constructor.newInstance(assignments[0], proxySettings[1], IStaticIpConfiguration, null);
            Method MSetConfiguration = getMethod(classEthernetManager, "setConfiguration",classIpConfiguration);


            invokeMethod(MSetConfiguration, IEthernetManager, IIpConfiguration);//设置值


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

反射工具类

import android.content.Context;
import android.util.Log;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectionFunctions {

    public static Process ExecRuntimeCommand(String command) {
        try {
            return Runtime.getRuntime().exec(command);
        } catch (IOException e) {
            Log.e("execRuntimeCommand", e.getMessage());
        }
        return null;
    }

    public static Process ExecRuntimeSUCommand(String command) {
        try {
            return Runtime.getRuntime().exec(new String[]{"su", "-c", command});
        } catch (IOException e) {
            Log.e("execRuntimeCommand", e.getMessage());
        }
        return null;
    }

    private Context context;

    public static Boolean TRUE = Boolean.TRUE;
    public static Boolean FALSE = Boolean.FALSE;
    public static Class<?> BOOLEAN = Boolean.TYPE;
    public static Class<?> CHAR = char.class;
    public static Class<?> INT = int.class;
    public static Class<?> SHORT = short.class;
    public static Class<?> LONG = long.class;
    public static Class<?> FLOAT = float.class;
    public static Class<?> DOUBLE = double.class;
    public static Class<?> BYTE = byte.class;
    public static Class<?> STRING = String.class;

    public ReflectionFunctions(Context context) {
        this.context = context;
    }

    public Context getContext() {
        return context;
    }

    protected Process execRuntimeCommand(String command) {
        return ReflectionFunctions.ExecRuntimeCommand(command);
    }

    protected Process execRuntimeSUCommand(String command) {
        return ReflectionFunctions.ExecRuntimeSUCommand(command);
    }

    protected Class<?> getClass(String className) throws ClassNotFoundException {
        return Class.forName(className);
    }

    protected Object getNewInstance(Class<?> classType) throws IllegalAccessException, InstantiationException {
        return classType.newInstance();
    }

    protected Object getSystemServiceInstance(String name) {
        return getContext().getSystemService(name);
    }

    protected Method getMethod(String className, String methodName, Class<?>... params) throws ClassNotFoundException, NoSuchMethodException {
        return getMethod(getClass(className), methodName, params);
    }

    protected Method getMethod(Class<?> classType, String methodName, Class<?>... params) throws NoSuchMethodException {
        return classType.getMethod(methodName, params);
    }

    protected Field getField(Class<?> classType,String fieldName) throws NoSuchFieldException {
        return classType.getField(fieldName);
    }

    protected void setField(Object classInstance,Field field,Object value) throws NoSuchFieldException, IllegalAccessException {
        field.setAccessible(true);
        field.set(classInstance,value);
    }

    protected Object invokeMethod(Method method, Object classInstance, Object... methodParams) throws InvocationTargetException, IllegalAccessException {
        try {
            return method.invoke(classInstance, methodParams);
        } catch (SecurityException e) {
            new ReflectionException("", e).printStackTrace();
            method.setAccessible(true);
            return invokeMethod(method, classInstance, methodParams);
        }
    }

    private static class ReflectionException extends RuntimeException {
        private ReflectionException(String message, Exception exception) {
            super(message, exception);
        }
    }

附主要类源码

/*
 * Copyright (C) 2014 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 android.net;

import android.content.Context;
import android.net.IEthernetManager;
import android.net.IEthernetServiceListener;
import android.net.IpConfiguration;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;

import java.util.ArrayList;

/**
 * A class representing the IP configuration of the Ethernet network.
 *
 * @hide
 */
public class EthernetManager {
    private static final String TAG = "EthernetManager";
    private static final int MSG_AVAILABILITY_CHANGED = 1000;

    private final Context mContext;
    private final IEthernetManager mService;
    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == MSG_AVAILABILITY_CHANGED) {
                boolean isAvailable = (msg.arg1 == 1);
                for (Listener listener : mListeners) {
                    listener.onAvailabilityChanged(isAvailable);
                }
            }
        }
    };
    private final ArrayList<Listener> mListeners = new ArrayList<Listener>();
    private final IEthernetServiceListener.Stub mServiceListener =
            new IEthernetServiceListener.Stub() {
                @Override
                public void onAvailabilityChanged(boolean isAvailable) {
                    mHandler.obtainMessage(
                            MSG_AVAILABILITY_CHANGED, isAvailable ? 1 : 0, 0, null).sendToTarget();
                }
            };

    /**
     * A listener interface to receive notification on changes in Ethernet.
     */
    public interface Listener {
        /**
         * Called when Ethernet port's availability is changed.
         * @param isAvailable {@code true} if one or more Ethernet port exists.
         */
        public void onAvailabilityChanged(boolean isAvailable);
    }

    /**
     * Create a new EthernetManager instance.
     * Applications will almost always want to use
     * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
     * the standard {@link android.content.Context#ETHERNET_SERVICE Context.ETHERNET_SERVICE}.
     */
    public EthernetManager(Context context, IEthernetManager service) {
        mContext = context;
        mService = service;
    }

    /**
     * Get Ethernet configuration.
     * @return the Ethernet Configuration, contained in {@link IpConfiguration}.
     */
    public IpConfiguration getConfiguration() {
        try {
            return mService.getConfiguration();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Set Ethernet configuration.
     */
    public void setConfiguration(IpConfiguration config) {
        try {
            mService.setConfiguration(config);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Indicates whether the system currently has one or more
     * Ethernet interfaces.
     */
    public boolean isAvailable() {
        try {
            return mService.isAvailable();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Adds a listener.
     * @param listener A {@link Listener} to add.
     * @throws IllegalArgumentException If the listener is null.
     */
    public void addListener(Listener listener) {
        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null");
        }
        mListeners.add(listener);
        if (mListeners.size() == 1) {
            try {
                mService.addListener(mServiceListener);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
     * Removes a listener.
     * @param listener A {@link Listener} to remove.
     * @throws IllegalArgumentException If the listener is null.
     */
    public void removeListener(Listener listener) {
        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null");
        }
        mListeners.remove(listener);
        if (mListeners.isEmpty()) {
            try {
                mService.removeListener(mServiceListener);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }
}

/*
 * Copyright (C) 2014 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 android.net;

import android.net.StaticIpConfiguration;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * A class representing a configured network.
 * @hide
 */
public class IpConfiguration implements Parcelable {
    private static final String TAG = "IpConfiguration";

    public enum IpAssignment {
        /* Use statically configured IP settings. Configuration can be accessed
         * with staticIpConfiguration */
        STATIC,
        /* Use dynamically configured IP settigns */
        DHCP,
        /* no IP details are assigned, this is used to indicate
         * that any existing IP settings should be retained */
        UNASSIGNED
    }

    public IpAssignment ipAssignment;

    public StaticIpConfiguration staticIpConfiguration;

    public enum ProxySettings {
        /* No proxy is to be used. Any existing proxy settings
         * should be cleared. */
        NONE,
        /* Use statically configured proxy. Configuration can be accessed
         * with httpProxy. */
        STATIC,
        /* no proxy details are assigned, this is used to indicate
         * that any existing proxy settings should be retained */
        UNASSIGNED,
        /* Use a Pac based proxy.
         */
        PAC
    }

    public ProxySettings proxySettings;

    public ProxyInfo httpProxy;

    private void init(IpAssignment ipAssignment,
                      ProxySettings proxySettings,
                      StaticIpConfiguration staticIpConfiguration,
                      ProxyInfo httpProxy) {
        this.ipAssignment = ipAssignment;
        this.proxySettings = proxySettings;
        this.staticIpConfiguration = (staticIpConfiguration == null) ?
                null : new StaticIpConfiguration(staticIpConfiguration);
        this.httpProxy = (httpProxy == null) ?
                null : new ProxyInfo(httpProxy);
    }

    public IpConfiguration() {
        init(IpAssignment.UNASSIGNED, ProxySettings.UNASSIGNED, null, null);
    }

    public IpConfiguration(IpAssignment ipAssignment,
                           ProxySettings proxySettings,
                           StaticIpConfiguration staticIpConfiguration,
                           ProxyInfo httpProxy) {
        init(ipAssignment, proxySettings, staticIpConfiguration, httpProxy);
    }

    public IpConfiguration(IpConfiguration source) {
        this();
        if (source != null) {
            init(source.ipAssignment, source.proxySettings,
                 source.staticIpConfiguration, source.httpProxy);
        }
    }

    public IpAssignment getIpAssignment() {
        return ipAssignment;
    }

    public void setIpAssignment(IpAssignment ipAssignment) {
        this.ipAssignment = ipAssignment;
    }

    public StaticIpConfiguration getStaticIpConfiguration() {
        return staticIpConfiguration;
    }

    public void setStaticIpConfiguration(StaticIpConfiguration staticIpConfiguration) {
        this.staticIpConfiguration = staticIpConfiguration;
    }

    public ProxySettings getProxySettings() {
        return proxySettings;
    }

    public void setProxySettings(ProxySettings proxySettings) {
        this.proxySettings = proxySettings;
    }

    public ProxyInfo getHttpProxy() {
        return httpProxy;
    }

    public void setHttpProxy(ProxyInfo httpProxy) {
        this.httpProxy = httpProxy;
    }

    @Override
    public String toString() {
        StringBuilder sbuf = new StringBuilder();
        sbuf.append("IP assignment: " + ipAssignment.toString());
        sbuf.append("\n");
        if (staticIpConfiguration != null) {
            sbuf.append("Static configuration: " + staticIpConfiguration.toString());
            sbuf.append("\n");
        }
        sbuf.append("Proxy settings: " + proxySettings.toString());
        sbuf.append("\n");
        if (httpProxy != null) {
            sbuf.append("HTTP proxy: " + httpProxy.toString());
            sbuf.append("\n");
        }

        return sbuf.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }

        if (!(o instanceof IpConfiguration)) {
            return false;
        }

        IpConfiguration other = (IpConfiguration) o;
        return this.ipAssignment == other.ipAssignment &&
                this.proxySettings == other.proxySettings &&
                Objects.equals(this.staticIpConfiguration, other.staticIpConfiguration) &&
                Objects.equals(this.httpProxy, other.httpProxy);
    }

    @Override
    public int hashCode() {
        return 13 + (staticIpConfiguration != null ? staticIpConfiguration.hashCode() : 0) +
               17 * ipAssignment.ordinal() +
               47 * proxySettings.ordinal() +
               83 * httpProxy.hashCode();
    }

    /** Implement the Parcelable interface */
    public int describeContents() {
        return 0;
    }

    /** Implement the Parcelable interface  */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(ipAssignment.name());
        dest.writeString(proxySettings.name());
        dest.writeParcelable(staticIpConfiguration, flags);
        dest.writeParcelable(httpProxy, flags);
    }

    /** Implement the Parcelable interface */
    public static final Creator<IpConfiguration> CREATOR =
        new Creator<IpConfiguration>() {
            public IpConfiguration createFromParcel(Parcel in) {
                IpConfiguration config = new IpConfiguration();
                config.ipAssignment = IpAssignment.valueOf(in.readString());
                config.proxySettings = ProxySettings.valueOf(in.readString());
                config.staticIpConfiguration = in.readParcelable(null);
                config.httpProxy = in.readParcelable(null);
                return config;
            }

            public IpConfiguration[] newArray(int size) {
                return new IpConfiguration[size];
            }
        };
}

/*
 * Copyright (C) 2014 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 android.net;

import android.net.LinkAddress;
import android.os.Parcelable;
import android.os.Parcel;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Class that describes static IP configuration.
 *
 * This class is different from LinkProperties because it represents
 * configuration intent. The general contract is that if we can represent
 * a configuration here, then we should be able to configure it on a network.
 * The intent is that it closely match the UI we have for configuring networks.
 *
 * In contrast, LinkProperties represents current state. It is much more
 * expressive. For example, it supports multiple IP addresses, multiple routes,
 * stacked interfaces, and so on. Because LinkProperties is so expressive,
 * using it to represent configuration intent as well as current state causes
 * problems. For example, we could unknowingly save a configuration that we are
 * not in fact capable of applying, or we could save a configuration that the
 * UI cannot display, which has the potential for malicious code to hide
 * hostile or unexpected configuration from the user: see, for example,
 * http://b/12663469 and http://b/16893413 .
 *
 * @hide
 */
public class StaticIpConfiguration implements Parcelable {
    public LinkAddress ipAddress;
    public InetAddress gateway;
    public final ArrayList<InetAddress> dnsServers;
    public String domains;

    public StaticIpConfiguration() {
        dnsServers = new ArrayList<InetAddress>();
    }

    public StaticIpConfiguration(StaticIpConfiguration source) {
        this();
        if (source != null) {
            // All of these except dnsServers are immutable, so no need to make copies.
            ipAddress = source.ipAddress;
            gateway = source.gateway;
            dnsServers.addAll(source.dnsServers);
            domains = source.domains;
        }
    }

    public void clear() {
        ipAddress = null;
        gateway = null;
        dnsServers.clear();
        domains = null;
    }

    /**
     * Returns the network routes specified by this object. Will typically include a
     * directly-connected route for the IP address's local subnet and a default route. If the
     * default gateway is not covered by the directly-connected route, it will also contain a host
     * route to the gateway as well. This configuration is arguably invalid, but it used to work
     * in K and earlier, and other OSes appear to accept it.
     */
    public List<RouteInfo> getRoutes(String iface) {
        List<RouteInfo> routes = new ArrayList<RouteInfo>(3);
        if (ipAddress != null) {
            RouteInfo connectedRoute = new RouteInfo(ipAddress, null, iface);
            routes.add(connectedRoute);
            if (gateway != null && !connectedRoute.matches(gateway)) {
                routes.add(RouteInfo.makeHostRoute(gateway, iface));
            }
        }
        if (gateway != null) {
            routes.add(new RouteInfo((IpPrefix) null, gateway, iface));
        }
        return routes;
    }

    /**
     * Returns a LinkProperties object expressing the data in this object. Note that the information
     * contained in the LinkProperties will not be a complete picture of the link's configuration,
     * because any configuration information that is obtained dynamically by the network (e.g.,
     * IPv6 configuration) will not be included.
     */
    public LinkProperties toLinkProperties(String iface) {
        LinkProperties lp = new LinkProperties();
        lp.setInterfaceName(iface);
        if (ipAddress != null) {
            lp.addLinkAddress(ipAddress);
        }
        for (RouteInfo route : getRoutes(iface)) {
            lp.addRoute(route);
        }
        for (InetAddress dns : dnsServers) {
            lp.addDnsServer(dns);
        }
        lp.setDomains(domains);
        return lp;
    }

    public String toString() {
        StringBuffer str = new StringBuffer();

        str.append("IP address ");
        if (ipAddress != null ) str.append(ipAddress).append(" ");

        str.append("Gateway ");
        if (gateway != null) str.append(gateway.getHostAddress()).append(" ");

        str.append(" DNS servers: [");
        for (InetAddress dnsServer : dnsServers) {
            str.append(" ").append(dnsServer.getHostAddress());
        }

        str.append(" ] Domains ");
        if (domains != null) str.append(domains);
        return str.toString();
    }

    public int hashCode() {
        int result = 13;
        result = 47 * result + (ipAddress == null ? 0 : ipAddress.hashCode());
        result = 47 * result + (gateway == null ? 0 : gateway.hashCode());
        result = 47 * result + (domains == null ? 0 : domains.hashCode());
        result = 47 * result + dnsServers.hashCode();
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;

        if (!(obj instanceof StaticIpConfiguration)) return false;

        StaticIpConfiguration other = (StaticIpConfiguration) obj;

        return other != null &&
                Objects.equals(ipAddress, other.ipAddress) &&
                Objects.equals(gateway, other.gateway) &&
                dnsServers.equals(other.dnsServers) &&
                Objects.equals(domains, other.domains);
    }

    /** Implement the Parcelable interface */
    public static Creator<StaticIpConfiguration> CREATOR =
        new Creator<StaticIpConfiguration>() {
            public StaticIpConfiguration createFromParcel(Parcel in) {
                StaticIpConfiguration s = new StaticIpConfiguration();
                readFromParcel(s, in);
                return s;
            }

            public StaticIpConfiguration[] newArray(int size) {
                return new StaticIpConfiguration[size];
            }
        };

    /** Implement the Parcelable interface */
    public int describeContents() {
        return 0;
    }

    /** Implement the Parcelable interface */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(ipAddress, flags);
        NetworkUtils.parcelInetAddress(dest, gateway, flags);
        dest.writeInt(dnsServers.size());
        for (InetAddress dnsServer : dnsServers) {
            NetworkUtils.parcelInetAddress(dest, dnsServer, flags);
        }
        dest.writeString(domains);
    }

    protected static void readFromParcel(StaticIpConfiguration s, Parcel in) {
        s.ipAddress = in.readParcelable(null);
        s.gateway = NetworkUtils.unparcelInetAddress(in);
        s.dnsServers.clear();
        int size = in.readInt();
        for (int i = 0; i < size; i++) {
            s.dnsServers.add(NetworkUtils.unparcelInetAddress(in));
        }
        s.domains = in.readString();
    }
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android7.1.2修改以太网静态设置 的相关文章

  • MaterialComponents AlertDialog 文本颜色

    Reading MaterialComponents 主题警报对话框按钮 https stackoverflow com questions 52829954 materialcomponents theme alert dialog bu
  • 如何在datepickerdialog android中选择年份?

    我是 Android 编程新手 请帮忙 我正在使用创建材料设计的片段DatePickerDialog点击EditText 问题是它设置为当前日期 由我设置 但是 如果用户必须选择过去的日期 比如说 10 年前 用户必须每月滚动 这是痛苦的
  • 无法在 Android 模拟器上使用 ART

    我只是想在我的模拟器上尝试 android 4 4 的 ART 我所做的是创建一个模拟器 选择设备为 Nexus 7 目标为 Android 4 4 RAM 512 然后我启动模拟器并加载它 然后我进入开发者选项并选择运行时作为 ART 设
  • 我应该将 onClickListener 放在自定义 ListView 的哪里?

    我正在定制ListView包含 a 的行数CheckBox and a TextView 在我使用自定义之前ListViews使用 SimpleCursorAdapter 我的onListItemClick 工作得很好 我读过我必须添加一个
  • java.lang.RuntimeException:release()后调用的方法

    If i am 不使用 相机 release in 表面被破坏 then 无法从另一个 Activity 再次启动 CameraActivity 简而言之 得到不幸的是应用程序已停止 错误 即使不释放相机 但如果我确实点击了 主页 按钮 来
  • 使用 firebase 按最新消息对聊天列表进行排序

    我不知道为什么我陷入了一个问题chatList不按最后一条消息时间或最新消息排序 我尝试过存储timestamp在数据库中和订单子依据时间戳 但它仍然不起作用 不起作用意味着列表不会在每条消息后排序 并继续将列表显示为在第一条消息后排序 看
  • 如何自动下载 Google 签名的通用 APK 以在 Google Play 之外分发?

    我有使用 Play 应用签名的应用 我想将应用程序上传到华为应用程序库 Google 建议从捆绑资源管理器下载已签名的通用 APK 然后上传到 Google Play 之外的商店 如果您还在 Google Play 之外分发您的应用或计划
  • 错误:包 com.google.android.gms.appstate 不存在

    由于此错误 无法编译我的 android 项目 BaseGameUtils src main java com google example games basegameutils GameHelper java Error 32 39 e
  • 在Android中绘制圆角矩形

    我已经发现这个问题 https stackoverflow com questions 5618402 how to draw rounded rectangle in android ui解决方案是这段代码
  • 如何在Android data/data/project文件系统中创建文件目录和文件夹

    我正在开发一个视频编辑器程序 并且对 android 和 java 相当陌生 我希望发生的是 当用户按下 创建新项目 按钮时 会弹出一个对话框 询问用户项目的名称 我已经把那部分写下来了 但是我想要的是 当用户在该对话框上按 确定 时 我的
  • 无法仅在控制台中启动 androidstudio

    你好 我的问题是下一个 我下载了Android Studio如果我去 路径 android studio bin 我执行studio sh 我收到以下错误 No JDK found Please validate either STUDIO
  • setKeyListener 将覆盖 setInputType 并更改键盘

    大家好 我在两个设备之间遇到问题 在实践中使用InputType和KeyListener我正在操纵一个EditText让它从数字键盘接收逗号和数字 有关更多背景信息 请检查我之前的question https stackoverflow c
  • 三星 tab2 平板电脑的 Android 开发

    是否可以使用 Eclipse 在 Samsung Tab 2 平板电脑中开发 Android 应用程序 需要安装什么驱动吗 当然可以 你必须安装标准的android开发工具 SDK ADT ad eclipse Juno最新版本 从这里下载
  • Android 4 上的 html5 视频:全屏播放然后重定向到另一个网页 - 不起作用

    我正在为 Android 4 智能手机设计一个 html5 页面 其中包含一个 3gpp 或 mp4 视频 打开时必须自动全屏播放 当视频结束时应该重定向到另一个网址 一些谷歌搜索告诉我 Android 4 上不再允许自动播放 因此我选择显
  • DialogFragment在Android中的位置

    我有一个DialogFragment显示一个View就像弹出屏幕一样 窗口始终出现在屏幕中间 有没有办法设置位置DialogFragment窗户 我已经查看了但还没有找到任何东西 尝试这样的事情 Override public View o
  • 在运行时用Dagger添加Retrofit RequestInterceptor

    我正在使用匕首和改装 我用 Dagger 注入我的 Retrofit 服务 现在我想做一个授权请求来获取 accessToken 之后 我想使用请求拦截器来增强我的 api 模块 以便将此访问令牌用于将来的请求 我的想法是在收到访问令牌后使
  • 将视图放置在 ConstraintLayout 之外

    我想将视图放置在ConstraintLayout用滑动动画来制作它们的动画 我尝试过设置像这样的约束constraintBottom toTopOf parent 但是View留在容器内 请注意 我希望通过使用内置动画的约束来实现此目的 而
  • Eclipse:缺少 Java 构建路径

    我正在尝试使用 Eclipse 来使用适用于 Android 的 Google SDK 教程 我能够让前两个项目正常工作 但是当运行第三个 R java 时消失了 所以我放弃了 我根据练习 3 的解决方案集制作了一个全新的包 它充满了错误
  • 有什么方法可以禁用/覆盖 Galaxy Tab 4 上的多任务按钮吗? [复制]

    这个问题在这里已经有答案了 我们编写了一个工业控制应用程序 并随我们的制造产品预装在三星 Galaxy 平板电脑上 我们使用的平板电脑是运行 Honeycomb 的 Tab 10 但我们无法再获得足够的 OEM 平板电脑 因此我们改用运行
  • RecyclerView 不调用 onCreateViewHolder 或 onBindView

    没有收到任何错误 所有数据似乎都有效 由于某种原因 没有调用与视图相关的方法 我已确定以下事项 getItemCount 是唯一被调用的适配器方法 并且返回一个正整数值 我知道这将是你们将要查看的区域 构造函数正在被调用 成员变量有效 Pa

随机推荐

  • mysql8设置sql_mode

    原文 mysql8报错 在mysql配置文件下设置 sql mode NO AUTO VALUE ON ZERO STRICT TRANS TABLES NO ZERO IN DATE NO ZERO DATE ERROR FOR DIVI
  • 重磅!阿里推出国产开源的jdk!

    简介 Alibaba Dragonwell 是一款免费的 生产就绪型Open JDK 发行版 提供长期支持 包括性能增强和安全修复 阿里巴巴拥有最丰富的Java应用场景 覆盖电商 金融 物流等众多领域 世界上最大的Java用户之一 Alib
  • 同样25岁,为什么有人事业有成,有人却一无所有?

    文章来源知乎 https www zhihu com question 21726594 文 陈彬 我刚过24周岁的生日 虚岁的话也算是25了 说下自己吧 我是农村孩子 我爸是木工 初中文化 我妈是农村妇女 小学没上完 算认得几个字 我上面
  • shell 向 awk 传递变量参数

    本文翻译自StackOverflow提问 How do I use shell variables in an awk script 但更改了文章段落结构和部分表述 方式1 使用 v 选项 最好的方式 兼容性最佳 使用 v选项 P S 记得
  • eclipse 快捷键大全

    1 Eclipse常用快捷键 1 Ctrl Space 说明 内容助理 提供对方法 变量 参数 javadoc等得提示 应运在多种场合 总之需要提示的时候可先按此快捷键 注 避免输入法的切换设置与此设置冲突 2 Ctrl Shift Spa
  • Windows系统route add delete change路由增加改变删除

    1 管理员身份打开命令行cmd 注 如遇到需上升操作权限 是因为没有使用管理员身份运行cmd 搜索输入cmd 右击 以管理员身份 或者win10右击win图标 选择命令提示符 管理员 2 route 路由 详细操作 输入route 可以看到
  • 聊聊ChatGPT是如何组织对话的

    为什么要组织对话 总所周知 ChatGPT的训练大致可分为下图中展示的几个阶段 其中 在Pretraining阶段 模型的训练数据是纯文本 目标是根据上文预测下一个token 而在后面的几个阶段中 为了让模型具备对话的能力 相应的就需要使用
  • 腾讯QQ 桌面版的内存优化探索与总结

    大厂技术 高级前端 Node进阶 点击上方 程序员成长指北 关注公众号 回复1 加入高级Node交流群 相比用户停留时间短 用完即走的 Web 页面 桌面 QQ 用户在一次登录后 可能会挂机一周以上 这段期间 如果没有严格控制好 QQ 内存
  • 07 Vue中样式绑定方法 三种方法汇总

    1 第一种方法 使用class 进行绑定样 通过 activated 真假来控制 div div div div
  • Redis数据类型

    目前Redis数据库支持5种数据类型 分别是String 字符串 Hash 哈希 List 列表 Set 集合 Sorted Set 有序集合 1 字符串 String 字符串类型是Redis中最基本的数据类型 它是二进制安全的 任何形式的
  • usb otg type-c的硬件介绍

    一 usb硬件接口 Type A Type B Type C Mini usb Micro usb 1 typeA 2 Type b 3 Type c 4 Mini usb 5 Micro usb 二 usb线序 1 Usb2 0 usb2
  • 【数据库软件(MySQL)学习】day01

    数据库 database 保存有组织的数据的容器 通常是一个文件或一组文件 DBMS 数据库管理系统 即数据库管理软件 数据库是通过DBMS创建和操纵的容器 表 table 某种特定类型数据的结构化清单 模式 scheme 关于数据库和表的
  • QT开发之过滤器

    1 使用 需要先添加 ui gt lineEdit gt installEventFilter this 在窗体上为lineEdit1安装过滤器 头文件声明 bool eventFilter QObject QEvent 过滤器 bool
  • 成功解决:RuntimeError: DataLoader worker (pid(s) XXX) exited unexpectedly

    num workers是用来指定开多进程的数量 默认值为0 表示不启用多进程 将num workers改为0即可 0是默认值
  • iTab浏览器插件安装教程

    iTab浏览器插件 iTab是一个好看好用的自定义卡片式浏览器新标签页扩展 安装iTab标签页扩展后 您将告别呆板无趣的原生标签页 享受iTab标签页为您带来的个性化新体验 离线资源下载 iTab资源 安装教程 IE 浏览器 1 打开浏览器
  • 百度文本内容审核

    百度提供了免费的文本内容审核 响应时间在1秒左右 第一步 在百度开发账号中创建应用 获取配置信息 百度图片审核配置信息 public class BaiduSensitiveConfig 1 app id public static fin
  • 关于BatchNorm,我们需要了解什么(一)

    一 前言 准备写一个系列的文章 关于BatchNorm 本文的主要内容是对BN技术做一个汇总 默认读者已经了解BN层的主要工作原理 理解BN算法中每个参数的含义以及在训练和推理过程中的算法原理 1 BN存在的问题以及在必须使用BN的时候 我
  • powerDesigner反向生成数据建模图

    添加sql脚本文件 The file has been successfully reverse engineered 保存dpm文件 生成报告 建议标准模式 html就行
  • php文件注入思路

    题目描述 打开题目给定url 发现有一个文件上传按钮 猜测可能是需要上传php文件对服务器进行查看 解题步骤 1 上传一个文档文档 提示无法上传 2 上传一张jpg图像 发现给定了图像存储的路径 3 于是使用浏览器权限绕过的方式 上传php
  • Android7.1.2修改以太网静态设置

    如何设置以太网有线网络静态配置 从源码看设置以太网配置调用的是EthernetManager的setConfiguration方法 所以我们就只需要创建IpConfiguration这个实例 他的构造方法传入值是 最终配置的参数就是Stat