From c857f90590e7d7fcffa89511982eb33afd34805f Mon Sep 17 00:00:00 2001 From: Eric Erfanian Date: Mon, 15 May 2017 14:05:33 -0700 Subject: Update Dialer to v10 RC32 This release was created following the instructions at: go/dialer-aosp-release Subsequent dialer releases will follow as O bugs are fixed, until we reach our final RC. Version: 10 Candidate: RC32 Branch: dialer-android_release_branch/153304843.1 dialer-android_20170416.00/dialer-android_20170416.00_RC32 This release contains the following bug fixes since RC17: Bug: 33176679 33272455 3646510 36773894 37297649 37413780 37513689 37640315 37680595 37698062 37873639 37901752 37919295 37953423 38062852 38069600 38137349 38173549 38180252 38191514 Test: make, on device Change-Id: I4e4bb630082758e418ff24892b7db3142c6eb09a --- .../com/android/voicemail/impl/ActivationTask.java | 49 +------------ .../com/android/voicemail/impl/AndroidManifest.xml | 5 ++ .../impl/DeviceProvisionedJobService.java | 85 ++++++++++++++++++++++ java/com/android/voicemail/impl/OmtpService.java | 6 ++ .../voicemail/impl/OmtpVvmCarrierConfigHelper.java | 3 +- .../voicemail/impl/TelephonyVvmConfigManager.java | 24 ++++-- .../android/voicemail/impl/res/xml/vvm_config.xml | 64 ++++++++++++++++ .../voicemail/impl/scheduling/TaskExecutor.java | 9 ++- .../voicemail/impl/scheduling/TaskReceiver.java | 5 +- .../impl/scheduling/TaskSchedulerJobService.java | 35 ++++++++- 10 files changed, 224 insertions(+), 61 deletions(-) create mode 100644 java/com/android/voicemail/impl/DeviceProvisionedJobService.java (limited to 'java/com/android/voicemail') diff --git a/java/com/android/voicemail/impl/ActivationTask.java b/java/com/android/voicemail/impl/ActivationTask.java index 91e369531..6e27b5015 100644 --- a/java/com/android/voicemail/impl/ActivationTask.java +++ b/java/com/android/voicemail/impl/ActivationTask.java @@ -19,11 +19,9 @@ package com.android.voicemail.impl; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; -import android.database.ContentObserver; import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.provider.Settings; -import android.provider.Settings.Global; import android.support.annotation.Nullable; import android.support.annotation.WorkerThread; import android.telecom.PhoneAccountHandle; @@ -43,8 +41,6 @@ import com.android.voicemail.impl.sync.SyncTask; import com.android.voicemail.impl.sync.VvmAccountManager; import com.android.voicemail.impl.utils.LoggerUtils; import java.io.IOException; -import java.util.HashSet; -import java.util.Set; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -67,8 +63,6 @@ public class ActivationTask extends BaseTask { private static final String EXTRA_MESSAGE_DATA_BUNDLE = "extra_message_data_bundle"; - @Nullable private static DeviceProvisionedObserver sDeviceProvisionedObserver; - private final RetryPolicy mRetryPolicy; private Bundle mMessageData; @@ -98,7 +92,7 @@ public class ActivationTask extends BaseTask { // Activation might need information such as system language to be set, so wait until // the setup wizard is finished. The data bundle from the SMS will be re-requested upon // activation. - queueActivationAfterProvisioned(context, phoneAccountHandle); + DeviceProvisionedJobService.activateAfterProvisioned(context, phoneAccountHandle); return; } @@ -285,45 +279,4 @@ public class ActivationTask extends BaseTask { .createForPhoneAccountHandle(phoneAccountHandle); return telephonyManager.getServiceState().getState() == ServiceState.STATE_IN_SERVICE; } - - private static void queueActivationAfterProvisioned( - Context context, PhoneAccountHandle phoneAccountHandle) { - if (sDeviceProvisionedObserver == null) { - sDeviceProvisionedObserver = new DeviceProvisionedObserver(context); - context - .getContentResolver() - .registerContentObserver( - Settings.Global.getUriFor(Global.DEVICE_PROVISIONED), - false, - sDeviceProvisionedObserver); - } - sDeviceProvisionedObserver.addPhoneAcountHandle(phoneAccountHandle); - } - - private static class DeviceProvisionedObserver extends ContentObserver { - - private final Context mContext; - private final Set mPhoneAccountHandles = new HashSet<>(); - - private DeviceProvisionedObserver(Context context) { - super(null); - mContext = context; - } - - public void addPhoneAcountHandle(PhoneAccountHandle phoneAccountHandle) { - mPhoneAccountHandles.add(phoneAccountHandle); - } - - @Override - public void onChange(boolean selfChange) { - if (isDeviceProvisioned(mContext)) { - VvmLog.i(TAG, "device provisioned, resuming activation"); - for (PhoneAccountHandle phoneAccountHandle : mPhoneAccountHandles) { - start(mContext, phoneAccountHandle, null); - } - mContext.getContentResolver().unregisterContentObserver(sDeviceProvisionedObserver); - sDeviceProvisionedObserver = null; - } - } - } } diff --git a/java/com/android/voicemail/impl/AndroidManifest.xml b/java/com/android/voicemail/impl/AndroidManifest.xml index 8c0d67f6b..3e512ba1e 100644 --- a/java/com/android/voicemail/impl/AndroidManifest.xml +++ b/java/com/android/voicemail/impl/AndroidManifest.xml @@ -91,6 +91,11 @@ android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false"/> + + sCachedConfigs; private final Map mConfigs; - public TelephonyVvmConfigManager(Resources resources) { + public TelephonyVvmConfigManager(Context context) { if (sCachedConfigs == null) { - sCachedConfigs = loadConfigs(resources.getXml(R.xml.vvm_config)); + sCachedConfigs = loadConfigs(context, context.getResources().getXml(R.xml.vvm_config)); } mConfigs = sCachedConfigs; } @VisibleForTesting - TelephonyVvmConfigManager(XmlPullParser parser) { - mConfigs = loadConfigs(parser); + TelephonyVvmConfigManager(Context context, XmlPullParser parser) { + mConfigs = loadConfigs(context, parser); } @Nullable @@ -64,7 +67,7 @@ public class TelephonyVvmConfigManager { return mConfigs.get(mccMnc); } - private static Map loadConfigs(XmlPullParser parser) { + private static Map loadConfigs(Context context, XmlPullParser parser) { Map configs = new ArrayMap<>(); try { ArrayList list = readBundleList(parser); @@ -73,6 +76,13 @@ public class TelephonyVvmConfigManager { throw new IllegalArgumentException("PersistableBundle expected, got " + object); } PersistableBundle bundle = (PersistableBundle) object; + + if (bundle.containsKey(KEY_FEATURE_FLAG_NAME) + && !ConfigProviderBindings.get(context) + .getBoolean(bundle.getString(KEY_FEATURE_FLAG_NAME), false)) { + continue; + } + String[] mccMncs = bundle.getStringArray(KEY_MCCMNC); if (mccMncs == null) { throw new IllegalArgumentException("MCCMNC is null"); diff --git a/java/com/android/voicemail/impl/res/xml/vvm_config.xml b/java/com/android/voicemail/impl/res/xml/vvm_config.xml index 230d40f90..daba3d511 100644 --- a/java/com/android/voicemail/impl/res/xml/vvm_config.xml +++ b/java/com/android/voicemail/impl/res/xml/vvm_config.xml @@ -22,6 +22,30 @@ + + + vvm_carrier_flag_20610 + + + + + + 8082 + + + + vvm_type_omtp + + + + + + + @@ -46,6 +70,30 @@ + + + vvm_carrier_flag_20610 + + + + + + 64085 + + + + vvm_type_omtp + + + + + + + @@ -85,6 +133,22 @@ + + + vvm_carrier_flag_302220 + + + + + 7723 + vvm_type_omtp + + + diff --git a/java/com/android/voicemail/impl/scheduling/TaskExecutor.java b/java/com/android/voicemail/impl/scheduling/TaskExecutor.java index 84dc1db4a..e3b718e50 100644 --- a/java/com/android/voicemail/impl/scheduling/TaskExecutor.java +++ b/java/com/android/voicemail/impl/scheduling/TaskExecutor.java @@ -193,13 +193,13 @@ final class TaskExecutor { /** Should attempt to run the next task when a task has finished or been added. */ private boolean taskAutoRunDisabledForTesting = false; + /** Handles execution of the background task in teh worker thread. */ @VisibleForTesting final class WorkerThreadHandler extends Handler { public WorkerThreadHandler(Looper looper) { super(looper); } - @Override @WorkerThread public void handleMessage(Message msg) { @@ -218,6 +218,7 @@ final class TaskExecutor { } } + /** Handles completion of the background task in the main thread. */ @VisibleForTesting final class MainThreadHandler extends Handler { @@ -233,6 +234,11 @@ final class TaskExecutor { getTasks().remove(task); task.onCompleted(); isWorkerThreadBusy = false; + if (!isJobRunning() || isTerminating()) { + // TaskExecutor was terminated when the task is running in background, don't need to run the + // next task or terminate again + return; + } maybeRunNextTask(); } } @@ -290,6 +296,7 @@ final class TaskExecutor { @MainThread private void maybeRunNextTask() { Assert.isMainThread(); + if (isWorkerThreadBusy) { return; } diff --git a/java/com/android/voicemail/impl/scheduling/TaskReceiver.java b/java/com/android/voicemail/impl/scheduling/TaskReceiver.java index 00d36d00f..e78dcf72c 100644 --- a/java/com/android/voicemail/impl/scheduling/TaskReceiver.java +++ b/java/com/android/voicemail/impl/scheduling/TaskReceiver.java @@ -49,6 +49,7 @@ public class TaskReceiver extends BroadcastReceiver { for (Intent intent : deferredBroadcasts) { context.sendBroadcast(intent); } + deferredBroadcasts.clear(); } @Override @@ -68,13 +69,13 @@ public class TaskReceiver extends BroadcastReceiver { deferredBroadcasts.add(intent); return; } - Task task = Tasks.createTask(context, intent.getExtras()); + Task task = Tasks.createTask(context.getApplicationContext(), intent.getExtras()); taskExecutor.addTask(task); } else { VvmLog.i(TAG, "scheduling new job"); List taskList = new ArrayList<>(); taskList.add(intent.getExtras()); - TaskSchedulerJobService.scheduleJob(context, taskList, 0, true); + TaskSchedulerJobService.scheduleJob(context.getApplicationContext(), taskList, 0, true); } } } diff --git a/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java b/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java index 9bfce0052..107234edc 100644 --- a/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java +++ b/java/com/android/voicemail/impl/scheduling/TaskSchedulerJobService.java @@ -23,9 +23,11 @@ import android.app.job.JobScheduler; import android.app.job.JobService; import android.content.ComponentName; import android.content.Context; +import android.content.SharedPreferences; import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.Parcelable; +import android.preference.PreferenceManager; import android.support.annotation.MainThread; import com.android.dialer.constants.ScheduledJobIds; import com.android.voicemail.impl.Assert; @@ -41,11 +43,28 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor. private static final String EXTRA_TASK_EXTRAS_ARRAY = "extra_task_extras_array"; + private static final String EXTRA_JOB_ID = "extra_job_id"; + + private static final String EXPECTED_JOB_ID = + "com.android.voicemail.impl.scheduling.TaskSchedulerJobService.EXPECTED_JOB_ID"; + + private static final String NEXT_JOB_ID = + "com.android.voicemail.impl.scheduling.TaskSchedulerJobService.NEXT_JOB_ID"; + private JobParameters jobParameters; @Override @MainThread public boolean onStartJob(JobParameters params) { + int jobId = params.getTransientExtras().getInt(EXTRA_JOB_ID); + int expectedJobId = + PreferenceManager.getDefaultSharedPreferences(this).getInt(EXPECTED_JOB_ID, 0); + if (jobId != expectedJobId) { + VvmLog.e( + TAG, "Job " + jobId + " is not the last scheduled job " + expectedJobId + ", ignoring"); + return false; // nothing more to do. Job not running in background. + } + VvmLog.i(TAG, "starting " + jobId); jobParameters = params; TaskExecutor.createRunningInstance(this); TaskExecutor.getRunningInstance() @@ -97,6 +116,13 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor. jobScheduler.cancel(ScheduledJobIds.VVM_TASK_SCHEDULER_JOB); } Bundle extras = new Bundle(); + int jobId = createJobId(context); + extras.putInt(EXTRA_JOB_ID, jobId); + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putInt(EXPECTED_JOB_ID, jobId) + .apply(); + extras.putParcelableArray( EXTRA_TASK_EXTRAS_ARRAY, pendingTasks.toArray(new Bundle[pendingTasks.size()])); JobInfo.Builder builder = @@ -112,7 +138,7 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor. VvmLog.i(TAG, "running job instantly."); } jobScheduler.schedule(builder.build()); - VvmLog.i(TAG, "job scheduled"); + VvmLog.i(TAG, "job " + jobId + " scheduled"); } /** @@ -143,4 +169,11 @@ public class TaskSchedulerJobService extends JobService implements TaskExecutor. } return result; } + + private static int createJobId(Context context) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + int jobId = sharedPreferences.getInt(NEXT_JOB_ID, 0); + sharedPreferences.edit().putInt(NEXT_JOB_ID, jobId + 1).apply(); + return jobId; + } } -- cgit v1.2.3