在项目\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. NumberFormat DecimalFormat

    http://blog.csdn.net/evangel_z/article/details/7624503 http://blog.163.com/wangzhengquan85@126/blog/ ...

  2. How to use wget ?

    1.How to get conent (not download page) of website? wget <websit> -q -O -

  3. ECharts饼图试玩

    处理类似提交问卷的数据,要生成图表,用了ECharts,好方便的. 简陋效果: 1.表单存储 有单选和多选题,单选直接存储各选项数字值,1,2,3,4...中一个:多选用|分隔存储选项值,如1|3,2 ...

  4. hadoop(2014/0619)

    map-reduce :分解任务和合并任务的能力 hdfs: namenode and datanode namenode放置元数据 datanoe放置数据

  5. Windows下安装Python lxml库(无废话版)

    python官网:python-2.7.12.amd64.msihttps://pypi.python.org/pypi/setuptools:setuptools-28.6.0.zipsetupto ...

  6. Intellij Idea 工具在java文件中如何避免 import .*包

    Intellij Idea工具在java文件中怎么避免import java.utils.*这样的导入方式,不推崇导入*这样的做法!Editor->Code Style->Java-> ...

  7. 现在web前端这么火,钱景怎么样啊?

    web前端开发工程师可以说是一个全新的职业,在IT整个行业中真正受到重视的时间没有超过5年,也正因为这样,大家越来越想了解web前端工程师的前景究竟怎么样? web前端培训就业前景如何?web前端工程 ...

  8. spring事务手动回滚

    @Transactional(rollbackFor = { Exception.class }) public JSONObject preSendMsg(AuthInfo authInfo, Me ...

  9. 日志管理-Log4net

    引言 log4net库是Apache log4j框架在Micorsoft.NET平台的实现,是一个帮组程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具.(百度百科) 实际项目中使用log ...

  10. css表示屏幕宽度和高度

    expression(document.body.offsetWidth + "px"); expression(document.body.offsetHeight + &quo ...