summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2017-02-09 16:56:51 -0800
committerMakoto Onuki <omakoto@google.com>2017-02-09 17:00:38 -0800
commitf26261b11e66435addeeb6c62978eb3fc767a4ec (patch)
treefa08dbc79c3c87c447ad9de8793139d685b943cf
parent7c018bc1d64f767e04be6ea026e3886eb9267ce0 (diff)
downloadandroid_packages_providers_CalendarProvider-f26261b11e66435addeeb6c62978eb3fc767a4ec.tar.gz
android_packages_providers_CalendarProvider-f26261b11e66435addeeb6c62978eb3fc767a4ec.tar.bz2
android_packages_providers_CalendarProvider-f26261b11e66435addeeb6c62978eb3fc767a4ec.zip
Stop using IntentService and use async receiver.
Also: - Set FLAG_RECEIVER_INCLUDE_BACKGROUND for ACTION_EVENT_REMINDER - Remove the wake lock; with goAsync() now it's not needed. Test: Manual test with: adb shell am broadcast --receiver-include-background -a android.intent.action.EVENT_REMINDER -d content: Bug 35207106 Change-Id: Ib3afd744c5b94522d08778c367641d7c8f444a1f
-rw-r--r--AndroidManifest.xml1
-rw-r--r--src/com/android/providers/calendar/CalendarAlarmManager.java31
-rw-r--r--src/com/android/providers/calendar/CalendarProviderBroadcastReceiver.java29
-rw-r--r--src/com/android/providers/calendar/CalendarProviderIntentService.java51
-rw-r--r--tests/src/com/android/providers/calendar/CalendarProvider2ForTesting.java14
5 files changed, 22 insertions, 104 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9e92336..e567b52 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -113,7 +113,6 @@
<data android:scheme="content" />
</intent-filter>
</receiver>
- <service android:name="CalendarProviderIntentService"/>
</application>
</manifest>
diff --git a/src/com/android/providers/calendar/CalendarAlarmManager.java b/src/com/android/providers/calendar/CalendarAlarmManager.java
index ac14713..adb98c4 100644
--- a/src/com/android/providers/calendar/CalendarAlarmManager.java
+++ b/src/com/android/providers/calendar/CalendarAlarmManager.java
@@ -127,10 +127,6 @@ public class CalendarAlarmManager {
*/
@VisibleForTesting
protected Object mAlarmLock;
- /**
- * Used to keep the process from getting killed while scheduling alarms
- */
- private final WakeLock mScheduleNextAlarmWakeLock;
@VisibleForTesting
protected Context mContext;
@@ -141,14 +137,6 @@ public class CalendarAlarmManager {
PowerManager powerManager = (PowerManager) mContext.getSystemService(
Context.POWER_SERVICE);
- // Create a wake lock that will be used when we are actually
- // scheduling the next alarm
- mScheduleNextAlarmWakeLock = powerManager.newWakeLock(
- PowerManager.PARTIAL_WAKE_LOCK, SCHEDULE_NEXT_ALARM_WAKE_LOCK);
- // We want the Wake Lock to be reference counted (so that we dont
- // need to take care
- // about its reference counting)
- mScheduleNextAlarmWakeLock.setReferenceCounted(true);
}
protected void initializeWithContext(Context context) {
@@ -229,25 +217,6 @@ public class CalendarAlarmManager {
setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTimeMillis, pending);
}
- PowerManager.WakeLock getScheduleNextAlarmWakeLock() {
- return mScheduleNextAlarmWakeLock;
- }
-
- void acquireScheduleNextAlarmWakeLock() {
- getScheduleNextAlarmWakeLock().acquire();
- }
-
- void releaseScheduleNextAlarmWakeLock() {
- try {
- getScheduleNextAlarmWakeLock().release();
- } catch (RuntimeException e) {
- if (!e.getMessage().startsWith("WakeLock under-locked ")) {
- throw e;
- }
- Log.w(TAG, "WakeLock under-locked ignored.");
- }
- }
-
void rescheduleMissedAlarms() {
rescheduleMissedAlarms(mContext.getContentResolver());
}
diff --git a/src/com/android/providers/calendar/CalendarProviderBroadcastReceiver.java b/src/com/android/providers/calendar/CalendarProviderBroadcastReceiver.java
index af00bfa..187f6e8 100644
--- a/src/com/android/providers/calendar/CalendarProviderBroadcastReceiver.java
+++ b/src/com/android/providers/calendar/CalendarProviderBroadcastReceiver.java
@@ -24,22 +24,37 @@ import android.provider.CalendarContract;
import android.util.Log;
public class CalendarProviderBroadcastReceiver extends BroadcastReceiver {
+ private static final String TAG = CalendarProvider2.TAG;
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (!CalendarAlarmManager.ACTION_CHECK_NEXT_ALARM.equals(action)
&& !CalendarContract.ACTION_EVENT_REMINDER.equals(action)) {
+ Log.e(TAG, "Received invalid intent: " + intent);
setResultCode(Activity.RESULT_CANCELED);
return;
}
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Received intent: " + intent);
+ }
final CalendarProvider2 provider = CalendarProvider2.getInstance();
- // Acquire a wake lock that will be released when the launched Service is doing its work
- provider.getOrCreateCalendarAlarmManager().acquireScheduleNextAlarmWakeLock();
- // Set the result code
- setResultCode(Activity.RESULT_OK);
- // Launch the Service
- intent.setClass(context, CalendarProviderIntentService.class);
- context.startService(intent);
+
+ final PendingResult result = goAsync();
+
+ new Thread(() -> {
+ // Schedule the next alarm. Please be noted that for ACTION_EVENT_REMINDER broadcast,
+ // we never remove scheduled alarms.
+ final boolean removeAlarms = intent
+ .getBooleanExtra(CalendarAlarmManager.KEY_REMOVE_ALARMS, false);
+ provider.getOrCreateCalendarAlarmManager().runScheduleNextAlarm(removeAlarms, provider);
+
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Next alarm set.");
+ }
+
+ result.finish();
+ }).start();
+
}
}
diff --git a/src/com/android/providers/calendar/CalendarProviderIntentService.java b/src/com/android/providers/calendar/CalendarProviderIntentService.java
deleted file mode 100644
index dcaf264..0000000
--- a/src/com/android/providers/calendar/CalendarProviderIntentService.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2010 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 com.android.providers.calendar;
-
-import android.app.IntentService;
-import android.content.Intent;
-import android.provider.CalendarContract;
-import android.util.Log;
-
-public class CalendarProviderIntentService extends IntentService {
-
- private static final String TAG = CalendarProvider2.TAG;
-
- public CalendarProviderIntentService() {
- super("CalendarProviderIntentService");
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Received Intent: " + intent);
- }
- final CalendarProvider2 provider = CalendarProvider2.getInstance();
- final String action = intent.getAction();
- if (CalendarAlarmManager.ACTION_CHECK_NEXT_ALARM.equals(action)
- || CalendarContract.ACTION_EVENT_REMINDER.equals(action)) {
- // Schedule the next alarm. Please be noted that for ACTION_EVENT_REMINDER broadcast,
- // we never remove scheduled alarms.
- final boolean removeAlarms = intent
- .getBooleanExtra(CalendarAlarmManager.KEY_REMOVE_ALARMS, false);
- provider.getOrCreateCalendarAlarmManager().runScheduleNextAlarm(removeAlarms, provider);
- // Release the wake lock that was set in the Broadcast Receiver
- provider.getOrCreateCalendarAlarmManager().releaseScheduleNextAlarmWakeLock();
- } else if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Invalid Intent action: " + action);
- }
- }
-}
diff --git a/tests/src/com/android/providers/calendar/CalendarProvider2ForTesting.java b/tests/src/com/android/providers/calendar/CalendarProvider2ForTesting.java
index 4d07bc1..e54f5bd 100644
--- a/tests/src/com/android/providers/calendar/CalendarProvider2ForTesting.java
+++ b/tests/src/com/android/providers/calendar/CalendarProvider2ForTesting.java
@@ -77,19 +77,5 @@ public class CalendarProvider2ForTesting extends CalendarProvider2 {
@Override
public void rescheduleMissedAlarms(ContentResolver cr) {
}
-
-
- @Override
- PowerManager.WakeLock getScheduleNextAlarmWakeLock() {
- return null;
- }
-
- @Override
- void acquireScheduleNextAlarmWakeLock() {
- }
-
- @Override
- void releaseScheduleNextAlarmWakeLock() {
- }
}
}