码迷,mamicode.com
首页 > 移动开发 > 详细

android源码中修改wifi热点默认始终开启

时间:2016-06-27 13:44:01      阅读:1278      评论:0      收藏:0      [点我收藏+]

标签:

在项目\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);


另外,System.xxxx的常量定义在源码中的路径:项目\frameworks\base\core\java\android\provider\Settings.java

android源码中修改wifi热点默认始终开启

标签:

原文地址:http://www.cnblogs.com/suxiaoqi/p/5619741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!