赞
踩
3:从不 --采用deepsleep模式睡眠,不断电但是断网的模式睡眠,下次唤醒再重新连接。
有些android手机睡眠策略调节无效,就是这部分功能没有实现。没有一下代码,很多手机有这种Bug。
无论是gb还是ics qct上的代码都不能直接与上层联系的,它只选用一个固定模式,要么是deepsleep要么是wow模式。但是在高通qrd代码则实现了关联。
实现方法:通过kobject在sys下创建虚拟文件系统/sys/android_wlan/wlan_power/sleep_policy通过上层设置传如不同值。以下是实现代码。通过store和show来实现上层写入和读出。
很值得学习,故把代码贴出来了。
gb上的store
static ssize_t ar6000_sleep_policy_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t size)
{
if (sysfs_streq(buf, "0")) //判断buf?=0
sleep_policy = EARLY_SLEEP;
else if (sysfs_streq(buf, "1"))要是1则调度deepsleep模式睡眠函数
sleep_policy = DEEP_SLEEP;
else if (sysfs_streq(buf, "2"))要是2则调度wow模式睡眠
sleep_policy = NEVER_SLEEP;
else {
pr_err("%s: invalid value %d\n", __func__, *buf);
}
return 0;
}
show函数
static ssize_t ath6kl_sleep_policy_show(struct device *dev,
struct device_attribute *attr, char *buf)}
上层代码位置wifi sleep_policy 代码位置 wifiservice.java advancedwifisetting.java
gb实现传递的代码 wifiservice.java
/**
* Determines whether the Wi-Fi chipset should stay awake or be
put to
* sleep. Looks at the setting for the sleep policy and the
current
* conditions.
*
* @see #shouldDeviceStayAwake(int, int)
*/
private void writeSleepOptions(int policy) {
try {
FileOutputStream os = new FileOutputStream(
"/sys/android_wlan/sleep_policy", true);
if(policy == 2)
os.write(new byte[] { (byte)'2' });
else if(policy == 1)
os.write(new byte[] { (byte)'1' });
else
os.write(new byte[] { (byte)'0' });
os.close();
} catch (Exception e) {
Slog.w(TAG, "Failed setting sleep policy");
}
}
private boolean shouldWifiStayAwake(int stayAwakeConditions, int
pluggedType) {
int wifiSleepPolicy =
Settings.System.getInt(mContext.getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY,
Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
if (wifiSleepPolicy ==
Settings.System.WIFI_SLEEP_POLICY_NEVER) {
// Never sleep
writeSleepOptions(2);
return true;
} else if ((wifiSleepPolicy ==
Settings.System.WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED) &&
(pluggedType != 0)) {
// Never sleep while plugged, and we're plugged
writeSleepOptions(1);
return true;
} else {
// Default
writeSleepOptions(0);
return shouldDeviceStayAwake(stayAwakeConditions,
pluggedType);
}
}
gb sleep_policy高级设置默认属性 代码位置advancedwifisetting.java
private void initSleepPolicyPreference() {
ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
pref.setOnPreferenceChangeListener(this);
int value = Settings.System.getInt(getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY,Settings. System.WIFI_SLEEP_POLICY_NEVER);
pref.setValue(String.valueOf(value));
}
好了,知道了睡眠策略,就可以更改默认的睡眠策略了,本人最喜欢默认为WOW。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。