android源码中修改wifi热点默认始终开启
在项目\frameworks\base\wifi\java\android\net\wifi\WifiStateMachine.java里面,有如下的代码,是设置wifi热点保持状态的:如下:
private class HotspotAutoDisableObserver extends ContentObserver {
public HotspotAutoDisableObserver(Handler handler) {
super(handler);
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(
Settings.System.WIFI_HOTSPOT_AUTO_DISABLE), false, this);
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
mDuration = Settings.System.getInt(mContext.getContentResolver(), Settings.System.WIFI_HOTSPOT_AUTO_DISABLE,
Settings.System.WIFI_HOTSPOT_AUTO_DISABLE_FOR_FIVE_MINS);
if (mDuration != Settings.System.WIFI_HOTSPOT_AUTO_DISABLE_OFF && mPluggedType == 0) {
if (mClientNum == 0 && WifiStateMachine.this.getCurrentState() == mTetheredState) {
mAlarmManager.cancel(mIntentStopHotspot);
Xlog.d(TAG, "Set alarm for setting changed, mDuration:" + mDuration);
mAlarmManager.set(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + mDuration * HOTSPOT_DISABLE_MS, mIntentStopHotspot);
}
} else {
mAlarmManager.cancel(mIntentStopHotspot);
}
}
}
修改默认值为始终:
mDuration = Settings.System.getInt(mContext.getContentResolver(), Settings.System.WIFI_HOTSPOT_AUTO_DISABLE,
Settings.System.WIFI_HOTSPOT_AUTO_DISABLE_OFF); 最关键的部分是修改初始化:
private void initializeExtra() {
PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
mDhcpWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DHCP_WAKELOCK");
mDhcpWakeLock.setReferenceCounted(false);
mHotspotNative = new WifiNative("ap0");
mHotspotMonitor = new WifiMonitor(this, mHotspotNative);
HandlerThread wifiThread = new HandlerThread("WifiSMForObserver");
wifiThread.start();
mHotspotAutoDisableObserver = new HotspotAutoDisableObserver(new Handler(wifiThread.getLooper()));
Intent stopHotspotIntent = new Intent(ACTION_STOP_HOTSPOT);
mIntentStopHotspot = PendingIntent.getBroadcast(mContext, STOP_HOTSPOT_REQUEST, stopHotspotIntent, 0);
//mDuration = Settings.System.getInt(mContext.getContentResolver(), Settings.System.WIFI_HOTSPOT_AUTO_DISABLE,
// Settings.System.WIFI_HOTSPOT_AUTO_DISABLE_FOR_FIVE_MINS);
mDuration = Settings.System.getInt(mContext.getContentResolver(), Settings.System.WIFI_HOTSPOT_AUTO_DISABLE,
Settings.System.WIFI_HOTSPOT_AUTO_DISABLE_OFF);//---------修改为默认常开
// M: For stop scan after screen off in disconnected state feature @{
Intent stopScanIntent = new Intent(ACTION_STOP_SCAN, null);
mStopScanIntent = PendingIntent.getBroadcast(mContext, STOPSCAN_REQUEST, stopScanIntent, 0);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("com.mtk.beamplus.activated");
intentFilter.addAction("com.mtk.beamplus.deactivated");
intentFilter.addAction(ACTION_STOP_HOTSPOT);
intentFilter.addAction(IWifiFwkExt.AUTOCONNECT_SETTINGS_CHANGE);
intentFilter.addAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED);
intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
intentFilter.addAction(Intent.ACTION_DUAL_SIM_MODE_CHANGED);
intentFilter.addAction(ACTION_STOP_SCAN);
final boolean isHotspotAlwaysOnWhilePlugged = mContext.getResources().getBoolean(
com.mediatek.internal.R.bool.is_mobile_hotspot_always_on_while_plugged);
Xlog.d(TAG, "isHotspotAlwaysOnWhilePlugged:" + isHotspotAlwaysOnWhilePlugged);
if (isHotspotAlwaysOnWhilePlugged) {
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
}
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Xlog.d(TAG, "onReceive, action:" + action);
if (action.equals("com.mtk.beamplus.activated")) {
mBeamPlusStarted.set(true);
sendMessage(M_CMD_UPDATE_BGSCAN);
} else if (action.equals("com.mtk.beamplus.deactivated")) {
mBeamPlusStarted.set(false);
sendMessage(M_CMD_UPDATE_BGSCAN);
} else if (action.equals(ACTION_STOP_HOTSPOT)) {
mWifiManager.setWifiApEnabled(null, false);
int wifiSavedState = 0;
try {
wifiSavedState = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_SAVED_STATE);
} catch (Settings.SettingNotFoundException e) {
Xlog.e(TAG, "SettingNotFoundException:" + e);
}
Xlog.d(TAG, "Received stop hotspot intent, wifiSavedState:" + wifiSavedState);
if (wifiSavedState == 1) {
mWifiManager.setWifiEnabled(true);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.WIFI_SAVED_STATE, 0);
}
} else if (action.equals(IWifiFwkExt.AUTOCONNECT_SETTINGS_CHANGE)) {
sendMessage(M_CMD_UPDATE_SETTINGS);
} else if (action.equals(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)) {
WifiDisplayStatus status = (WifiDisplayStatus)intent.getParcelableExtra(
DisplayManager.EXTRA_WIFI_DISPLAY_STATUS);
Xlog.d(TAG, "Received ACTION_WIFI_DISPLAY_STATUS_CHANGED.");
setWfdConnected(status);
sendMessage(M_CMD_UPDATE_BGSCAN);
} else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
if (isHotspotAlwaysOnWhilePlugged) {
int pluggedType = intent.getIntExtra("plugged", 0);
Xlog.d(TAG, "ACTION_BATTERY_CHANGED pluggedType:" + pluggedType + ", mPluggedType:" + mPluggedType);
if (mPluggedType != pluggedType) {
mPluggedType = pluggedType;
if (mDuration != Settings.System.WIFI_HOTSPOT_AUTO_DISABLE_OFF && mPluggedType == 0) {
if (mClientNum == 0 && WifiStateMachine.this.getCurrentState() == mTetheredState) {
mAlarmManager.cancel(mIntentStopHotspot);
Xlog.d(TAG, "Set alarm for ACTION_BATTERY_CHANGED changed, mDuration:" + mDuration);
mAlarmManager.set(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + mDuration * HOTSPOT_DISABLE_MS, mIntentStopHotspot);
}
} else {
mAlarmManager.cancel(mIntentStopHotspot);
}
}
}
} else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
String iccState = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
Xlog.d(TAG, "iccState:" + iccState);
if (!iccState.equals(IccCardConstants.INTENT_VALUE_ICC_LOADED)) {
return;
}
sendMessage(M_CMD_UPDATE_COUNTRY_CODE);
} else if (action.equals(Intent.ACTION_DUAL_SIM_MODE_CHANGED)) {
sendMessage(M_CMD_UPDATE_COUNTRY_CODE);
} else if (action.equals(ACTION_STOP_SCAN)) {
sendMessage(M_CMD_SLEEP_POLICY_STOP_SCAN);
}
}
};
mContext.registerReceiver(receiver, intentFilter);
mPppoeInfo = new PPPOEInfo();
mPppoeLinkProperties = new LinkProperties();
}
另外,System.xxxx的常量定义在源码中的路径:项目\frameworks\base\core\java\android\provider\Settings.java
android源码中修改wifi热点默认始终开启的更多相关文章
- android 源码 中修改系统字体大小
在源码\android\frameworks\base\core\java\android\content\res \Configuration.java下有读取DEFAULT_FONTSCALE的值 ...
- 源码中修改Android的开机画面和动画【转】
本文转载自:http://blog.csdn.net/dddxxxx/article/details/54343976 参照文章:http://blog.csdn.net/a345017062/art ...
- android studio应用修改到android源码中作为内置应用
1. 方法一:导入,编译(太麻烦,各种不兼容问题) android studio和eclipse的应用结构目录是不同的,但是在android源码中的应用基本上都是使用的eclipse目录结构(在/pa ...
- Eclipse与Android源码中ProGuard工具的使用
由于工作需要,这两天和同事在研究android下面的ProGuard工具的使用,通过查看android官网对该工具的介绍以及网络上其它相关资料,再加上自己的亲手实践,算是有了一个基本了解.下面将自己的 ...
- Eclipse与Android源码中ProGuard工具的使用(代码混淆)
由于工作需要,这两天和同事在研究android下面的ProGuard工具的使用,通过查看android官网对该工具的介绍以及网络上其它相关资料,再加上自己的亲手实践,算是有了一个基本了解.下面将自己的 ...
- Android源码中的FLAG为何使用16进制
1.在阅读源码的时候经常发现有一些标志属性使用一些位操作来判断是否具有该标志,增加标志或者去除标志. 比如View.java中的 /** * This view does not want keyst ...
- 关于android源码中的APP编译时引用隐藏的API出现的问题
今天在编译android源码中的计算器APP时发现,竟然无法使用系统隐藏的API,比如android.os.ServiceManager中的API,引用这个类时提示错误,记忆中在android源码中的 ...
- 访何红辉:谈谈Android源码中的设计模式
最近Android 6.0版本的源代码开放下载,刚好分析Android源码的技术书籍<Android源码设计模式解析与实战>上市,我们邀请到它的作者何红辉,来谈谈Android源码中的设计 ...
- 在Android源码中查找Java代码中native函数对应的C++实现
Android源码中很多关键代码都是C++实现的,java通过jni来调用,经常会看到java中这样的代码: static native Thread currentThread(); 如何根据方法名 ...
随机推荐
- github for window的代理设置方法
修改 .gitconfig 文件,主要是针对http 和 https进行修改,设置代理 [user] name = name email = mail@.com [http] proxy = 配置文件 ...
- scala中的集合框架
- sublime 配置jade高亮显示
1.下载 Package Control.sublime-package 文件放入Packages文件目录下 2.control + shift + p 输入install package 3. ...
- php+mysql+Apache环境搭建
最近有一个小程序需要用php来跑,记录一下php的环境配置过程. 1.首先在下载集成工具wamp,WAMP是指在Windows服务器上使用Apache.MySQL和PHP的集成安装环境,可以快速安装配 ...
- 安装springboot时遇到 LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.问题
将工程外部jar包删除slf4j就可以运行.
- Mac上安装django
参考:https://docs.djangoproject.com/en/1.9/topics/install/#installing-official-release 升级pip sudo pip ...
- Linux下查看某进程相关进程
1- ps -T <pid> ###pid表示进程号 或者ps -T -p <pid> 2- top -H -p <pid> ###pid表示进程号 3- ...
- TypeScript & JavaScript
http://www.typescriptlang.org/docs/tutorial.html handbook: Basic Types Variable Declarations Interfa ...
- 【转】SQL Server中的事务与锁
SQL Server中的事务与锁 了解事务和锁 事务:保持逻辑数据一致性与可恢复性,必不可少的利器. 锁:多用户访问同一数据库资源时,对访问的先后次序权限管理的一种机制,没有他事务或许将会一塌糊涂 ...
- zip命令的常用选项
zip命令的常用选项 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 大家都知道,在linux上一切皆文件,在实际生产环境中,如果我们需要部署一些系统的服务,我们会将一些软件包提前下 ...