首页 > 其他分享 >Android 13 移植EthernetSettings/Ethernet更新

Android 13 移植EthernetSettings/Ethernet更新

时间:2024-08-09 17:54:54浏览次数:8  
标签:13 service import void Connectivity ethernet Ethernet EthernetSettings android

移植EthernetSettings

Android 13 在Settings搜索没有发现以太网设置,应该是移除了,但是客户的设备需要,所以移植Android 11的.

以太网相关的功能在Android13中进行模块化,提取到packages/modules/Connectivity/中,
EthernetManager相关代码从framework移到packages/modules/Connectivity/下.

Android 13 internet界面有无网络,会显示不同的界面!

--- a/packages/modules/Connectivity/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java
+++ b/packages/modules/Connectivity/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java
@@ -16,11 +16,16 @@

 package com.android.server.ethernet;

+import static android.net.EthernetManager.ETHERNET_STATE_DISABLED;
+import static android.net.EthernetManager.ETHERNET_STATE_ENABLED;
 import static android.net.NetworkCapabilities.TRANSPORT_TEST;

 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.content.BroadcastReceiver;
 import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;

@@ -63,6 +69,14 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
         mContext = context;
         mHandler = handler;
         mTracker = tracker;
+        //add xxx
+        IntentFilter intentFilter = new IntentFilter();
+        intentFilter.addAction("xx.action.xx.ethernet.open");
+        intentFilter.addAction("xx.action.xx.ethernet.close");
+        mEthernetSwitchBroadcast = new EthernetSwitchBroadcastReceiver();
+        context.registerReceiver(mEthernetSwitchBroadcast, intentFilter);
+        //add xxx
+
     }

     private void enforceAutomotiveDevice(final @NonNull String methodName) {
@@ -77,9 +91,63 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {

     public void start() {
         Log.i(TAG, "Starting Ethernet service");
-        mTracker.start();
-        mStarted.set(true);
+        //add xxx
+        //mTracker.start();
+        //mStarted.set(true);
+        mEthernetState = getEthernetState();
+        boolean is_enabled = false;
+        if (mEthernetState == ETHERNET_STATE_ENABLED) {
+            is_enabled = true;
+        }
+        mTracker.start(is_enabled);
+        mStarted.set(is_enabled);
+        //add xxx
+    }
+
+    //add xxx
+    private EthernetSwitchBroadcastReceiver mEthernetSwitchBroadcast;
+    private int mState = -1;
+    private int mEthernetState; //-1 init 0 disable 1 enable
+
+    private int getEthernetState() {
+        int state = SystemProperties.getInt("xxx_ethernet_on", 0);
+        return state;
+    }
+
+    private void setEthernetState(int state) {
+        //SystemProperties.set("xxx__ethernet_on", state + "");
+    }
+
+    public synchronized void setState(int state) {
+        Log.i(TAG, "setState from mState=" + mState + " to state=" + state);
+        if (mState != state) {
+            mState = state;
+            if (state == ETHERNET_STATE_DISABLED) {
+                //setEthernetState(ETHERNET_STATE_DISABLED);
+                mTracker.setIntefaceState(false);
+                mStarted.set(false);
+            } else {
+                //setEthernetState(ETHERNET_STATE_ENABLED);
+                mTracker.setIntefaceState(true);
+                mStarted.set(true);
+            }
+        }
+    }
+
+    class EthernetSwitchBroadcastReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            Log.d(TAG, "EthernetSwitchBroadcastReceiver action:" + action);
+            if (action.equals("xx.action.xx.ethernet.open")) {
+                setState(ETHERNET_STATE_ENABLED);
+            } else if (action.equals("xx.action.xx.ethernet.close")) {
+                setState(ETHERNET_STATE_DISABLED);
+            }
+
+        }
     }
