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(); 如何根据方法名 ...
随机推荐
- Linux DNS配置
1.安装bind #安装bind yum install -y bind bind-chroot bind-utils 2.主配置文件 vi /etc/named.conf #修改监听为本机IP li ...
- bootstrap 部分css样式
clip: rect(0, 0, 0, 0);剪裁绝对定位元素.outline: 0; cursor: not-allowed;
- sql执行
一.提高sql执行效率---in与exist . where column in (select * from table where ...) . ...where exists (select ' ...
- mac终端显示和隐藏隐藏文件的命令
defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder //显示隐藏文件 defaults write ...
- VS2013 ViewData ViewBag Ajax等关键词报错(当前上下文不存在名称)而且不提示也点不出来,但是可以正常运行,
这个多数问题是因为 视图 的Web.config 内的配置问题 在Views文件夹下 有一个Web.config文件,把里面的版本号(System.Web.Mvc, Version=5.2.2.0) ...
- XEP-0078:非SASL认证
XEP-0078:非SASL认证 抽象: 这个文件规定了使用Jabber的Jabber的服务器和服务认证的协议:智商:AUTH命名空间.注意哦:本文规定的协议,取而代之的SASL认证的被取代,如RFC ...
- python引用py文件中文报错
文件 a.py 中引用文件 b.py 如果文件b.py中包含中文,会报错. 文件hello.py中代码如下: def say_nihao(): print "你好" 文件main. ...
- NET基础(4):引用类型和值类型
CLR支持两种类型:引用类型和值类型.虽然FCL的大多数类型都是引用类型,但程序员用的最多的还是引用类型,引用类型总是从托管堆分配,c#的new操作符返回对象内存地址-即指向对象数据的内存地址.使用引 ...
- MWeb 2.0 测试版可以下载啦,这次是公开测试,感兴趣的朋友可以试试
2.0 版是 MWeb 发布以来,最重要的一个版本.MWeb 自去年一月份发布以来,获得了很多朋友的建议,在此非常感谢!没有你们,2.0 版可能就不能出来!然后再次感谢 Producter: http ...
- Java里能用session吗?
1.Session是服务器端存储的,Js里不能使用. 2.一般Session的实现需要依赖客户端的Cookie来储存一个SessionId,客户端每次请求服务器都会带上这个Cookie,这样服务器端就 ...