summaryrefslogtreecommitdiffstats
path: root/src/com/android/deskclock
diff options
context:
space:
mode:
authorJames Lemieux <jplemieux@google.com>2016-12-07 17:34:54 -0800
committerJames Lemieux <jplemieux@google.com>2016-12-07 17:34:54 -0800
commit58d9315aed4f645eb60c22be117b074e18c0982f (patch)
treed1bf080314b75061efd3a314c46b4797676e09c5 /src/com/android/deskclock
parent51917c54f72faa32d2cb3c287de3d0816b4f9017 (diff)
downloadandroid_packages_apps_DeskClock-58d9315aed4f645eb60c22be117b074e18c0982f.tar.gz
android_packages_apps_DeskClock-58d9315aed4f645eb60c22be117b074e18c0982f.tar.bz2
android_packages_apps_DeskClock-58d9315aed4f645eb60c22be117b074e18c0982f.zip
Prevent reset timers from having their remaining time changed
Bug: 33416541 Bug: 33397230 This CL also removes the notion of a maximum timer length. In practice, the UI components limit timer lengths to 99h 99m 99s, but more time can be added after creation and external API callers can specify longer lengths than the UI allows. Change-Id: Ib3cb503e1aecea1ceb0427e4fe8267595c84e852
Diffstat (limited to 'src/com/android/deskclock')
-rw-r--r--src/com/android/deskclock/HandleApiCalls.java2
-rw-r--r--src/com/android/deskclock/data/DataModel.java4
-rw-r--r--src/com/android/deskclock/data/Timer.java29
3 files changed, 20 insertions, 15 deletions
diff --git a/src/com/android/deskclock/HandleApiCalls.java b/src/com/android/deskclock/HandleApiCalls.java
index 782e73ce8..b840206f2 100644
--- a/src/com/android/deskclock/HandleApiCalls.java
+++ b/src/com/android/deskclock/HandleApiCalls.java
@@ -420,7 +420,7 @@ public class HandleApiCalls extends Activity {
// Verify that the timer length is between one second and one day.
final long lengthMillis = SECOND_IN_MILLIS * intent.getIntExtra(AlarmClock.EXTRA_LENGTH, 0);
- if (lengthMillis < Timer.MIN_LENGTH || lengthMillis > Timer.MAX_LENGTH) {
+ if (lengthMillis < Timer.MIN_LENGTH) {
final String voiceMessage = getString(R.string.invalid_timer_length);
Controller.getController().notifyVoiceFailure(this, voiceMessage);
LOGGER.i("Invalid timer length requested: " + lengthMillis);
diff --git a/src/com/android/deskclock/data/DataModel.java b/src/com/android/deskclock/data/DataModel.java
index f5d9328ac..dec6d784f 100644
--- a/src/com/android/deskclock/data/DataModel.java
+++ b/src/com/android/deskclock/data/DataModel.java
@@ -567,7 +567,7 @@ public final class DataModel {
}
/**
- * @param timer the timer whose {@code length} to change
+ * @param timer the timer whose {@code length} to change
* @param length the new length of the timer in milliseconds
*/
public void setTimerLength(Timer timer, long length) {
@@ -576,7 +576,7 @@ public final class DataModel {
}
/**
- * @param timer the timer whose {@code remainingTime} to change
+ * @param timer the timer whose {@code remainingTime} to change
* @param remainingTime the new remaining time of the timer in milliseconds
*/
public void setRemainingTime(Timer timer, long remainingTime) {
diff --git a/src/com/android/deskclock/data/Timer.java b/src/com/android/deskclock/data/Timer.java
index 9e7ade061..816d58786 100644
--- a/src/com/android/deskclock/data/Timer.java
+++ b/src/com/android/deskclock/data/Timer.java
@@ -72,8 +72,8 @@ public final class Timer {
/** The minimum duration of a timer. */
public static final long MIN_LENGTH = SECOND_IN_MILLIS;
- /** The maximum duration of a timer. */
- public static final long MAX_LENGTH =
+ /** The maximum duration of a new timer created via the user interface. */
+ static final long MAX_LENGTH =
99 * HOUR_IN_MILLIS + 99 * MINUTE_IN_MILLIS + 99 * SECOND_IN_MILLIS;
static final long UNUSED = Long.MIN_VALUE;
@@ -301,12 +301,11 @@ public final class Timer {
}
/**
- * @return a copy of this timer with the given {@code length}
+ * @return a copy of this timer with the given {@code length} or this timer if the length could
+ * not be legally adjusted
*/
Timer setLength(long length) {
- if (mLength == length
- || length <= 0L
- || length > MAX_LENGTH) {
+ if (mLength == length || length <= Timer.MIN_LENGTH) {
return this;
}
@@ -325,11 +324,12 @@ public final class Timer {
}
/**
- * @return a copy of this timer with the given {@code remainingTime}
+ * @return a copy of this timer with the given {@code remainingTime} or this timer if the
+ * remaining time could not be legally adjusted
*/
Timer setRemainingTime(long remainingTime) {
- // Do not allow the remaining time to exceed the maximum.
- if (mRemainingTime == remainingTime || remainingTime > MAX_LENGTH) {
+ // Do not change the remaining time of a reset timer.
+ if (mRemainingTime == remainingTime || mState == RESET) {
return this;
}
@@ -355,11 +355,16 @@ public final class Timer {
/**
* @return a copy of this timer with an additional minute added to the remaining time and total
- * length, or this Timer if adding a minute would exceed the maximum timer duration
+ * length, or this Timer if the minute could not be added
*/
Timer addMinute() {
- final long remainingTime = (mState == EXPIRED || mState == MISSED) ? 0L : mRemainingTime;
- return setRemainingTime(remainingTime + MINUTE_IN_MILLIS);
+ // Expired and missed timers restart with 60 seconds of remaining time.
+ if (mState == EXPIRED || mState == MISSED) {
+ return setRemainingTime(MINUTE_IN_MILLIS);
+ }
+
+ // Otherwise try to add a minute to the remaining time.
+ return setRemainingTime(mRemainingTime + MINUTE_IN_MILLIS);
}
@Override