FileDocCategorySizeDatePackage
DozeTestDream.javaAPI DocAndroid 5.1 API5740Thu Mar 12 22:22:42 GMT 2015com.android.dreams.dozetest

DozeTestDream

public class DozeTestDream extends android.service.dreams.DreamService
Simple test for doze mode.

adb shell setprop debug.doze.component com.android.dreams.dozetest/.DozeTestDream

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final int
UPDATE_TIME_TIMEOUT
private static final int
DISPLAY_STATE_WHEN_DOZING
private android.os.PowerManager
mPowerManager
private PowerManager.WakeLock
mWakeLock
private android.app.AlarmManager
mAlarmManager
private android.app.PendingIntent
mAlarmIntent
private android.os.Handler
mHandler
private android.widget.TextView
mAlarmClock
private final Date
mTime
private DateFormat
mTimeFormat
private boolean
mDreaming
private long
mLastTime
private final android.content.BroadcastReceiver
mAlarmReceiver
Constructors Summary
Methods Summary
private voidcancelTimeUpdate()

        mAlarmManager.cancel(mAlarmIntent);
    
public voidonAttachedToWindow()

        super.onAttachedToWindow();
        setInteractive(false);
        setLowProfile(true);
        setFullscreen(true);
        setContentView(R.layout.dream);
        setScreenBright(false);

        mAlarmClock = (TextView)findViewById(R.id.alarm_clock);

        mTimeFormat = DateFormat.getTimeFormat(this);
    
public voidonCreate()


    
       
        super.onCreate();

        mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
        mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

        mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);

        Intent intent = new Intent("com.android.dreams.dozetest.ACTION_ALARM");
        intent.setPackage(getPackageName());
        IntentFilter filter = new IntentFilter();
        filter.addAction(intent.getAction());
        registerReceiver(mAlarmReceiver, filter);
        mAlarmIntent = PendingIntent.getBroadcast(this, 0, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        setDozeScreenState(DISPLAY_STATE_WHEN_DOZING);
    
public voidonDestroy()

        super.onDestroy();

        unregisterReceiver(mAlarmReceiver);
        mAlarmIntent.cancel();
    
public voidonDreamingStarted()

        super.onDreamingStarted();

        mDreaming = true;

        Log.d(TAG, "Dream started: canDoze=" + canDoze());

        performTimeUpdate();

        startDozing();
    
public voidonDreamingStopped()

        super.onDreamingStopped();

        mDreaming = false;

        Log.d(TAG, "Dream ended: isDozing=" + isDozing());

        stopDozing();
        cancelTimeUpdate();
    
private voidperformTimeUpdate()

        if (mDreaming) {
            long now = System.currentTimeMillis();
            now -= now % 60000; // back up to last minute boundary
            if (mLastTime == now) {
                return;
            }

            mLastTime = now;
            mTime.setTime(now);
            mAlarmClock.setText(mTimeFormat.format(mTime));

            mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, now + 60000, mAlarmIntent);

            mWakeLock.acquire(UPDATE_TIME_TIMEOUT + 5000 /*for testing brightness*/);

            // flash the screen a bit to test these functions
            setDozeScreenState(DISPLAY_STATE_WHEN_DOZING);
            setDozeScreenBrightness(200);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    setDozeScreenBrightness(50);
                }
            }, 2000);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    setDozeScreenState(Display.STATE_OFF);
                }
            }, 5000);
        }