Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a80cfe9 authored by Christopher Tate's avatar Christopher Tate Committed by Android (Google) Code Review
Browse files

Merge "Batch alarms to reduce device wakeups"

parents 059bf080 e0a22b32
Loading
Loading
Loading
Loading
+7 −6
Original line number Original line Diff line number Diff line
@@ -3052,17 +3052,18 @@ package android.app {
  public class AlarmManager {
  public class AlarmManager {
    method public void cancel(android.app.PendingIntent);
    method public void cancel(android.app.PendingIntent);
    method public void set(int, long, android.app.PendingIntent);
    method public void set(int, long, android.app.PendingIntent);
    method public void setInexactRepeating(int, long, long, android.app.PendingIntent);
    method public void setExact(int, long, android.app.PendingIntent);
    method public deprecated void setInexactRepeating(int, long, long, android.app.PendingIntent);
    method public void setRepeating(int, long, long, android.app.PendingIntent);
    method public void setRepeating(int, long, long, android.app.PendingIntent);
    method public void setTime(long);
    method public void setTime(long);
    method public void setTimeZone(java.lang.String);
    method public void setTimeZone(java.lang.String);
    field public static final int ELAPSED_REALTIME = 3; // 0x3
    field public static final int ELAPSED_REALTIME = 3; // 0x3
    field public static final int ELAPSED_REALTIME_WAKEUP = 2; // 0x2
    field public static final int ELAPSED_REALTIME_WAKEUP = 2; // 0x2
    field public static final long INTERVAL_DAY = 86400000L; // 0x5265c00L
    field public static final deprecated long INTERVAL_DAY = 86400000L; // 0x5265c00L
    field public static final long INTERVAL_FIFTEEN_MINUTES = 900000L; // 0xdbba0L
    field public static final deprecated long INTERVAL_FIFTEEN_MINUTES = 900000L; // 0xdbba0L
    field public static final long INTERVAL_HALF_DAY = 43200000L; // 0x2932e00L
    field public static final deprecated long INTERVAL_HALF_DAY = 43200000L; // 0x2932e00L
    field public static final long INTERVAL_HALF_HOUR = 1800000L; // 0x1b7740L
    field public static final deprecated long INTERVAL_HALF_HOUR = 1800000L; // 0x1b7740L
    field public static final long INTERVAL_HOUR = 3600000L; // 0x36ee80L
    field public static final deprecated long INTERVAL_HOUR = 3600000L; // 0x36ee80L
    field public static final int RTC = 1; // 0x1
    field public static final int RTC = 1; // 0x1
    field public static final int RTC_WAKEUP = 0; // 0x0
    field public static final int RTC_WAKEUP = 0; // 0x0
  }
  }
+56 −13
Original line number Original line Diff line number Diff line
@@ -16,7 +16,9 @@


package android.app;
package android.app;


import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.Build;
import android.os.RemoteException;
import android.os.RemoteException;


/**
/**
@@ -52,6 +54,8 @@ import android.os.RemoteException;
 */
 */
public class AlarmManager
public class AlarmManager
{
{
    private static final String TAG = "AlarmManager";

    /**
    /**
     * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()}
     * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()}
     * (wall clock time in UTC), which will wake up the device when
     * (wall clock time in UTC), which will wake up the device when
@@ -81,12 +85,16 @@ public class AlarmManager
    public static final int ELAPSED_REALTIME = 3;
    public static final int ELAPSED_REALTIME = 3;


    private final IAlarmManager mService;
    private final IAlarmManager mService;
    private final boolean mAlwaysExact;


    /**
    /**
     * package private on purpose
     * package private on purpose
     */
     */
    AlarmManager(IAlarmManager service) {
    AlarmManager(IAlarmManager service, Context ctx) {
        mService = service;
        mService = service;

        final int sdkVersion = ctx.getApplicationInfo().targetSdkVersion;
        mAlwaysExact = (sdkVersion < Build.VERSION_CODES.KEY_LIME_PIE);
    }
    }
    
    
    /**
    /**
@@ -133,10 +141,7 @@ public class AlarmManager
     * @see #RTC_WAKEUP
     * @see #RTC_WAKEUP
     */
     */
    public void set(int type, long triggerAtMillis, PendingIntent operation) {
    public void set(int type, long triggerAtMillis, PendingIntent operation) {
        try {
        setImpl(type, triggerAtMillis, 0, operation, mAlwaysExact);
            mService.set(type, triggerAtMillis, operation);
        } catch (RemoteException ex) {
        }
    }
    }


    /**
    /**
@@ -188,20 +193,58 @@ public class AlarmManager
     */
     */
    public void setRepeating(int type, long triggerAtMillis,
    public void setRepeating(int type, long triggerAtMillis,
            long intervalMillis, PendingIntent operation) {
            long intervalMillis, PendingIntent operation) {
        setImpl(type, triggerAtMillis, intervalMillis, operation, mAlwaysExact);
    }

    /**
     * TBW: new 'exact' alarm that must be delivered as nearly as possible
     * to the precise time specified.
     */
    public void setExact(int type, long triggerAtMillis, PendingIntent operation) {
        setImpl(type, triggerAtMillis, 0, operation, true);
    }

    private void setImpl(int type, long triggerAtMillis, long intervalMillis,
            PendingIntent operation, boolean isExact) {
        try {
        try {
            mService.setRepeating(type, triggerAtMillis, intervalMillis, operation);
            mService.set(type, triggerAtMillis, intervalMillis, operation, isExact);
        } catch (RemoteException ex) {
        } catch (RemoteException ex) {
        }
        }
    }
    }


    /**
    /**
     * Available inexact recurrence intervals recognized by
     * @deprecated setInexactRepeating() is deprecated; as of API 19 all
     * {@link #setInexactRepeating(int, long, long, PendingIntent)} 
     * repeating alarms are inexact.
     */
     */
    @Deprecated
    public static final long INTERVAL_FIFTEEN_MINUTES = 15 * 60 * 1000;
    public static final long INTERVAL_FIFTEEN_MINUTES = 15 * 60 * 1000;

    /**
     * @deprecated setInexactRepeating() is deprecated; as of API 19 all
     * repeating alarms are inexact.
     */
    @Deprecated
    public static final long INTERVAL_HALF_HOUR = 2*INTERVAL_FIFTEEN_MINUTES;
    public static final long INTERVAL_HALF_HOUR = 2*INTERVAL_FIFTEEN_MINUTES;

    /**
     * @deprecated setInexactRepeating() is deprecated; as of API 19 all
     * repeating alarms are inexact.
     */
    @Deprecated
    public static final long INTERVAL_HOUR = 2*INTERVAL_HALF_HOUR;
    public static final long INTERVAL_HOUR = 2*INTERVAL_HALF_HOUR;

    /**
     * @deprecated setInexactRepeating() is deprecated; as of API 19 all
     * repeating alarms are inexact.
     */
    @Deprecated
    public static final long INTERVAL_HALF_DAY = 12*INTERVAL_HOUR;
    public static final long INTERVAL_HALF_DAY = 12*INTERVAL_HOUR;

    /**
     * @deprecated setInexactRepeating() is deprecated; as of API 19 all
     * repeating alarms are inexact.
     */
    @Deprecated
    public static final long INTERVAL_DAY = 2*INTERVAL_HALF_DAY;
    public static final long INTERVAL_DAY = 2*INTERVAL_HALF_DAY;


    /**
    /**
@@ -236,6 +279,8 @@ public class AlarmManager
     * typically comes from {@link PendingIntent#getBroadcast
     * typically comes from {@link PendingIntent#getBroadcast
     * IntentSender.getBroadcast()}.
     * IntentSender.getBroadcast()}.
     *
     *
     * @deprecated As of API 19, all repeating alarms are inexact.
     *
     * @see android.os.Handler
     * @see android.os.Handler
     * @see #set
     * @see #set
     * @see #cancel
     * @see #cancel
@@ -252,12 +297,10 @@ public class AlarmManager
     * @see #INTERVAL_HALF_DAY
     * @see #INTERVAL_HALF_DAY
     * @see #INTERVAL_DAY
     * @see #INTERVAL_DAY
     */
     */
    @Deprecated
    public void setInexactRepeating(int type, long triggerAtMillis,
    public void setInexactRepeating(int type, long triggerAtMillis,
            long intervalMillis, PendingIntent operation) {
            long intervalMillis, PendingIntent operation) {
        try {
        setRepeating(type, triggerAtMillis, intervalMillis, operation);
            mService.setInexactRepeating(type, triggerAtMillis, intervalMillis, operation);
        } catch (RemoteException ex) {
        }
    }
    }
    
    
    /**
    /**
+3 −3
Original line number Original line Diff line number Diff line
@@ -309,11 +309,11 @@ class ContextImpl extends Context {
                    return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler());
                    return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler());
                }});
                }});


        registerService(ALARM_SERVICE, new StaticServiceFetcher() {
        registerService(ALARM_SERVICE, new ServiceFetcher() {
                public Object createStaticService() {
                public Object createService(ContextImpl ctx) {
                    IBinder b = ServiceManager.getService(ALARM_SERVICE);
                    IBinder b = ServiceManager.getService(ALARM_SERVICE);
                    IAlarmManager service = IAlarmManager.Stub.asInterface(b);
                    IAlarmManager service = IAlarmManager.Stub.asInterface(b);
                    return new AlarmManager(service);
                    return new AlarmManager(service, ctx);
                }});
                }});


        registerService(AUDIO_SERVICE, new ServiceFetcher() {
        registerService(AUDIO_SERVICE, new ServiceFetcher() {
+1 −3
Original line number Original line Diff line number Diff line
@@ -24,9 +24,7 @@ import android.app.PendingIntent;
 * {@hide}
 * {@hide}
 */
 */
interface IAlarmManager {
interface IAlarmManager {
    void set(int type, long triggerAtTime, in PendingIntent operation);
    void set(int type, long triggerAtTime, long interval, in PendingIntent operation, boolean isExact);
    void setRepeating(int type, long triggerAtTime, long interval, in PendingIntent operation);
    void setInexactRepeating(int type, long triggerAtTime, long interval, in PendingIntent operation);
    void setTime(long millis);
    void setTime(long millis);
    void setTimeZone(String zone);
    void setTimeZone(String zone);
    void remove(in PendingIntent operation);
    void remove(in PendingIntent operation);
+497 −314

File changed.

Preview size limit exceeded, changes collapsed.

Loading