开发者

Idle time period before screen lock, wifi shutdown, phone sleep?

开发者_如何学CI want to know how much time of inactivity has to pass before:

  1. the screen locks (Actually I know that one, it's configurable in the settings)
  2. the Wi-Fi shuts down? Where can I change this value?
  3. the phone goes to sleep mode? Where can I change this value?

UPDATE: I don't want to lock anything. I only want to know how long it takes normally, when there are no locks set? Where in the OS code is this specified?


the Wi-Fi shuts down? Where can I change this value?

I don't know if you can change this value, CommonsWare says it's not possible. However on my phone (Froyo, 2.2.1) if you press the menu button on Wifi Settings there is an "advanced" option. In there you can set the Wifi Inactivity policy. I have the option to never shut it down, shut it down when the screen is off, or only when not connected.

Does that help any?

Ok, here is info about #2

the Wi-Fi shuts down? Where can I change this value?

Apparently there is a undocumented value in android.provider.Settings, called wifi_idle_ms that controls this. I found some info here, the setting is store in a db that is normally found at /data/data/com.android.providers.settings/databases/settings.db, on the secure table. There are instructions on how to change it on XDA, and the consensus seems to be that the default value is 15 minutes, or 900000.


the Wi-Fi shuts down? Where can I change this value?

You can't. It is part of the OS and will be affected by the existence of acquired WifiLocks.

the phone goes to sleep mode? Where can I change this value?

You can't. It is part of the OS and will be affected by the existence of acquired WakeLocks.


I suppose that either wi-fi or phone receives Broadcasts and acting based on that. If so you can try to intercept those Broadcasts before wi-fi and phone will receive them and and then simply cancel Broadcast like:

public class ScreenStateBroadcastReceiver extends BroadcastReceiver
{
    private static String TAG=ScreenStateBroadcastReceiver.class.getName();

    @Override
    public void onReceive(Context context, Intent intent)
    {
        //checking has screen been switched off?
        if (Intent.ACTION_SCREEN_OFF.equalsIgnoreCase(intent.getAction()))
        {
            Log.v(TAG, "Screen is going off");
            this.abortBroadcast();
        }
    }
}

In order to be sure that your application will receive Broadcast before other OS component - you can try to put Broadcast receiving priority putting in AndroidManifest smth like:

    <receiver android:name=".ScreenStateBroadcastReceiver"> 
        <intent-filter android:priority="10000">
            <action android:name="android.intent.action.SCREEN_OFF"/>
        </intent-filter>
    </receiver>

Disclaimer: Never tried, but I hope it would work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