summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorSean Stout <sstout@google.com>2017-01-09 15:36:19 -0800
committerSean Stout <sstout@google.com>2017-01-09 17:05:05 -0800
commit0f5bb7f76c3e77a62e43cefce0444d447ae40f03 (patch)
tree55eadbf8888b680597428d4d2f43b23c278061c2 /src/com
parent3385e658639cad89b4d6c49b1ab80a969c2d2369 (diff)
downloadandroid_packages_apps_DeskClock-0f5bb7f76c3e77a62e43cefce0444d447ae40f03.tar.gz
android_packages_apps_DeskClock-0f5bb7f76c3e77a62e43cefce0444d447ae40f03.tar.bz2
android_packages_apps_DeskClock-0f5bb7f76c3e77a62e43cefce0444d447ae40f03.zip
Change method of getting initial phone state for listener.
Bug: 34147269 Test: manual - call phone while alarm is going off Change-Id: Idbec14c57220abcdf9e7c7de9f19b3c862d5bafd
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/deskclock/alarms/AlarmService.java45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/com/android/deskclock/alarms/AlarmService.java b/src/com/android/deskclock/alarms/AlarmService.java
index 0de462316..b9a97db1b 100644
--- a/src/com/android/deskclock/alarms/AlarmService.java
+++ b/src/com/android/deskclock/alarms/AlarmService.java
@@ -62,12 +62,15 @@ public class AlarmService extends Service {
/** Private action used to stop an alarm with this service. */
public static final String STOP_ALARM_ACTION = "STOP_ALARM";
- /** Binder given to AlarmActivity */
+ /** Binder given to AlarmActivity. */
private final IBinder mBinder = new Binder();
/** Whether the service is currently bound to AlarmActivity */
private boolean mIsBound = false;
+ /** Listener for changes in phone state. */
+ private final PhoneStateChangeListener mPhoneStateListener = new PhoneStateChangeListener();
+
/** Whether the receiver is currently registered */
private boolean mIsRegistered = false;
@@ -99,23 +102,8 @@ public class AlarmService extends Service {
}
private TelephonyManager mTelephonyManager;
- private int mInitialCallState;
private AlarmInstance mCurrentAlarm = null;
- private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
- @Override
- public void onCallStateChanged(int state, String ignored) {
- // The user might already be in a call when the alarm fires. When
- // we register onCallStateChanged, we get the initial in-call state
- // which kills the alarm. Check against the initial call state so
- // we don't kill the alarm during a call.
- if (state != TelephonyManager.CALL_STATE_IDLE && state != mInitialCallState) {
- startService(AlarmStateManager.createStateChangeIntent(AlarmService.this,
- "AlarmService", mCurrentAlarm, AlarmInstance.MISSED_STATE));
- }
- }
- };
-
private void startAlarm(AlarmInstance instance) {
LogUtils.v("AlarmService.start with instance: " + instance.mId);
if (mCurrentAlarm != null) {
@@ -127,8 +115,7 @@ public class AlarmService extends Service {
mCurrentAlarm = instance;
AlarmNotifications.showAlarmNotification(this, mCurrentAlarm);
- mInitialCallState = mTelephonyManager.getCallState();
- mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
+ mTelephonyManager.listen(mPhoneStateListener.init(), PhoneStateListener.LISTEN_CALL_STATE);
AlarmKlaxon.start(this, mCurrentAlarm);
sendBroadcast(new Intent(ALARM_ALERT_ACTION));
}
@@ -255,4 +242,26 @@ public class AlarmService extends Service {
mIsRegistered = false;
}
}
+
+ private final class PhoneStateChangeListener extends PhoneStateListener {
+
+ private int mPhoneCallState;
+
+ PhoneStateChangeListener init() {
+ mPhoneCallState = -1;
+ return this;
+ }
+
+ @Override
+ public void onCallStateChanged(int state, String ignored) {
+ if (mPhoneCallState == -1) {
+ mPhoneCallState = state;
+ }
+
+ if (state != TelephonyManager.CALL_STATE_IDLE && state != mPhoneCallState) {
+ startService(AlarmStateManager.createStateChangeIntent(AlarmService.this,
+ "AlarmService", mCurrentAlarm, AlarmInstance.MISSED_STATE));
+ }
+ }
+ }
}