+    //add xxx

     private void throwIfEthernetNotStarted() {
         if (!mStarted.get()) {
diff --git a/packages/modules/Connectivity/service-t/src/com/android/server/ethernet/EthernetTracker.java b/packages/modules/Connectivity/service-t/src/com/android/server/ethernet/EthernetTracker.java
index 1c02a6625f..34c8c8dc8d 100644
--- a/packages/modules/Connectivity/service-t/src/com/android/server/ethernet/EthernetTracker.java
+++ b/packages/modules/Connectivity/service-t/src/com/android/server/ethernet/EthernetTracker.java
@@ -43,6 +43,7 @@ import android.os.Handler;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
 import android.os.ServiceSpecificException;
+import android.provider.Settings;
 import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.Log;
@@ -173,7 +174,12 @@ public class EthernetTracker {
         mConfigStore = new EthernetConfigStore();
     }

+    //add xxx
     void start() {
+        start(true);
+    }
+
+    void start(boolean isEnabled) {
         mFactory.register();
         mConfigStore.read();

@@ -191,8 +197,31 @@ public class EthernetTracker {
             Log.e(TAG, "Could not register InterfaceObserver " + e);
         }

-        mHandler.post(this::trackAvailableInterfaces);
+        if (isEnabled) {
+            mHandler.post(this::trackAvailableInterfaces);
+        }
+    }
+
+    public synchronized void setIntefaceState(boolean isFaceUp) {
+        try {
+            String[] interfaces = getInterfaces(true);
+            for (String iface : interfaces) {
+                if (isTrackingInterface(iface)) {
+                    if (isFaceUp) {
+                        NetdUtils.setInterfaceUp(mNetd, iface);
+                    } else {
+                        NetdUtils.setInterfaceDown(mNetd, iface);
+                    }
+                }
+            }
+            if (isFaceUp) {
+                mHandler.post(this::trackAvailableInterfaces);
+            }
+        } catch (Exception e) {
+            Log.e(TAG, "Error change eth isFaceUp : " + isFaceUp);
+        }
     }
+    //add xxx

     void updateIpConfiguration(String iface, IpConfiguration ipConfiguration) {
         if (DBG) {
@@ -521,7 +550,7 @@ public class EthernetTracker {
         }

         final String hwAddress = config.hwAddr;
-
+        Settings.System.putString(mContext.getContentResolver(), "sys_tex_hwAddress", hwAddress);//add xx xx
         NetworkCapabilities nc = mNetworkCapabilities.get(iface);
         if (nc == null) {
             // Try to resolve using mac address

Android13 有线网开关研究
Android13 原生以太网实现设置静态IP
Android13 MTK平台添加以太网设置静态IP菜单

问题补充:再/packages/modules/Connectivity/service-t/src/com/android/server/ethernet/ 目录下,
想利用SystemProperties.set()保存数据,但是编译报错,error: cannot find symbol,但是我明明导入了!
为什么这么确认我导入,因为还引用了SystemProperties.getInt().然后控制变量,定位到问题是SystemProperties.set()无法再这个目录使用.
为什么会有这个问题呢?我百度大法,有了一些大致的猜想!然后去查看了它的Android.bp

packages/modules/Connectivity/service-t/Android.bp

// This builds T+ services depending on framework-connectivity-t
// hidden symbols separately from the S+ services, to ensure that S+
// services cannot accidentally depend on T+ hidden symbols from
// framework-connectivity-t.
java_library {
    name: "service-connectivity-tiramisu-pre-jarjar",
    sdk_version: "system_server_current",
    // TODO(b/210962470): Bump this to at least S, and then T.
    min_sdk_version: "30",
    srcs: [
        ":service-connectivity-tiramisu-sources",
    ],
    libs: [ 

问题可能关于sdk_version这个属性有关!
当然上面的都只是猜测,只是做个记录,为什么无法编译的bug还没解决.

然后去询问大佬,大佬提供一个思路,让我用反射去调用它,确实编译通过了,数据也能保存.
(ps:我太执着于解决那个编译报错,而忘记了自己的目的!目的是啥,是利用SystemProperties.set()保存数据,
既然(正常)固定的调用方式编译报错,然后一时半会又搞不定编译报错(难点:报错信息不够明确,无法定位).
应该先去想还有什么其它的方式可能调用SystemProperties.set(),先达成目的,然后再回来想想那个编译报错.)

+++ b/packages/modules/Connectivity/service-t/src/com/android/server/ethernet/EthernetTracker.java
+import java.lang.reflect.Method;
@@ -551,6 +552,7 @@ public class EthernetTracker {

         final String hwAddress = config.hwAddr;
+        setProperty("sys.xxx.xxx",hwAddress);
         NetworkCapabilities nc = mNetworkCapabilities.get(iface);
         if (nc == null) {
             // Try to resolve using mac address
@@ -578,6 +580,17 @@ public class EthernetTracker {
         }
     }

+    //add text
+    private void setProperty(String key, String value){
+        try {
+            Class<?> c =  Class.forName("android.os.SystemProperties");
+            Method method = c.getMethod("set",String.class,String.class);
+            method.invoke(c,key,value);
+        }catch (Exception e){
+            Log.d(TAG,"xxxxxxxxxx");
+        }
+    }
+    //add text

大佬的博客,感谢大佬
Android 使用反射机制获取或设置系统属性
Android高版本源码编译提示error: cannot find symbol
内置 APP 如何访问隐藏 API

Ethernet更新

新增以太网打开关闭的函数

./packages/modules/Connectivity/framework-t/src/android/net/EthernetManager.java
    @RequiresPermission(anyOf = {
            NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
            android.Manifest.permission.NETWORK_STACK,
            android.Manifest.permission.NETWORK_SETTINGS})
    @SystemApi(client = MODULE_LIBRARIES)
    public void setEthernetEnabled(boolean enabled) {
        try {
            mService.setEthernetEnabled(enabled);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
//需要权限和系统应用签名(SystemApi) 

Android 13 Ethernet变更

标签:13,service,import,void,Connectivity,ethernet,Ethernet,EthernetSettings,android
From: https://www.cnblogs.com/kato-T/p/18351226

相关文章

  • SSM酒店后台管理系统 ---附源码13123
    目 录摘要Abstract1绪论1.1课题目的及意义1.2研究背景1.3研究方法1.4论文结构与章节安排2 酒店后台管理系统系统分析2.1可行性分析2.2系统功能分析2.2.1功能性分析2.3.2非功能性分析2.4 系统用例分析2.5本章小结3酒店后台管理系统......
  • 福昕PDF编辑器v13专业版 授权版
    福昕高级PDF编辑器是一款功能强大的PDF文件编辑软件,提供多种实用的编辑功能。软件截图:使用说明:解压后,双击open_foxit.exe来运行软件下载地址:FoxitPDFEditor-Pro-v13解压密码:helloh下载时可能会有广告,忽略,等下载结束即可。部分杀软会因该版本软件未购买签名证书(如下图......
  • 0213-数据链路层协议
    环境Time2022-11-20WSL-Ubuntu22.04Rust1.65.0pnet0.31.0前言说明参考:https://docs.rs/pnet_datalink/0.31.0/pnet_datalink/linuxRFC894:https://www.rfc-editor.org/rfc/pdfrfc/rfc894.txt.pdf《TCP/IP详解卷1:协议》:http://www.52im.net/topic-tcpipvol1.html目......
  • 高通C6490 android13 GMS 认证之CtsCarrierApiTestCases
    我们机器是没有SIM卡的,只需要连接wifi。跑CTS测试,CtsCarrierApiTestCases的测试结果都是报没有SIM卡的错误。如下:android.carrierapi.cts.ApnDatabaseTest#testQueryConflictCase fail ThistestrequiresaSIMcardwithcarrierprivilegerulesonit. 解决方法:需要......
  • OpenSSH 信息泄漏漏洞 (CVE-2023-51385)【低可信】
    详细信息跳转此页面:https://blog.csdn.net/python10101/article/details/140083056?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7EPosition-3-140083056-blog-137541643.235%5Ev43%5Epc_blog_bottom_relevance_base3......
  • 3131. Find the Integer Added to Array I
    Youaregiventwoarraysofequallength, nums1 and nums2.Eachelementin nums1 hasbeenincreased(ordecreasedinthecaseofnegative)byaninteger,representedbythevariable x.Asaresult, nums1 becomes equal to nums2.Twoarraysareco......
  • Java项目:213基于Springboot + vue实现的网上订餐系统(含论文+开题报告+开题PPT)
    作者主页:夜未央5788 简介:Java领域优质创作者、Java项目、学习资料、技术互助文末获取源码项目介绍基于Springboot+vue实现的网上订餐系统前台登录:1.首页:菜品信息推荐、菜品信息展示、查看更多2.菜品信息:菜品分类、菜品名称查询、菜品详情、下单提交3.个人中心:可......
  • 1.13 - 动手学聚类算法
    1.基于距离的k-means聚类,需要人工提供聚簇数量K1.1通过肘方法确定最佳聚簇数量 importnumpyasnpimportmatplotlib.pyplotaspltfromsklearn.clusterimportKMeansfromsklearn.preprocessingimportStandardScalerfromsklearn.datasetsimportmake_blobs,lo......
  • 洛谷:P1308 [NOIP2011 普及组] 统计单词数
    题目描述一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数。现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给定的文章中出现的次数和第一次出现的位置。注意:匹配单词时,不区分大小写,但要......
  • android13 下拉栏修改为圆形图标
    在android13默认使用了我们想要将他改成圆形的图标,然后将字体修改到图标下方首先我们要找到图标是在哪里添加进去的在QSFactoryImpl有个方法@OverridepublicQSTileViewcreateTileView(Contextcontext,QSTiletile,booleancollapsedView){QSI......