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:
@@ -154,7 +154,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
|
||||
private final Context mContext;
|
||||
private final INetworkManagementService mNetworkManager;
|
||||
private final IAlarmManager mAlarmManager;
|
||||
private final AlarmManager mAlarmManager;
|
||||
private final TrustedTime mTime;
|
||||
private final TelephonyManager mTeleManager;
|
||||
private final NetworkStatsSettings mSettings;
|
||||
@@ -261,10 +261,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
NetworkStatsSettings settings) {
|
||||
mContext = checkNotNull(context, "missing Context");
|
||||
mNetworkManager = checkNotNull(networkManager, "missing INetworkManagementService");
|
||||
mAlarmManager = checkNotNull(alarmManager, "missing IAlarmManager");
|
||||
mTime = checkNotNull(time, "missing TrustedTime");
|
||||
mTeleManager = checkNotNull(TelephonyManager.getDefault(), "missing TelephonyManager");
|
||||
mSettings = checkNotNull(settings, "missing NetworkStatsSettings");
|
||||
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
|
||||
final PowerManager powerManager = (PowerManager) context.getSystemService(
|
||||
Context.POWER_SERVICE);
|
||||
@@ -420,20 +420,16 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
* reschedule based on current {@link NetworkStatsSettings#getPollInterval()}.
|
||||
*/
|
||||
private void registerPollAlarmLocked() {
|
||||
try {
|
||||
if (mPollIntent != null) {
|
||||
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
|
||||
if (mPollIntent != null) {
|
||||
mAlarmManager.cancel(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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user