在“设置”->“无线和网络”,有一项飞行模式的checkbox。根据其描述“禁用所有无线连接”,可略知其功能,但具体实现了哪些功能呢,我们从代码的角度来分析。

在类WirelessSettings中,包含一个成员变量mAirplaneModeEnabler,飞行模式的功能是由类AirplaneModeEnabler来实现的。setAirplaneModeOn(boolean enabling)是该类用来设置飞行模式开关的方法,该方法最重要的实现是广播Intent.ACTION_AIRPLANE_MODE_CHANGED,并携带开/关的标志位。

Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", enabling);
mContext.sendBroadcast(intent);
查找源代码,有3个模块响应该事件。

1. PhoneApp:关闭电话射频信号

2. WifiService:关闭wifi信号

3. BluetoothService:关闭bluetooth信号

但wifi模块稍有区别,即使在飞行模式下,wifi也可以开启。

相关文章:

  • 2021-05-20
  • 2021-08-26
  • 2021-12-09
  • 2021-06-09
  • 2021-10-02
  • 2022-02-11
  • 2022-01-14
  • 2022-12-23
猜你喜欢
  • 2021-07-07
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-12-28
  • 2021-06-30
  • 2021-11-14
相关资源
相似解决方案