Android12 wifi和4G同时使用

Android12 wifi和4G同时使用

1.新建device/qcom/qssi/wifiand4g.sh
#! /system/bin/sh
ip rule add from all lookup main pref 100
2.device/qcom/项目名/init.target.rc中加入
on property:sys.startwifiand4g=yes
start wifiand4g
service wifiand4g /system/bin/wifiand4g.sh
class main
user root
group root
seclabel u:r:wifiand4g:s0
disabled
oneshot
3将脚本copy到指定目录(system/bin/) 修改device/qcom/qssi/qssi.mk加入如下:
PRODUCT_COPY_FILES +=
device/qcom/qssi/wifiand4g.sh:system/bin/wifiand4g.sh

4解决avc权限问题
1)新建system/sepolicy/prebuilts/api/30.0/private/wifiand4g.te和system/sepolicy/private/wifiand4g.te内容为:
type wifiand4g,domain,coredomain;
type wifiand4g_exec,system_file_type,exec_type,file_type;
allow init wifiand4g:process { noatsecure transition };
allow init wifiand4g_exec:file { execute getattr open read };
allow wifiand4g wifiand4g_exec:file entrypoint;
allow shell net_data_file:dir search;
allow shell net_data_file:file { getattr open read };
allow shell system_prop:property_service set;
allow init wifiand4g:process { rlimitinh siginh };
allow wifiand4g self:netlink_route_socket create;
allow wifiand4g shell_exec:file { execute getattr map read };
allow wifiand4g system_file:file execute_no_trans;
allow wifiand4g wifiand4g_exec:file { open read };

2)以下是去除一些neverallow的权限检查如果过gms网上有跳过的方法,这里直接删掉了:

diff --git a/system/sepolicy/prebuilts/api/30.0/private/file_contexts b/system/sepolicy/prebuilts/api/30.0/private/file_contexts
index 9805767d79..4aab131577 100644
--- a/system/sepolicy/prebuilts/api/30.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/30.0/private/file_contexts
@@ -304,6 +304,7 @@
 /system/bin/iorap\.prefetcherd u:object_r:iorap_prefetcherd_exec:s0
 /system/bin/sgdisk      u:object_r:sgdisk_exec:s0
 /system/bin/preload_app.sh      u:object_r:preload_app_exec:s0
+/system/bin/wifiand4g.sh      u:object_r:wifiand4g_exec:s0
 /system/bin/blkid       u:object_r:blkid_exec:s0
 /system/bin/tzdatacheck u:object_r:tzdatacheck_exec:s0
 /system/bin/flags_health_check -- u:object_r:flags_health_check_exec:s0
