/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.support.v4.content; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.PowerManager; import android.util.Log; import android.util.SparseArray; /** * Helper for the common pattern of implementing a {@link BroadcastReceiver} * that receives a device wakeup event and then passes the work off * to a {@link android.app.Service}, while ensuring that the * device does not go back to sleep during the transition. * *
This class takes care of creating and managing a partial wake lock * for you; you must request the {@link android.Manifest.permission#WAKE_LOCK} * permission to use it.
* *A {@link WakefulBroadcastReceiver} uses the method * {@link WakefulBroadcastReceiver#startWakefulService startWakefulService()} * to start the service that does the work. This method is comparable to * {@link android.content.Context#startService startService()}, except that * the {@link WakefulBroadcastReceiver} is holding a wake lock when the service * starts. The intent that is passed with * {@link WakefulBroadcastReceiver#startWakefulService startWakefulService()} * holds an extra identifying the wake lock.
* * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/content/SimpleWakefulReceiver.java * complete} * *The service (in this example, an {@link android.app.IntentService}) does * some work. When it is finished, it releases the wake lock by calling * {@link WakefulBroadcastReceiver#completeWakefulIntent * completeWakefulIntent(intent)}. The intent it passes as a parameter * is the same intent that the {@link WakefulBroadcastReceiver} originally * passed in.
* * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/content/SimpleWakefulService.java * complete} */ public abstract class WakefulBroadcastReceiver extends BroadcastReceiver { private static final String EXTRA_WAKE_LOCK_ID = "android.support.content.wakelockid"; private static final SparseArray