diff options
| author | 2015-11-22 18:25:01 +0900 | |
|---|---|---|
| committer | 2015-11-24 13:47:15 +0900 | |
| commit | e5f11cd6cc11efed1f33e47252e737b459ea33ce (patch) | |
| tree | bc6541a0143f855093f22907453db22ee955be0a | |
| parent | 9b43ce0c98ce9f865d6db547529d098c8982ccc2 (diff) | |
Refactor alarm setting code in preparation for switch to callback
Bug: 25823676
Change-Id: Id4d1031b5bd3a7f041c32ad4ac9384e045b385e8
| -rw-r--r-- | services/net/java/android/net/dhcp/DhcpClient.java | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/services/net/java/android/net/dhcp/DhcpClient.java b/services/net/java/android/net/dhcp/DhcpClient.java index c9efc69b5979..20f80223f6f9 100644 --- a/services/net/java/android/net/dhcp/DhcpClient.java +++ b/services/net/java/android/net/dhcp/DhcpClient.java @@ -266,6 +266,10 @@ public class DhcpClient extends BaseDhcpStateMachine { return pendingIntent; } + private void setAlarm(long alarmTime, PendingIntent intent) { + mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmTime, intent); + } + private boolean initInterface() { try { mIface = NetworkInterface.getByName(mIfaceName); @@ -429,7 +433,7 @@ public class DhcpClient extends BaseDhcpStateMachine { if (mDhcpLeaseExpiry != 0) { long now = SystemClock.elapsedRealtime(); long alarmTime = (now + mDhcpLeaseExpiry) / 2; - mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmTime, mRenewIntent); + setAlarm(alarmTime, mRenewIntent); Log.d(TAG, "Scheduling renewal in " + ((alarmTime - now) / 1000) + "s"); } else { Log.d(TAG, "Infinite lease, no renewal needed"); @@ -561,8 +565,7 @@ public class DhcpClient extends BaseDhcpStateMachine { // one state, so we can just use the state timeout. private void scheduleOneshotTimeout() { final long alarmTime = SystemClock.elapsedRealtime() + DHCP_TIMEOUT_MS; - mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmTime, - mOneshotTimeoutIntent); + setAlarm(alarmTime, mOneshotTimeoutIntent); } private void cancelOneshotTimeout() { @@ -732,7 +735,7 @@ public class DhcpClient extends BaseDhcpStateMachine { long timeout = jitterTimer(mTimer); long alarmTime = now + timeout; mAlarmManager.cancel(mKickIntent); - mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmTime, mKickIntent); + setAlarm(alarmTime, mKickIntent); mTimer *= 2; if (mTimer > MAX_TIMEOUT_MS) { mTimer = MAX_TIMEOUT_MS; |