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

Commit c42a1e10 authored by Adrian Roos's avatar Adrian Roos
Browse files

Add AlarmClock API to AlarmManager

Adds a new kind of alarm that represents an alarm clock and
a way to query the next scheduled alarm clock.

Deprecates Settings.System.NEXT_ALARM_FORMATTED.

Bug: 14589952
Change-Id: I297eeeff36d07adcda010afac183d0f5ee37dc99
parent cafd1521
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -3661,15 +3661,27 @@ package android.app {
    method public void update(android.app.ActivityOptions);
  }
  public class AlarmClockInfo implements android.os.Parcelable {
    ctor public AlarmClockInfo(long, android.app.PendingIntent);
    method public int describeContents();
    method public android.app.PendingIntent getShowIntent();
    method public long getTriggerTime();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public class AlarmManager {
    method public void cancel(android.app.PendingIntent);
    method public android.app.AlarmClockInfo getNextAlarmClock();
    method public void set(int, long, android.app.PendingIntent);
    method public void setAlarmClock(android.app.AlarmClockInfo, android.app.PendingIntent);
    method public void setExact(int, long, android.app.PendingIntent);
    method public void setInexactRepeating(int, long, long, android.app.PendingIntent);
    method public void setRepeating(int, long, long, android.app.PendingIntent);
    method public void setTime(long);
    method public void setTimeZone(java.lang.String);
    method public void setWindow(int, long, long, android.app.PendingIntent);
    field public static final java.lang.String ACTION_NEXT_ALARM_CLOCK_CHANGED = "android.app.action.NEXT_ALARM_CLOCK_CHANGED";
    field public static final int ELAPSED_REALTIME = 3; // 0x3
    field public static final int ELAPSED_REALTIME_WAKEUP = 2; // 0x2
    field public static final long INTERVAL_DAY = 86400000L; // 0x5265c00L
@@ -24745,7 +24757,7 @@ package android.provider {
    field public static final java.lang.String MODE_RINGER_STREAMS_AFFECTED = "mode_ringer_streams_affected";
    field public static final java.lang.String MUTE_STREAMS_AFFECTED = "mute_streams_affected";
    field public static final deprecated java.lang.String NETWORK_PREFERENCE = "network_preference";
    field public static final java.lang.String NEXT_ALARM_FORMATTED = "next_alarm_formatted";
    field public static final deprecated java.lang.String NEXT_ALARM_FORMATTED = "next_alarm_formatted";
    field public static final java.lang.String NOTIFICATION_SOUND = "notification_sound";
    field public static final deprecated java.lang.String PARENTAL_CONTROL_ENABLED = "parental_control_enabled";
    field public static final deprecated java.lang.String PARENTAL_CONTROL_LAST_UPDATE = "parental_control_last_update";
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2014, 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.app;

parcelable AlarmClockInfo;
+101 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.app;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * An immutable description of an alarm clock.
 *
 * @see AlarmManager#setAlarmClock
 * @see AlarmManager#getNextAlarmClock
 */
public class AlarmClockInfo implements Parcelable {

    private final long mTriggerTime;
    private final PendingIntent mShowIntent;

    /**
     * Creates a new alarm clock description.
     *
     * @param triggerTime time at which the underlying alarm is triggered in wall time milliseconds
     *                    since the epoch
     * @param showIntent an intent that can be used to show or edit details of
     *                        the alarm clock.
     */
    public AlarmClockInfo(long triggerTime, PendingIntent showIntent) {
        mTriggerTime = triggerTime;
        mShowIntent = showIntent;
    }

    /**
     * Use the {@link #CREATOR}
     * @hide
     */
    AlarmClockInfo(Parcel in) {
        mTriggerTime = in.readLong();
        mShowIntent = in.readParcelable(PendingIntent.class.getClassLoader());
    }

    /**
     * Returns the time at which the alarm is going to trigger.
     *
     * This value is UTC wall clock time in milliseconds, as returned by
     * {@link System#currentTimeMillis()} for example.
     */
    public long getTriggerTime() {
        return mTriggerTime;
    }

    /**
     * Returns an intent intent that can be used to show or edit details of the alarm clock in
     * the application that scheduled it.
     *
     * <p class="note">Beware that any application can retrieve and send this intent, potentially
     * with additional fields filled in. See
     * {@link PendingIntent#send(android.content.Context, int, android.content.Intent)
     * PendingIntent.send()} and {@link android.content.Intent#fillIn Intent.fillIn()}
     * for details.
     */
    public PendingIntent getShowIntent() {
        return mShowIntent;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mTriggerTime);
        dest.writeParcelable(mShowIntent, flags);
    }

    public static final Creator<AlarmClockInfo> CREATOR = new Creator<AlarmClockInfo>() {
        @Override
        public AlarmClockInfo createFromParcel(Parcel in) {
            return new AlarmClockInfo(in);
        }

        @Override
        public AlarmClockInfo[] newArray(int size) {
            return new AlarmClockInfo[size];
        }
    };
}
+81 −8
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package android.app;

import android.annotation.SdkConstant;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.WorkSource;

/**
@@ -94,6 +96,17 @@ public class AlarmManager
     */
    public static final int ELAPSED_REALTIME = 3;

    /**
     * Broadcast Action: Sent after the value returned by
     * {@link #getNextAlarmClock()} has changed.
     *
     * <p class="note">This is a protected intent that can only be sent by the system.
     * It is only sent to registered receivers.</p>
     */
    @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_NEXT_ALARM_CLOCK_CHANGED =
            "android.app.action.NEXT_ALARM_CLOCK_CHANGED";

    /** @hide */
    public static final long WINDOW_EXACT = 0;
    /** @hide */
@@ -188,7 +201,7 @@ public class AlarmManager
     * @see #RTC_WAKEUP
     */
    public void set(int type, long triggerAtMillis, PendingIntent operation) {
        setImpl(type, triggerAtMillis, legacyExactLength(), 0, operation, null);
        setImpl(type, triggerAtMillis, legacyExactLength(), 0, operation, null, null);
    }

    /**
@@ -249,7 +262,7 @@ public class AlarmManager
     */
    public void setRepeating(int type, long triggerAtMillis,
            long intervalMillis, PendingIntent operation) {
        setImpl(type, triggerAtMillis, legacyExactLength(), intervalMillis, operation, null);
        setImpl(type, triggerAtMillis, legacyExactLength(), intervalMillis, operation, null, null);
    }

    /**
@@ -299,7 +312,7 @@ public class AlarmManager
     */
    public void setWindow(int type, long windowStartMillis, long windowLengthMillis,
            PendingIntent operation) {
        setImpl(type, windowStartMillis, windowLengthMillis, 0, operation, null);
        setImpl(type, windowStartMillis, windowLengthMillis, 0, operation, null, null);
    }

    /**
@@ -337,17 +350,45 @@ public class AlarmManager
     * @see #RTC_WAKEUP
     */
    public void setExact(int type, long triggerAtMillis, PendingIntent operation) {
        setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, operation, null);
        setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, operation, null, null);
    }

    /**
     * Schedule an alarm that represents an alarm clock.
     *
     * The system may choose to display information about this alarm to the user.
     *
     * <p>
     * This method is like {@link #setExact(int, long, PendingIntent)}, but implies
     * {@link #RTC_WAKEUP}.
     *
     * @param info
     * @param operation Action to perform when the alarm goes off;
     *        typically comes from {@link PendingIntent#getBroadcast
     *        IntentSender.getBroadcast()}.
     *
     * @see #set
     * @see #setRepeating
     * @see #setWindow
     * @see #setExact
     * @see #cancel
     * @see #getNextAlarmClock()
     * @see android.content.Context#sendBroadcast
     * @see android.content.Context#registerReceiver
     * @see android.content.Intent#filterEquals
     */
    public void setAlarmClock(AlarmClockInfo info, PendingIntent operation) {
        setImpl(RTC_WAKEUP, info.getTriggerTime(), WINDOW_EXACT, 0, operation, null, info);
    }

    /** @hide */
    public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis,
            PendingIntent operation, WorkSource workSource) {
        setImpl(type, triggerAtMillis, windowMillis, intervalMillis, operation, workSource);
        setImpl(type, triggerAtMillis, windowMillis, intervalMillis, operation, workSource, null);
    }

    private void setImpl(int type, long triggerAtMillis, long windowMillis, long intervalMillis,
            PendingIntent operation, WorkSource workSource) {
            PendingIntent operation, WorkSource workSource, AlarmClockInfo alarmClock) {
        if (triggerAtMillis < 0) {
            /* NOTYET
            if (mAlwaysExact) {
@@ -361,7 +402,7 @@ public class AlarmManager

        try {
            mService.set(type, triggerAtMillis, windowMillis, intervalMillis, operation,
                    workSource);
                    workSource, alarmClock);
        } catch (RemoteException ex) {
        }
    }
@@ -461,7 +502,7 @@ public class AlarmManager
     */
    public void setInexactRepeating(int type, long triggerAtMillis,
            long intervalMillis, PendingIntent operation) {
        setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, intervalMillis, operation, null);
        setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, intervalMillis, operation, null, null);
    }
    
    /**
@@ -506,4 +547,36 @@ public class AlarmManager
        } catch (RemoteException ex) {
        }
    }

    /**
     * Gets information about the next alarm clock currently scheduled.
     *
     * The alarm clocks considered are those scheduled by {@link #setAlarmClock}
     * from any package of the calling user.
     *
     * @see #setAlarmClock
     * @see AlarmClockInfo
     */
    public AlarmClockInfo getNextAlarmClock() {
        return getNextAlarmClock(UserHandle.myUserId());
    }

    /**
     * Gets information about the next alarm clock currently scheduled.
     *
     * The alarm clocks considered are those scheduled by {@link #setAlarmClock}
     * from any package of the given {@parm userId}.
     *
     * @see #setAlarmClock
     * @see AlarmClockInfo
     *
     * @hide
     */
    public AlarmClockInfo getNextAlarmClock(int userId) {
        try {
            return mService.getNextAlarmClock(userId);
        } catch (RemoteException ex) {
            return null;
        }
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
*/
package android.app;

import android.app.AlarmClockInfo;
import android.app.PendingIntent;
import android.os.WorkSource;

@@ -27,10 +28,12 @@ import android.os.WorkSource;
interface IAlarmManager {
	/** windowLength == 0 means exact; windowLength < 0 means the let the OS decide */
    void set(int type, long triggerAtTime, long windowLength,
            long interval, in PendingIntent operation, in WorkSource workSource);
            long interval, in PendingIntent operation, in WorkSource workSource,
            in AlarmClockInfo alarmClock);
    boolean setTime(long millis);
    void setTimeZone(String zone);
    void remove(in PendingIntent operation);
    AlarmClockInfo getNextAlarmClock(int userId);
}

Loading