android在开启飞行模式的情况下,禁止打开蓝牙
(1)将alps/framework/base/packages/settingsprovider/res/values/defaults.xml里
面airplane_mode_toggleable_radios标签中的“bluetooth”去掉。
(2)在packages/apps/settings/src/android/settings/bluetoothangel/BluetoothEnabler.java这支文件里进行如下修改:
1.import 如下两个包:
import android.database.ContentObserver;
import com.android.settings.AirplaneModeEnabler;
import android.os.Handler;
2. 在resume()方法的末尾添加如下语句:
//add
mContext.getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.AIRPLANE_MODE_ON), true,
mAirplaneModeObserver);
mSwitch.setEnabled(!shouldDisableBT());
//add end
3.在pause()方法里面添加如下语句:
//add
mContext.getContentResolver().unregisterContentObserver(mAirplaneModeObserver);
//add end
4. 在setSwitch()方法里注释掉如下语句:
//mSwitch.setEnabled(isOn || isOff);
添加如下语句:
mSwitch.setEnabled(!shouldDisableBT()); //add
5. 将handleStateChanged()方法里面的BluetoothAdapter.STATE_ON,BluetoothAdapter.OFF和default
这三个case里的mSwitch.setEnabled(true);修改为:
mSwitch.setEnabled(!shouldDisableBT()); // add
6.在BluetoothEnabler这个class添加如下方法和成员变量:
//add
private boolean shouldDisableBT(){
String toggleable = Settings.System.getString(mContext.getContentResolver(),
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
if(toggleable == null || !toggleable.contains(Settings.System.RADIO_BLUETOOTH)){
return AirplaneModeEnabler.isAirplaneModeOn(mContext);
}
return false;
}
// add
private ContentObserver mAirplaneModeObserver = new ContentObserver(new
Handler()) {
@Override
public void onChange(boolean selfChange) {
onAirplaneModeChanged();
}
};
// add
private void onAirplaneModeChanged() {
mSwitch.setEnabled(!AirplaneModeEnabler.isAirplaneModeOn(mContext));
}
(3)ALPS.JB.MP\alps\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\tool
bar\connectionSwitchPannel.java
在private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
里面的onReceive()函数里的
else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
这个判断分支内最后添加:
//add for airplan -bt toggle state
mBluetoothStateTracker.setAirlineMode(enabled);
mBluetoothIcon.getConfigView().setEnabled(mBluetoothStateTracker.isClickable());
//add end
BluetoothStateTracker 类中添加如下代码
class BluetoothStateTracker extends StateTracker {
//add
private
boolean mIsAirlineMode = false;
public void setAirlineMode(boolean
enable) {
if (DBG) {
Xlog.i(TAG, "Bluetooth setAirlineMode
called, enabled is: " + enable);
}
mIsAirlineMode = enable;
}
public boolean isClickable() {
Xlog.i(TAG, "BT mIsAirlineMode
is " + mIsAirlineMode + ", mIsUserSwitching is " + mIsUserSwitching);
return
!mIsAirlineMode && super.isClickable();
}
//add end
(4)\alps\packages\apps\Settings\src\com\android\settings\widget\SettingsAppWidgetProvider.java
//add
import com.android.settings.AirplaneModeEnabler;
//add end
else if ((FeatureOption.MTK_BT_SUPPORT) && (buttonId == BUTTON_BLUETOOTH)) {
//sBluetoothState.toggleState(context);
//add
if(!AirplaneModeEnabler.isAirplaneModeOn(context)) {
sBluetoothState.toggleState(context);
}
//add end
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。