summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2018-03-26 11:05:29 -0700
committerCopybara-Service <copybara-piper@google.com>2018-03-26 22:23:04 -0700
commite652cbf3991aad4a46ad811f370a54c1051089e0 (patch)
tree1a84176c631cccc87c584fa41e54ada1e3af36d6 /java
parent07d6d00a5cc6c1aeb1befaccc1e832b3d5b398d8 (diff)
Catch BadParcelableException
This happens when an old dialer submitted a job and the newer dialer is trying to handle it. The class fingerprint changed so it can no longer be unparceled. In this CL, such tasks will be dropped. Bug: 64225192 Test: N/A PiperOrigin-RevId: 190491751 Change-Id: I90fe2d24a435201cfae09970387e9b1c3a58b094
Diffstat (limited to 'java')
-rw-r--r--java/com/android/voicemail/impl/scheduling/TaskQueue.java11
-rw-r--r--java/com/android/voicemail/impl/scheduling/TaskReceiver.java9
-rw-r--r--java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java7
-rw-r--r--java/com/android/voicemail/impl/scheduling/Tasks.java19
4 files changed, 38 insertions, 8 deletions
diff --git a/java/com/android/voicemail/impl/scheduling/TaskQueue.java b/java/com/android/voicemail/impl/scheduling/TaskQueue.java
index fc5aa947a..6afcf0087 100644
--- a/java/com/android/voicemail/impl/scheduling/TaskQueue.java
+++ b/java/com/android/voicemail/impl/scheduling/TaskQueue.java
@@ -23,6 +23,7 @@ import android.support.annotation.Nullable;
import com.android.voicemail.impl.Assert;
import com.android.voicemail.impl.VvmLog;
import com.android.voicemail.impl.scheduling.Task.TaskId;
+import com.android.voicemail.impl.scheduling.Tasks.TaskCreationException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
@@ -49,9 +50,13 @@ class TaskQueue implements Iterable<Task> {
public void fromBundles(Context context, List<Bundle> pendingTasks) {
Assert.isTrue(queue.isEmpty());
for (Bundle pendingTask : pendingTasks) {
- Task task = Tasks.createTask(context, pendingTask);
- task.onRestore(pendingTask);
- add(task);
+ try {
+ Task task = Tasks.createTask(context, pendingTask);
+ task.onRestore(pendingTask);
+ add(task);
+ } catch (TaskCreationException e) {
+ VvmLog.e("TaskQueue.fromBundles", "cannot create task", e);
+ }
}
}
diff --git a/java/com/android/voicemail/impl/scheduling/TaskReceiver.java b/java/com/android/voicemail/impl/scheduling/TaskReceiver.java
index e78dcf72c..b9fd272af 100644
--- a/java/com/android/voicemail/impl/scheduling/TaskReceiver.java
+++ b/java/com/android/voicemail/impl/scheduling/TaskReceiver.java
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import com.android.voicemail.impl.VvmLog;
+import com.android.voicemail.impl.scheduling.Tasks.TaskCreationException;
import java.util.ArrayList;
import java.util.List;
@@ -69,8 +70,12 @@ public class TaskReceiver extends BroadcastReceiver {
deferredBroadcasts.add(intent);
return;
}
- Task task = Tasks.createTask(context.getApplicationContext(), intent.getExtras());
- taskExecutor.addTask(task);
+ try {
+ Task task = Tasks.createTask(context.getApplicationContext(), intent.getExtras());
+ taskExecutor.addTask(task);
+ } catch (TaskCreationException e) {
+ VvmLog.e(TAG, "cannot create task", e);
+ }
} else {
VvmLog.i(TAG, "scheduling new job");
List<Bundle> taskList = new ArrayList<>();
diff --git a/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java b/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java
index 0e3f27cd8..77a0d25cd 100644
--- a/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java
+++ b/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java
@@ -33,6 +33,7 @@ import com.android.dialer.constants.ScheduledJobIds;
import com.android.dialer.strictmode.StrictModeUtils;
import com.android.voicemail.impl.Assert;
import com.android.voicemail.impl.VvmLog;
+import com.android.voicemail.impl.scheduling.Tasks.TaskCreationException;
import java.util.ArrayList;
import java.util.List;
@@ -110,7 +111,11 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor.
TaskQueue queue = new TaskQueue();
queue.fromBundles(context, existingTasks);
for (Bundle pendingTask : pendingTasks) {
- queue.add(Tasks.createTask(context, pendingTask));
+ try {
+ queue.add(Tasks.createTask(context, pendingTask));
+ } catch (TaskCreationException e) {
+ VvmLog.e(TAG, "cannot create task", e);
+ }
}
pendingTasks = queue.toBundles();
}
diff --git a/java/com/android/voicemail/impl/scheduling/Tasks.java b/java/com/android/voicemail/impl/scheduling/Tasks.java
index 76da3d7f6..0333e1686 100644
--- a/java/com/android/voicemail/impl/scheduling/Tasks.java
+++ b/java/com/android/voicemail/impl/scheduling/Tasks.java
@@ -18,6 +18,7 @@ package com.android.voicemail.impl.scheduling;
import android.content.Context;
import android.content.Intent;
+import android.os.BadParcelableException;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.android.voicemail.impl.VvmLog;
@@ -29,16 +30,30 @@ final class Tasks {
static final String EXTRA_CLASS_NAME = "extra_class_name";
+ /** The task cannot be created. */
+ static final class TaskCreationException extends Exception {
+ TaskCreationException(Throwable throwable) {
+ super(throwable);
+ }
+ }
+
/**
* Create a task from a bundle. The bundle is created either with {@link #toBundle(Task)} or
* {@link #createIntent(Context, Class)} from the target {@link Task}
*/
@NonNull
- public static Task createTask(Context context, Bundle extras) {
+ public static Task createTask(Context context, Bundle extras) throws TaskCreationException {
// The extra contains custom parcelables which cannot be unmarshalled by the framework class
// loader.
extras.setClassLoader(context.getClassLoader());
- String className = extras.getString(EXTRA_CLASS_NAME);
+ String className;
+ try {
+ className = extras.getString(EXTRA_CLASS_NAME);
+ } catch (BadParcelableException e) {
+ // BadParcelableException:Parcelable protocol requires that the class implements Parcelable
+ // This happens when the task is submitted before an update, and can no longer be unparceled.
+ throw new TaskCreationException(e);
+ }
VvmLog.i("Task.createTask", "create task:" + className);
if (className == null) {
throw new IllegalArgumentException("EXTRA_CLASS_NAME expected");