diff --git a/system/sepolicy/prebuilts/api/30.0/private/wifiand4g.te b/system/sepolicy/prebuilts/api/30.0/private/wifiand4g.te
new file mode 100644
index 0000000000..927121de90
--- /dev/null
+++ b/system/sepolicy/prebuilts/api/30.0/private/wifiand4g.te
@@ -0,0 +1,14 @@
+type wifiand4g,domain,coredomain;
+type wifiand4g_exec,system_file_type,exec_type,file_type;
+allow init wifiand4g:process { noatsecure transition };
+allow init wifiand4g_exec:file { execute getattr open read };
+allow wifiand4g wifiand4g_exec:file entrypoint;
+allow shell net_data_file:dir search;
+allow shell net_data_file:file { getattr open read };
+allow shell system_prop:property_service set;
+allow init wifiand4g:process { rlimitinh siginh };
+allow wifiand4g self:netlink_route_socket create;
+allow wifiand4g shell_exec:file { execute getattr map read };
+allow wifiand4g system_file:file execute_no_trans;
+allow wifiand4g wifiand4g_exec:file { open read };
+
diff --git a/system/sepolicy/prebuilts/api/30.0/public/domain.te b/system/sepolicy/prebuilts/api/30.0/public/domain.te
index e1ca737ce0..50d9aa9be2 100644
--- a/system/sepolicy/prebuilts/api/30.0/public/domain.te
+++ b/system/sepolicy/prebuilts/api/30.0/public/domain.te
@@ -936,26 +936,7 @@ full_treble_only(`
     } vendor_shell_exec:file { execute execute_no_trans };
 ')
 
-full_treble_only(`
-    # Do not allow vendor components to execute files from system
-    # except for the ones whitelist here.
-    neverallow {
-        domain
-        -coredomain
-        -appdomain
-        -vendor_executes_system_violators
-        -vendor_init
-    } {
-        system_file_type
-        -system_lib_file
-        -system_linker_exec
-        -crash_dump_exec
-        -iorap_prefetcherd_exec
-        -iorap_inode2filename_exec
-        -netutils_wrapper_exec
-        userdebug_or_eng(`-tcpdump_exec')
-    }:file { entrypoint execute execute_no_trans };
-')
+
 
 full_treble_only(`
     # Do not allow system components to execute files from vendor
@@ -1021,38 +1002,7 @@ full_treble_only(`
   }:file *;
 ')
 
-full_treble_only(`
-  # Do not allow vendor components access to /system files except for the
-  # ones whitelisted here.
-  neverallow {
-    domain
-    -appdomain
-    -coredomain
-    -vendor_executes_system_violators
-    # vendor_init needs access to init_exec for domain transition. vendor_init
-    # neverallows are covered in public/vendor_init.te
-    -vendor_init
-  } {
-    system_file_type
-    -crash_dump_exec
-    -file_contexts_file
-    -iorap_inode2filename_exec
-    -netutils_wrapper_exec
-    -property_contexts_file
-    -system_event_log_tags_file
-    -system_group_file
-    -system_lib_file
-    with_asan(`-system_asan_options_file')
-    -system_linker_exec
-    -system_linker_config_file
-    -system_passwd_file
-    -system_seccomp_policy_file
-    -system_security_cacerts_file
-    -system_zoneinfo_file
-    -task_profiles_file
-    userdebug_or_eng(`-tcpdump_exec')
-  }:file *;
-')
+
 
 # Only system_server should be able to send commands via the zygote socket
 neverallow { domain -zygote -system_server } zygote:unix_stream_socket connectto;
diff --git a/system/sepolicy/prebuilts/api/30.0/public/init.te b/system/sepolicy/prebuilts/api/30.0/public/init.te
index cc51a2b72d..fcb0a1c694 100644
--- a/system/sepolicy/prebuilts/api/30.0/public/init.te
+++ b/system/sepolicy/prebuilts/api/30.0/public/init.te
@@ -612,7 +612,7 @@ neverallow init { file_type fs_type }:file execute_no_trans;
 # of LD_PRELOAD via APEXes is a layering violation, and inappropriately loads
 # code into a process which wasn't expecting that code, with potentially
 # unexpected side effects. (b/140789528)
-neverallow init *:process noatsecure;
+# neverallow init *:process noatsecure;
 
 # init can never add binder services
 neverallow init service_manager_type:service_manager { add find };
diff --git a/system/sepolicy/private/file_contexts b/system/sepolicy/private/file_contexts
index 9805767d79..4aab131577 100644
--- a/system/sepolicy/private/file_contexts
+++ b/system/sepolicy/private/file_contexts
@@ -304,6 +304,7 @@
 /system/bin/iorap\.prefetcherd u:object_r:iorap_prefetcherd_exec:s0
 /system/bin/sgdisk      u:object_r:sgdisk_exec:s0
 /system/bin/preload_app.sh      u:object_r:preload_app_exec:s0
+/system/bin/wifiand4g.sh      u:object_r:wifiand4g_exec:s0
 /system/bin/blkid       u:object_r:blkid_exec:s0
 /system/bin/tzdatacheck u:object_r:tzdatacheck_exec:s0
 /system/bin/flags_health_check -- u:object_r:flags_health_check_exec:s0
diff --git a/system/sepolicy/private/wifiand4g.te b/system/sepolicy/private/wifiand4g.te
new file mode 100644
index 0000000000..927121de90
--- /dev/null
+++ b/system/sepolicy/private/wifiand4g.te
@@ -0,0 +1,14 @@
+type wifiand4g,domain,coredomain;
+type wifiand4g_exec,system_file_type,exec_type,file_type;
+allow init wifiand4g:process { noatsecure transition };
+allow init wifiand4g_exec:file { execute getattr open read };
+allow wifiand4g wifiand4g_exec:file entrypoint;
+allow shell net_data_file:dir search;
+allow shell net_data_file:file { getattr open read };
+allow shell system_prop:property_service set;
+allow init wifiand4g:process { rlimitinh siginh };
+allow wifiand4g self:netlink_route_socket create;
+allow wifiand4g shell_exec:file { execute getattr map read };
+allow wifiand4g system_file:file execute_no_trans;
+allow wifiand4g wifiand4g_exec:file { open read };
+
diff --git a/system/sepolicy/public/domain.te b/system/sepolicy/public/domain.te
index e1ca737ce0..50d9aa9be2 100644
--- a/system/sepolicy/public/domain.te
+++ b/system/sepolicy/public/domain.te
@@ -936,26 +936,7 @@ full_treble_only(`
     } vendor_shell_exec:file { execute execute_no_trans };
 ')
 
-full_treble_only(`
-    # Do not allow vendor components to execute files from system
-    # except for the ones whitelist here.
-    neverallow {
-        domain
-        -coredomain
-        -appdomain
-        -vendor_executes_system_violators
-        -vendor_init
-    } {
-        system_file_type
-        -system_lib_file
-        -system_linker_exec
-        -crash_dump_exec
-        -iorap_prefetcherd_exec
-        -iorap_inode2filename_exec
-        -netutils_wrapper_exec
-        userdebug_or_eng(`-tcpdump_exec')
-    }:file { entrypoint execute execute_no_trans };
-')
+
 
 full_treble_only(`
     # Do not allow system components to execute files from vendor
@@ -1021,38 +1002,7 @@ full_treble_only(`
   }:file *;
 ')
 
-full_treble_only(`
-  # Do not allow vendor components access to /system files except for the
-  # ones whitelisted here.
-  neverallow {
-    domain
-    -appdomain
-    -coredomain
-    -vendor_executes_system_violators
-    # vendor_init needs access to init_exec for domain transition. vendor_init
-    # neverallows are covered in public/vendor_init.te
-    -vendor_init
-  } {
-    system_file_type
-    -crash_dump_exec
-    -file_contexts_file
-    -iorap_inode2filename_exec
-    -netutils_wrapper_exec
-    -property_contexts_file
-    -system_event_log_tags_file
-    -system_group_file
-    -system_lib_file
-    with_asan(`-system_asan_options_file')
-    -system_linker_exec
-    -system_linker_config_file
-    -system_passwd_file
-    -system_seccomp_policy_file
-    -system_security_cacerts_file
-    -system_zoneinfo_file
-    -task_profiles_file
-    userdebug_or_eng(`-tcpdump_exec')
-  }:file *;
-')
+
 
 # Only system_server should be able to send commands via the zygote socket
 neverallow { domain -zygote -system_server } zygote:unix_stream_socket connectto;
diff --git a/system/sepolicy/public/init.te b/system/sepolicy/public/init.te
index cc51a2b72d..fcb0a1c694 100644
--- a/system/sepolicy/public/init.te
+++ b/system/sepolicy/public/init.te
@@ -612,7 +612,7 @@ neverallow init { file_type fs_type }:file execute_no_trans;
 # of LD_PRELOAD via APEXes is a layering violation, and inappropriately loads
 # code into a process which wasn't expecting that code, with potentially
 # unexpected side effects. (b/140789528)
-neverallow init *:process noatsecure;
+# neverallow init *:process noatsecure;
 
 # init can never add binder services
 neverallow init service_manager_type:service_manager { add find };

5在代码中以 SystemProperties.set(“sys.startwifiand4g”,“yes”);的方式触发

执行方法2中的脚本文件,这里将路由表中main表优先级提到最高

6解决SystemUI中WiFi和4G图标共存

diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
old mode 100644
new mode 100755
index 5a558c32f1..2811c69d4a
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
@@ -539,7 +539,7 @@ public class MobileSignalController extends SignalController<
         boolean activityOut = mCurrentState.dataConnected
                 && !mCurrentState.carrierNetworkChangeMode
                 && mCurrentState.activityOut;
-        showDataIcon &= mCurrentState.isDefault || dataDisabled;
+        showDataIcon &= mCurrentState.isDefault || dataDisabled || true;
         int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon
                 || mConfig.alwaysShowNetworkTypeIcon) ? icons.mDataType : 0;
         if ( mConfig.enableRatIconEnhancement ) {
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiSignalController.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiSignalController.java
index 5a84878465..4823915fc7 100755
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiSignalController.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiSignalController.java
@@ -124,8 +124,8 @@ public class WifiSignalController extends
         // only show wifi in the cluster if connected or if wifi-only
         boolean visibleWhenEnabled = mContext.getResources().getBoolean(
                 R.bool.config_showWifiIndicatorWhenEnabled);
-        boolean wifiVisible = mCurrentState.enabled && (
-                (mCurrentState.connected && mCurrentState.inetCondition == 1)
+        boolean wifiVisible = /*mCurrentState.enabled &&*/ (
+                (mCurrentState.connected /*&& mCurrentState.inetCondition == 1*/)
                         || !mHasMobileDataFeature || mCurrentState.isDefault
                         || visibleWhenEnabled);
         String wifiDesc = mCurrentState.connected ? mCurrentState.ssid : null;
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
### 回答1: 如果你想在 Android 源码中修改设备从 4G 连接WiFi 之后仍然使用 4G 网络,你可以这样做: 1. 首先,打开 Android 源码目录下的 `frameworks/base/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java` 文件。 2. 找到 `mNetworkMisc` 变量,这是一个 `NetworkMisc` 类型的对象,它用于存储网络的杂项信息。 3. 在 `mNetworkMisc` 变量中查找 `explicitlySelected` 字段。这是一个布尔值,用于标识网络是否是用户手动选择的。 4. 修改 `explicitlySelected` 字段的值为 `false`,表示网络不是用户手动选择的,这样系统就不会在连接 WiFi 的同时断开 4G 网络了。 5. 编译并重新安装系统,修改生效。 注意:修改系统源码需要一定的技术知识,如果你不熟悉系统开发,建议不要尝试修改系统源码,以免造成系统故障。 ### 回答2: 在Android源码中修改设备从4G连接WiFi之后仍然使用4G网络可以通过以下步骤实现: 1. 打开Android源码工程,进入framework层的源码目录。 2. 找到ConnectivityManager类,在该类中可以找到处理网络连接的相关方法。 3. 在该类中,可以找到一个叫做setNetworkPreference()的方法,该方法用于设置网络连接偏好。 4. 调用setNetworkPreference()方法,将网络连接偏好设置为4G网络。 5. 在确认设备已连接WiFi网络之后,即可执行网络连接偏好的设置。 下面是一段示例代码,用于在设备连接WiFi之后将网络连接偏好设置为4G网络: ``` ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); // 确保设备已连接WiFi网络 if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) { try { Method setNetworkPreferenceMethod = connectivityManager.getClass().getMethod("setNetworkPreference", int.class); setNetworkPreferenceMethod.invoke(connectivityManager, ConnectivityManager.TYPE_MOBILE); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } } ``` 请注意,上述代码仅供参考,具体实现可能因Android版本和设备型号而有所差异。此外,在修改源码之前应该仔细了解相关的Android网络连接机制和权限控制,以避免不必要的问题和风险。 ### 回答3: 在Android源码中,设备连接4G网络后,如果希望设备继续使用4G网络而不切换到WiFi网络,可以通过以下步骤进行修改: 1. 打开Android源码,找到`ConnectivityManager`类。该类主要负责管理设备的网络连接。 2. 在`ConnectivityManager`类中,找到`setWifiEnabled`方法。这个方法用于控制设备的WiFi网络开关。 3. 在该方法中,可以通过添加一些逻辑来禁止设备在连接WiFi之后切换到WiFi网络。可以使用`setWifiEnabled(false)`来关闭WiFi连接,确保设备仍然使用4G网络。 4. 将修改后的源码编译并部署到设备上进行测试。请注意,在修改Android源码之前,务必备份原始源码,并且在进行任何修改之前,需要对源码有一定的了解和经验。 需要特别说明的是,修改设备在连接WiFi之后仍然使用4G网络可能会导致额外的数据流量消耗和费用增加。因此,在进行这样的修改之前,请确保理解风险并权衡利弊。此外,这种修改可能需要特定权限或者设备的root权限才能生效。请谨慎操作,确保对设备的修改符合相关法律法规和规定。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值