在项目\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热点默认始终开启的更多相关文章

  1. android 源码 中修改系统字体大小

    在源码\android\frameworks\base\core\java\android\content\res \Configuration.java下有读取DEFAULT_FONTSCALE的值 ...

  2. 源码中修改Android的开机画面和动画【转】

    本文转载自:http://blog.csdn.net/dddxxxx/article/details/54343976 参照文章:http://blog.csdn.net/a345017062/art ...

  3. android studio应用修改到android源码中作为内置应用

    1. 方法一:导入,编译(太麻烦,各种不兼容问题) android studio和eclipse的应用结构目录是不同的,但是在android源码中的应用基本上都是使用的eclipse目录结构(在/pa ...

  4. Eclipse与Android源码中ProGuard工具的使用

    由于工作需要,这两天和同事在研究android下面的ProGuard工具的使用,通过查看android官网对该工具的介绍以及网络上其它相关资料,再加上自己的亲手实践,算是有了一个基本了解.下面将自己的 ...

  5. Eclipse与Android源码中ProGuard工具的使用(代码混淆)

    由于工作需要,这两天和同事在研究android下面的ProGuard工具的使用,通过查看android官网对该工具的介绍以及网络上其它相关资料,再加上自己的亲手实践,算是有了一个基本了解.下面将自己的 ...

  6. Android源码中的FLAG为何使用16进制

    1.在阅读源码的时候经常发现有一些标志属性使用一些位操作来判断是否具有该标志,增加标志或者去除标志. 比如View.java中的 /** * This view does not want keyst ...

  7. 关于android源码中的APP编译时引用隐藏的API出现的问题

    今天在编译android源码中的计算器APP时发现,竟然无法使用系统隐藏的API,比如android.os.ServiceManager中的API,引用这个类时提示错误,记忆中在android源码中的 ...

  8. 访何红辉:谈谈Android源码中的设计模式

    最近Android 6.0版本的源代码开放下载,刚好分析Android源码的技术书籍<Android源码设计模式解析与实战>上市,我们邀请到它的作者何红辉,来谈谈Android源码中的设计 ...

  9. 在Android源码中查找Java代码中native函数对应的C++实现

    Android源码中很多关键代码都是C++实现的,java通过jni来调用,经常会看到java中这样的代码: static native Thread currentThread(); 如何根据方法名 ...

随机推荐

  1. NodeJs并发异步的回调处理

    这里说并发异步,并不准确,应该说连续异步.NodeJs单线程异步的特性,直接导致多个异步同时进行时,无法确定最后的执行结果来回调.举个简单的例子: for(var i = 0; i < 5; i ...

  2. java线程同步 以及wait 和notify用法

    package test; public class ThreadTest2 extends Thread { private int threadNo; private String lock; p ...

  3. oracle查询某个时间点的数据

    1. select * from emps as of timestamp to_Date('2015-12-11 14:00:00','yyyy-mm-dd hh24:mi:ss'),SQL语句是查 ...

  4. 两个有意思的模式在ECMAScript中的实现

    简介 本篇文章对设计模式进行了筛选, 只列举两个有意思(坑)的设计实现, 如有错误愿闻其详. 构造函数 ECMAScript中的构造函数和其他语言的有那么点特别之处,可以认为, 一个函数, 如果被以n ...

  5. C# EF增删改查

    1.增 //1.创建一个EF数据上下文对象 MyDBEntities context=new MyDBEntities(); //2.将要添加的数据,封装成对象 Users user = new Us ...

  6. SELENIUM2 使用JavascriptExecutor在页面Javascipt执行

    目的: 1. 执行一段JS,来改变HTML2. 一些非标准控件无法用selenium2的API时,可以执行JS的办法来取代 主要操作:JavascriptExecutor j = (Javascrip ...

  7. Spring MVC配置

    web配置 <?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="ht ...

  8. 使用CXF框架集成Spring实现SOAP Web Service

  9. 网页3D引擎“Babylon.JS”入门教程翻译总结

    使用三个月的业余时间把官方教程的入门部分译为中文并上传到github,在下一步编程前做一个总结. 历程: 最早接触游戏编程是在大三下学期,用汇编语言和实验室里的单片机.触摸屏.电机(提供声效)编的打地 ...

  10. Leetcode: Circular Array Loop

    You are given an array of positive and negative integers. If a number n at an index is positive, the ...