安卓11添加切换以太网动态静态方法
客户要在app中自由切换动态,静态方法,直接把系统jar-api给他搞了半天搞不定,只有在系统里给他实现一个接口,方法如下:
Index: packages/apps/Settings/AndroidManifest.xml
===================================================================
--- packages/apps/Settings/AndroidManifest.xml	(revision 868)
+++ packages/apps/Settings/AndroidManifest.xml	(revision 869)
@@ -5,7 +5,7 @@android:sharedUserId="android.uid.system"><original-package android:name="com.android.settings" />
-
+     <uses-permission android:name="android.net.action.ETHERNET_IP_CHANGED"/><uses-permission android:name="android.permission.REQUEST_NETWORK_SCORES" /><uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" /><uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
@@ -3504,6 +3504,14 @@</intent-filter>/></receiver>+	<receiver android:name=".ethernet.EtherentBoardcastReceiver"
+			 android:enabled="true"
+			 android:exported="true">
+             <intent-filter android:priority="1000">
+                <action android:name="android.net.action.ETHERNET_IP_CHANGED" />
+            </intent-filter>
+        </receiver>
+<!-- This is the longest AndroidManifest.xml ever. --></application></manifest>
Index: packages/apps/Settings/src/com/android/settings/ethernet/EtherentBoardcastReceive.java
===================================================================
--- packages/apps/Settings/src/com/android/settings/ethernet/EtherentBoardcastReceive.java     (nonexistent)
+++ packages/apps/Settings/src/com/android/settings/ethernet/EtherentBoardcastReceive.java     (revision 869)
@@ -0,0 +1,220 @@
+package com.android.settings.ethernet;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.admin.DevicePolicyManager;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.PreferenceScreen;
+import android.provider.SearchIndexableResource;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.Log;
+import android.content.Intent;
+
+import androidx.preference.SwitchPreference;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.File;
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import java.util.regex.Pattern;
+import java.lang.Integer;
+import java.net.InetAddress;
+import java.net.Inet4Address;
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.Preference.OnPreferenceClickListener;
+
+import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment;
+
+
+/*for 5.0*/
+import android.net.EthernetManager;
+import android.net.IpConfiguration;
+import android.net.IpConfiguration.IpAssignment;
+import android.net.IpConfiguration.ProxySettings;
+import android.net.wifi.SupplicantState;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.net.StaticIpConfiguration;
+import android.net.NetworkUtils;
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import android.widget.Toast;
+//import android.preference.ListPreference;
+//import com.android.internal.logging.MetricsProto.MetricsEvent;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+
+
+import com.android.settings.ethernet.ethernet_static_ip_dialog;
+public class EtherentBoardcastReceiver extends BroadcastReceiver  {
+	private static final String TAG = "EtherentBoardcastReceiver";
+	 
+	private  static String mEthMode = null
+    private  static String mEthIpAddress = null;
+    private  static String mEthNetmask = null;
+    private  static String mEthGateway = null;
+    private  static String mEthdns1 = null;
+    private  static String mEthdns2 = null;
+
+    private final static String nullIpInfo = "0.0.0.0";
+	private String mIfaceName;
+	 @Override
+    public void onReceive(Context context, Intent intent) {
+
+			IpConfiguration mIpConfiguration;
+			StaticIpConfiguration mStaticIpConfiguration;
+			String action = intent.getAction();
+		    Log.i(TAG, "receive a new action : " + action);
+			
+			EthernetManager mEthManager = (EthernetManager) context.getSystemService(Context.ETHERNET_SERVICE);
+			if(mEthManager == null){
+				Log.i(TAG, "fail to getSystemService :  "+Context.ETHERNET_SERVICE);
+			}
+
+		  mStaticIpConfiguration =new StaticIpConfiguration();
+		  getNetConfigFromIntent(intent);
+		 /*
+		  * get ip address, netmask,dns ,gw etc.
+		  */
+		String[] ifaces = mEthManager.getAvailableInterfaces();
+        if (ifaces.length > 0) {
+            mIfaceName = ifaces[0];//"eth0";
+        }
+        if (null == mIfaceName) {
+            Log.e(TAG, "get ethernet ifaceName failed");
+            
+        }
+
+
+		if (mEthMode  == null ||mEthMode.equals("static"))
+		{
+			 Inet4Address inetAddr = getIPv4Address(this.mEthIpAddress);
+			int prefixLength = maskStr2InetMask(this.mEthNetmask); 
+			InetAddress gatewayAddr = getIPv4Address(this.mEthGateway); 
+			InetAddress dnsAddr1 = getIPv4Address(this.mEthdns1);
+			InetAddress dnsAddr2 = getIPv4Address(this.mEthdns2);
+			if(inetAddr ==null || gatewayAddr == null || prefixLength <= 0  ){
+				  Log.e(TAG,"ip,mask or dnsAddr is wrong");
+				  return ;
+			}
+			if (inetAddr.getAddress().toString().isEmpty() || prefixLength ==0 || gatewayAddr.toString().isEmpty()
+			  ) {
+				   Log.e(TAG,"ip,mask or dnsAddr is wrong");
+				  return ;
+			}
+			  
+			mStaticIpConfiguration.ipAddress = new LinkAddress(inetAddr, prefixLength);
+			mStaticIpConfiguration.gateway=gatewayAddr;
+			if(dnsAddr1 != null && !dnsAddr1.toString().isEmpty())
+				mStaticIpConfiguration.dnsServers.add(dnsAddr1);
+			if(dnsAddr2 != null && !dnsAddr2.toString().isEmpty())
+				mStaticIpConfiguration.dnsServers.add(dnsAddr2);
+		
+			mIpConfiguration=new IpConfiguration(IpAssignment.STATIC, ProxySettings.NONE,mStaticIpConfiguration,null);  
+			mEthManager.setConfiguration(mIfaceName, mIpConfiguration); 
+		}else{
+			mEthManager.setConfiguration(mIfaceName, new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE,null,null));
+		}
+       
+		//
+		
+    }
+	
+	private void getNetConfigFromIntent(Intent intent){
+		Bundle bundle = intent.getExtras();
+        if (bundle.getString("netMode") != null)
+			this.mEthMode = bundle.getString("netMode");
+		if (bundle.getString("ipaddr") != null)
+			this.mEthIpAddress = bundle.getString("ipaddr");
+		if (bundle.getString("netMask")!= null)
+			this.mEthNetmask = bundle.getString("netMask");
+		if (bundle.getString("gateway")!= null)
+			this.mEthGateway = bundle.getString("gateway");
+		if (bundle.getString("dns1") != null)
+			this.mEthdns1 = bundle.getString("dns1");
+		if (bundle.getString("dns2") != null)
+			this.mEthdns2 = bundle.getString("dns2");
+	}
+	 private Inet4Address getIPv4Address(String text) {
+        try {
+            return (Inet4Address) NetworkUtils.numericToInetAddress(text);
+        } catch (IllegalArgumentException|ClassCastException e) {
+            return null;
+        }
+    }
+
+	 /*
+     * convert subMask string to prefix length
+     */
+    private int maskStr2InetMask(String maskStr) {
+    	StringBuffer sb ;
+    	String str;
+    	int inetmask = 0; 
+    	int count = 0;
+    	/*
+    	 * check the subMask format
+    	 */
+      	Pattern pattern = Pattern.compile("(^((\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])$)|^(\\d|[1-2]\\d|3[0-2])$");
+    	if (pattern.matcher(maskStr).matches() == false) {
+    		Log.e(TAG,"subMask is error");
+    		return 0;
+    	}
+    	
+    	String[] ipSegment = maskStr.split("\\.");
+    	for(int n =0; n<ipSegment.length;n++) {
+    		sb = new StringBuffer(Integer.toBinaryString(Integer.parseInt(ipSegment[n])));
+    		str = sb.reverse().toString();
+    		count=0;
+    		for(int i=0; i<str.length();i++) {
+    			i=str.indexOf("1",i);
+    			if(i==-1)  
+    				break;
+    			count++;
+    		}
+    		inetmask+=count;
+    	}
+    	return inetmask;
+    }
+
+
+
+}
+
相关文章:
安卓11添加切换以太网动态静态方法
客户要在app中自由切换动态,静态方法,直接把系统jar-api给他搞了半天搞不定,只有在系统里给他实现一个接口,方法如下: Index: packages/apps/Settings/AndroidManifest.xml--- packages/apps/Settings/AndroidManifes…...
初级数据结构(五)——树和二叉树的概念
文中代码源文件已上传:数据结构源码 <-上一篇 初级数据结构(四)——队列 | NULL 下一篇-> 1、树结构(Tree) 1.1、树结构的特点 自然界中的树由根部开始向上生长,随机长出分支&…...
pdf读取内容缺失(漏字/文字丢失)问题
项目中遇到pdf文件漏字,由于文件涉密,不能展示,简单描述一下: 比如原pff中 姓名:张三 读取结果中:空白:张三 即:原文件说是银行出具的打款证明,银行内部设置了文件权限&a…...
c#面试基础语法——现有⼀个整数number,请写⼀个⽅法判断这个整数是否是2的N次⽅
1.number%20 取余(取模)只能判断number是不是2的倍数但不一定是2的N次方,如:6%20但是他并不是2的N次方 2.(number&(number-1))0 原理:如果number是2的N次方则表示2进制位只有一位是1。如:2 (…...
27系列DGUS智能屏发布:可实时播放高清模拟信号摄像头视频
针对高清晰度的模拟信号摄像头视频画面的显示需求,迪文特推出27系列DGUS智能屏。该系列智能屏可适配常见的AHD摄像头、CVBS摄像头,支持单路1080P高清显示、两路720P同屏显示(同一类型摄像头)。用户通过DGUS简单开发即可实现摄像头…...
YOLOv8改进 | 2023主干篇 | 替换LSKNet遥感目标检测主干 (附代码+修改教程+结构讲解)
一、本文介绍 本文给大家带来的改进内容是LSKNet(Large Kernel Selection, LK Selection),其是一种专为遥感目标检测设计的网络架构,其核心思想是动态调整其大的空间感受野,以更好地捕捉遥感场景中不同对象的范围上下…...
【工具】VUE 前端列表拖拽功能代码
【工具】VUE 前端列表拖拽功能代码 使用组件 yarn add sortablejs --save Sortable.js中文网 (sortablejs.com) 以下代码只是举个例子, 大家可以举一反三去实现各自的业务功能 <template><div><el-button type"primary" click"切换…...
人工智能与量子计算:开启未知领域的智慧之旅
导言 人工智能与量子计算的结合是科技领域的一场创新盛宴,引领我们进入了探索未知领域的新时代。本文将深入研究人工智能与量子计算的交汇点,探讨其原理、应用以及对计算领域的深远影响。 量子计算的崛起为人工智能领域注入了新的活力,开启了…...
2023了,前端实现AI电子秤思路分析
前景小知识: 这几年ai这个话题非常火爆,笔者从事零售行业软件开发也接到了新需求,希望实现ai电子秤,老规矩,先看需求 举个栗子: 或许,你已经留意到,当你在某些大型超市超市或生鲜类…...
CSS学习
CSS学习 1. 什么是css?2.css引入方式2.1 内嵌式2.2 外联式2.3 行内式2.4 引入方式特点 3. 基础选择器3.1 标签选择器3.2 类选择器3.3 id选择器3.4 通配符选择器 4. 文字基本样式4.1 字体样式4.1.1 字体大小4.1.2 字体粗细4.1.3 倾斜4.1.4 字体4.1.5 字体font相关属性连写 4.2 …...
Flask基本用法:一个HelloWorld,搭建服务、发起请求
目录 1、简介 2、安装 3、Flask使用示例 参考 1、简介 官网文档 Flask是一个轻量的web服务框架,我们可以利用它快速搭建一个服务,对外提供接口,其他人可以轻松调用我们的服务。这对算法工程师来说比较关键,我们通常不擅长搞开发…...
Tomcat-安装部署(源码包安装)
一、简介 Tomcat 是由 Apache 开发的一个 Servlet 容器,实现了对 Servlet 和 JSP 的支持,并提供了作为Web服务器的一些特有功能,如Tomcat管理和控制平台、安全域管理和Tomcat阀等。 简单来说,Tomcat是一个WEB应用程序的托管平台…...
【Hadoop_06】MapReduce的概述与wc案例
1、MapReduce概述1.1 MapReduce定义1.2 MapReduce优点1.3 MapReduce缺点1.4 MapReduce核心思想1.5 MapReduce进程1.6 常用数据序列化类型1.7 源码与MapReduce编程规范 2、WordCount案例实操2.1 本地测试2.2 提交到集群测试 1、MapReduce概述 1.1 MapReduce定义 MapReduce是一…...
Qt点击子窗口时父窗口标题栏高亮设计思路
父窗口调用findChildren得到其子孙窗口的列表,列表元素统一为QWidget*,遍历列表元素,每个元素调用installEventFilter,过滤QEvent::FocusIn和QEvent::FocusOut事件,做相应处理即可: QWidget* parent; QLis…...
掌握iText:轻松处理PDF文档-高级篇-添加水印
前言 iText作为一个功能强大、灵活且广泛应用的PDF处理工具,在实际项目中发挥着重要作用。通过这些文章,读者可以深入了解如何利用iText进行PDF的创建、编辑、加密和提取文本等操作,为日常开发工作提供了宝贵的参考和指导。 掌握iText&…...
深度学习基本概念
1.全连接层 全连接层就是该层的所有节点与输入节点全部相连,如图所 示。假设输入节点为X1, X 2, X 3,输出节点为 Y 1, Y 2, Y 3, Y 4。令 矩阵 W 代表全连接层的权重, W 12也就代表 …...
2023年最详细的:本地Linux服务器安装宝塔面板,并内网穿透实现公网远程登录
📚📚 🏅我是默,一个在CSDN分享笔记的博主。📚📚  🌟在这里,我要推荐给大家我的专栏《Linux》。🎯🎯 🚀无论你是编程小白,还是有一…...
基于ssm金旗帜文化培训学校网站的设计与开发论文
摘 要 互联网发展至今,无论是其理论还是技术都已经成熟,而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播,搭配信息管理工具可以很好地为人们提供服务。针对培训学校展示信息管理混乱,出错率高,信息安全…...
【Java】猜数字小游戏
规则 游戏开始随机生成4位数字符串,每个数字从0到9各不相同,比如0123玩家10次猜数机会,输入4位数字符串,每个数字从0到9各不相同游戏判断玩家输入与所猜谜底数,给出结果nAnB,A表示位置和数字都猜对的个数&…...
汽车EDI:Chrysler EDI项目案例
菲亚特克莱斯勒汽车Fiat Chrysler Automobiles(FCA)是一家全球性汽车制造商,主营产品包括轿车、SUV、皮卡车、商用车和豪华车等多种车型。其旗下品牌包括菲亚特、克莱斯勒、道奇、Jeep、Ram、阿尔法罗密欧和玛莎拉蒂等。 Chrysler通过EDI来优化订单处理、交付通知、…...
LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明
LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造,完美适配AGV和无人叉车。同时,集成以太网与语音合成技术,为各类高级系统(如MES、调度系统、库位管理、立库等)提供高效便捷的语音交互体验。 L…...
利用ngx_stream_return_module构建简易 TCP/UDP 响应网关
一、模块概述 ngx_stream_return_module 提供了一个极简的指令: return <value>;在收到客户端连接后,立即将 <value> 写回并关闭连接。<value> 支持内嵌文本和内置变量(如 $time_iso8601、$remote_addr 等)&a…...
基于uniapp+WebSocket实现聊天对话、消息监听、消息推送、聊天室等功能,多端兼容
基于 UniApp + WebSocket实现多端兼容的实时通讯系统,涵盖WebSocket连接建立、消息收发机制、多端兼容性配置、消息实时监听等功能,适配微信小程序、H5、Android、iOS等终端 目录 技术选型分析WebSocket协议优势UniApp跨平台特性WebSocket 基础实现连接管理消息收发连接…...
iPhone密码忘记了办?iPhoneUnlocker,iPhone解锁工具Aiseesoft iPhone Unlocker 高级注册版分享
平时用 iPhone 的时候,难免会碰到解锁的麻烦事。比如密码忘了、人脸识别 / 指纹识别突然不灵,或者买了二手 iPhone 却被原来的 iCloud 账号锁住,这时候就需要靠谱的解锁工具来帮忙了。Aiseesoft iPhone Unlocker 就是专门解决这些问题的软件&…...
令牌桶 滑动窗口->限流 分布式信号量->限并发的原理 lua脚本分析介绍
文章目录 前言限流限制并发的实际理解限流令牌桶代码实现结果分析令牌桶lua的模拟实现原理总结: 滑动窗口代码实现结果分析lua脚本原理解析 限并发分布式信号量代码实现结果分析lua脚本实现原理 双注解去实现限流 并发结果分析: 实际业务去理解体会统一注…...
【JavaWeb】Docker项目部署
引言 之前学习了Linux操作系统的常见命令,在Linux上安装软件,以及如何在Linux上部署一个单体项目,大多数同学都会有相同的感受,那就是麻烦。 核心体现在三点: 命令太多了,记不住 软件安装包名字复杂&…...
安宝特案例丨Vuzix AR智能眼镜集成专业软件,助力卢森堡医院药房转型,赢得辉瑞创新奖
在Vuzix M400 AR智能眼镜的助力下,卢森堡罗伯特舒曼医院(the Robert Schuman Hospitals, HRS)凭借在无菌制剂生产流程中引入增强现实技术(AR)创新项目,荣获了2024年6月7日由卢森堡医院药剂师协会࿰…...
JavaScript基础-API 和 Web API
在学习JavaScript的过程中,理解API(应用程序接口)和Web API的概念及其应用是非常重要的。这些工具极大地扩展了JavaScript的功能,使得开发者能够创建出功能丰富、交互性强的Web应用程序。本文将深入探讨JavaScript中的API与Web AP…...
纯 Java 项目(非 SpringBoot)集成 Mybatis-Plus 和 Mybatis-Plus-Join
纯 Java 项目(非 SpringBoot)集成 Mybatis-Plus 和 Mybatis-Plus-Join 1、依赖1.1、依赖版本1.2、pom.xml 2、代码2.1、SqlSession 构造器2.2、MybatisPlus代码生成器2.3、获取 config.yml 配置2.3.1、config.yml2.3.2、项目配置类 2.4、ftl 模板2.4.1、…...
基于IDIG-GAN的小样本电机轴承故障诊断
目录 🔍 核心问题 一、IDIG-GAN模型原理 1. 整体架构 2. 核心创新点 (1) 梯度归一化(Gradient Normalization) (2) 判别器梯度间隙正则化(Discriminator Gradient Gap Regularization) (3) 自注意力机制(Self-Attention) 3. 完整损失函数 二…...
