Batch alarms to reduce device wakeups

The default Alarm Manager behavior for KLP+ apps will be to aggressively
coalesce alarms, trading exact timeliness of delivery for minimizing the
number of alarm-delivery points, especially wakeup points.

There is new API in AlarmManager, setExact() and setExactRepeating(),
for use by apps that absolutely *must* get their alarms at a specific
point in time.

Bug 9532215

Change-Id: I40b4eea90220211cc958172d2629664b921ff051
This commit is contained in:
Christopher Tate
2013-07-11 14:43:13 -07:00
parent 926bb66cc1
commit 9fa19313dd

View File

@@ -154,7 +154,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private final Context mContext; private final Context mContext;
private final INetworkManagementService mNetworkManager; private final INetworkManagementService mNetworkManager;
private final IAlarmManager mAlarmManager; private final AlarmManager mAlarmManager;
private final TrustedTime mTime; private final TrustedTime mTime;
private final TelephonyManager mTeleManager; private final TelephonyManager mTeleManager;
private final NetworkStatsSettings mSettings; private final NetworkStatsSettings mSettings;
@@ -261,10 +261,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
NetworkStatsSettings settings) { NetworkStatsSettings settings) {
mContext = checkNotNull(context, "missing Context"); mContext = checkNotNull(context, "missing Context");
mNetworkManager = checkNotNull(networkManager, "missing INetworkManagementService"); mNetworkManager = checkNotNull(networkManager, "missing INetworkManagementService");
mAlarmManager = checkNotNull(alarmManager, "missing IAlarmManager");
mTime = checkNotNull(time, "missing TrustedTime"); mTime = checkNotNull(time, "missing TrustedTime");
mTeleManager = checkNotNull(TelephonyManager.getDefault(), "missing TelephonyManager"); mTeleManager = checkNotNull(TelephonyManager.getDefault(), "missing TelephonyManager");
mSettings = checkNotNull(settings, "missing NetworkStatsSettings"); mSettings = checkNotNull(settings, "missing NetworkStatsSettings");
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
final PowerManager powerManager = (PowerManager) context.getSystemService( final PowerManager powerManager = (PowerManager) context.getSystemService(
Context.POWER_SERVICE); Context.POWER_SERVICE);
@@ -420,20 +420,16 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
* reschedule based on current {@link NetworkStatsSettings#getPollInterval()}. * reschedule based on current {@link NetworkStatsSettings#getPollInterval()}.
*/ */
private void registerPollAlarmLocked() { private void registerPollAlarmLocked() {
try { if (mPollIntent != null) {
if (mPollIntent != null) { mAlarmManager.cancel(mPollIntent);
mAlarmManager.remove(mPollIntent);
}
mPollIntent = PendingIntent.getBroadcast(
mContext, 0, new Intent(ACTION_NETWORK_STATS_POLL), 0);
final long currentRealtime = SystemClock.elapsedRealtime();
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, currentRealtime,
mSettings.getPollInterval(), mPollIntent);
} catch (RemoteException e) {
// ignored; service lives in system_server
} }
mPollIntent = PendingIntent.getBroadcast(
mContext, 0, new Intent(ACTION_NETWORK_STATS_POLL), 0);
final long currentRealtime = SystemClock.elapsedRealtime();
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, currentRealtime,
mSettings.getPollInterval(), mPollIntent);
} }
/** /**