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(); 如何根据方法名 ...
随机推荐
- java beans
There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...
- ElasticSearchwindow下搭建
ElasticSearch是一个开源的分布式搜索引擎. 下载 下载地址: https://www.elastic.co/downloads/elasticsearch 当前版本:Elasticsear ...
- 深度解析正则表达式exec和match两者使用的异同以及要注意的地方
1.match match方法属于String正则表达方法. 语法: str.match(regexp) str:要进行匹配的字符串. regexp:一个正则表达式(或者由RegExp()构造成的正则 ...
- SEO
白帽SEO 内容优化 网站标题.关键字.描述 网站内容优化 Robot.txt文件 网站地图 增加外链引用 2. 网站结构布局优化 网站加载速度:一个页面<100k 扁平化:网站 目录层次 少, ...
- 链接的热键属性accesskey
<a href="" accesskey="h"></a> 意思是按住Alt键+h,再按enter键就可以直接链接到HTML的目标网址中 ...
- 使用天天模拟器开发Android应用
自带的模拟器太慢,Genymotion配置过于复杂,天天模拟器旧版本直接可用于调试,由于新版本的天大模拟器端口号被修改为6555,要想用于开发,需要使用ADB命令进行连接. 下载天天模拟器 天天模拟器 ...
- HTML标签marquee实现滚动效果
html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制.使用marquee标记不仅可以移动文字,也可以移动图片,表格等.只需要在<ma ...
- LeetCode Moving Average from Data Stream
原题链接在这里:https://leetcode.com/problems/moving-average-from-data-stream/ 题目: Given a stream of integer ...
- 批量修改一张表格的多个sheet名
例如这样的函数: Sub aab() For x = 4 To 5 Sheets(x).Name = "10" & Format(x - 3, "00" ...
- 在 Apache Ant中设置Proxy服务器
<target name="proxy"> <property name="proxy.host" value="https://m ...