应用场景:在特定的环境下,比如银行内部、行政机关内部,用到的很多产品都不允许连接外网的。所以产品相关的WIFI在界面上面不允许使用,4G、5G模块暂不讨论。
需求及实现效果
需求
去掉WIFI相关的模块,主要有两个模块,
- QS面板下拉框显示的WIFI 模块
- 系统设置里面的WIFI模块
实现效果
下拉框不显示,网络模块无WIFI模块选项
代码跟踪
SystemUI 去WIFI
SystemUI
相关知识,务必做到基本流程了解、概念、架构、布局,方便实现基础功能和理解业务修改。
参考资料:截屏功能添加中的SystemUI基础描述
熟悉了SystemUI后,这个需求就简单了,在QS面板里面不添加不就行了吗。找到QSTitle 默认配置的地方
\frameworks\base\packages\SystemUI\res\values\config.xml
<!-- The default tiles to display in QuickSettings -->
<string name="quick_settings_tiles_default" translatable="false">
internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle
</string>
<!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" -->
<string name="quick_settings_tiles_stock" translatable="false">
internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness
</string>
所以,这里把 internet 选项去掉就可以了。
注意事项
当前是RK平台,wifi 相关的title String 用的是 internet ,不同平台的title String flag 不一样的哦。 但都能够见名知义。
系统设置
String 字符串查找
去系统设置,进入二级界面,找到 网络现实的title 是,网络和互联网,根据 名称找到value 文件夹下的String 配置。
<string name="network_dashboard_title" msgid="788543070557731240">"网络和互联网"</string>
布局文件xml
根据network_dashboard_title 找到对应加载
找到对应的xml布局文件 network_and_internet.xml 、network_provider_internet.xml 源代码分别如下:
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="network_and_internet_screen"
android:title="@string/network_dashboard_title">
<PreferenceCategory
android:key="multi_network_header"
android:title="@string/summary_placeholder"
android:layout="@layout/preference_category_no_label"
settings:allowDividerBelow="true"
android:order="-40"
settings:controller="com.android.settings.network.MultiNetworkHeaderController"/>
<com.android.settings.widget.PrimarySwitchPreference
android:fragment="com.android.settings.wifi.WifiSettings"
android:key="main_toggle_wifi"
android:title="@string/wifi_settings"
android:summary="@string/summary_placeholder"
android:icon="@drawable/ic_settings_wireless"
android:order="-30"
settings:allowDividerAbove="true">
<intent
android:action="android.settings.WIFI_SETTINGS"
android:targetClass="Settings$WifiSettingsActivity" />
</com.android.settings.widget.PrimarySwitchPreference>
<com.android.settings.widget.AddPreference
android:key="mobile_network_list"
android:title="@string/network_settings_title"
android:summary="@string/summary_placeholder"
android:icon="@drawable/ic_network_cell"
android:order="-15"
settings:keywords="@string/keywords_more_mobile_networks"
settings:userRestriction="no_config_mobile_networks"
settings:useAdminDisabledSummary="true" />
<com.android.settingslib.RestrictedSwitchPreference
android:key="airplane_mode"
android:title="@string/airplane_mode"
android:icon="@drawable/ic_airplanemode_active"
android:disableDependentsState="true"
android:order="-5"
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
settings:userRestriction="no_airplane_mode"/>
<com.android.settingslib.RestrictedPreference
android:key="manage_mobile_plan"
android:title="@string/manage_mobile_plan_title"
android:persistent="false"
android:order="19"
settings:userRestriction="no_config_mobile_networks"
settings:useAdminDisabledSummary="true" />
........
</PreferenceScreen>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="network_provider_and_internet_screen"
android:title="@string/network_dashboard_title">
<com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.network.NetworkProviderSettings"
android:key="internet_settings"
android:title="@string/provider_internet_settings"
android:summary="@string/summary_placeholder"
android:icon="@drawable/ic_settings_wireless"
android:order="-30"
settings:allowDividerAbove="true"
settings:keywords="@string/keywords_internet"
settings:useAdminDisabledSummary="true" />
<com.android.settingslib.RestrictedPreference
android:key="calls_and_sms"
android:title="@string/calls_and_sms"
android:icon="@drawable/ic_calls_sms"
android:order="-20"
android:summary="@string/summary_placeholder"
settings:allowDividerBelow="true"
settings:keywords="@string/calls_and_sms"
settings:useAdminDisabledSummary="true" />
<com.android.settings.widget.AddPreference
android:key="mobile_network_list"
android:title="@string/provider_network_settings_title"
android:summary="@string/summary_placeholder"
android:icon="@drawable/ic_sim_card"
android:order="-15"
settings:keywords="@string/keywords_more_mobile_networks"
settings:userRestriction="no_config_mobile_networks"
settings:allowDividerAbove="true"
settings:useAdminDisabledSummary="true" />
<com.android.settingslib.RestrictedSwitchPreference
android:key="airplane_mode"
android:title="@string/airplane_mode"
android:icon="@drawable/ic_airplanemode_active"
android:order="-5"
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
settings:userRestriction="no_airplane_mode"/>
<com.android.settingslib.RestrictedPreference
android:key="manage_mobile_plan"
android:title="@string/manage_mobile_plan_title"
android:persistent="false"
android:order="19"
settings:userRestriction="no_config_mobile_networks"
settings:useAdminDisabledSummary="true" />
<com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.TetherSettings"
android:key="tether_settings"
android:title="@string/tether_settings_title_all"
android:icon="@drawable/ic_wifi_tethering"
android:order="5"
android:summary="@string/summary_placeholder"
settings:keywords="@string/keywords_hotspot_tethering"
settings:userRestriction="no_config_tethering"
settings:useAdminDisabledSummary="true" />
<com.android.settings.widget.PrimarySwitchPreference
android:fragment="com.android.settings.AllInOneTetherSettings"
android:key="all_tether_settings"
android:title="@string/tether_settings_title_all"
android:icon="@drawable/ic_wifi_tethering"
android:order="6"
android:summary="@string/summary_placeholder"
settings:controller="com.android.settings.network.AllInOneTetherPreferenceController"
settings:keywords="@string/keywords_hotspot_tethering"
settings:userRestriction="no_config_tethering"
settings:useAdminDisabledSummary="true" />
.....
</PreferenceScreen>
初步看文件布局描述,不就是我们要找到的二级目录,wifi 存在的那个界面吗?
再次反向找一下加载 xml 文件的源码位置
这里看到有用的信息是 network_provider_internet.xml 是正在使用的,它之前对应的老版本布局文件是network_and_internet。 加载布局的Fragment 是 NetworkDashboardFragment
RK3568_WFC_64_bsp:/ $ dumpsys activity top
Added Fragments:
#0: NetworkDashboardFragment{af5c2e7} (e548c033-35e0-497f-905a-df5ed7db31f6) id=0x7f0a0319}
Fragments Created Menus:
#0: NetworkDashboardFragment{af5c2e7} (e548c033-35e0-497f-905a-df5ed7db31f6) id=0x7f0a0319}
Back Stack Index: 0
FragmentManager misc state:
mHost=androidx.fragment.app.FragmentActivity$HostCallbacks@e15fd3d
mContainer=androidx.fragment.app.FragmentActivity$HostCallbacks@e15fd3d
mCurState=7 mStateSaved=false mStopped=false mDestroyed=false
上面代码反向推理,找到对应的布局,并验证对应的Fragment,说明xml 对应的布局修改即可解决问题。
故,最终共解决方案,屏蔽掉WIFI模块布局即可。在network_provider_internet.xml 中屏蔽掉wifi 布局代码,如下:
<!--
<com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.network.NetworkProviderSettings"
android:key="internet_settings"
android:title="@string/provider_internet_settings"
android:summary="@string/summary_placeholder"
android:icon="@drawable/ic_settings_wireless"
android:order="-30"
settings:allowDividerAbove="true"
settings:keywords="@string/keywords_internet"
settings:useAdminDisabledSummary="true" />
-->
总结
- SystemUI中的修改需要熟悉SystemUI基本内容
- 系统设置中的WIFI模块隐藏去掉可以反向通过 显示字符串,反向找到布局,加载布局的UI Fragment或者Activity,最后通过命令验证推理,实现最终需求。