Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/upgrade/PackageReplacedBroadcastReceiver.java

Issue 2807213002: [Android O] Initialize channels on first launch/upgrade (Closed)
Patch Set: Some more minor things Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.upgrade; 5 package org.chromium.chrome.browser.upgrade;
6 6
7 import android.content.BroadcastReceiver; 7 import android.content.BroadcastReceiver;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.os.AsyncTask;
10 import android.os.Build; 11 import android.os.Build;
11 12
13 import org.chromium.chrome.browser.notifications.ChannelsUpdater;
14
12 /** 15 /**
13 * Triggered when Chrome's package is replaced (e.g. when it is upgraded). 16 * Triggered when Chrome's package is replaced (e.g. when it is upgraded).
14 * 17 *
15 * Before changing this class, you must understand both the Receiver and Process Lifecycles: 18 * Before changing this class, you must understand both the Receiver and Process Lifecycles:
16 * http://developer.android.com/reference/android/content/BroadcastReceiver.html #ReceiverLifecycle 19 * http://developer.android.com/reference/android/content/BroadcastReceiver.html #ReceiverLifecycle
17 * 20 *
18 * - This process runs in the foreground as long as {@link #onReceive} is runnin g. If there are no 21 * - This process runs in the foreground as long as {@link #onReceive} is runnin g. If there are no
19 * other application components running, Android will aggressively kill it. 22 * other application components running, Android will aggressively kill it.
20 * 23 *
21 * - Because this runs in the foreground, don't add any code that could cause ja nk or ANRs. 24 * - Because this runs in the foreground, don't add any code that could cause ja nk or ANRs.
22 * 25 *
23 * - This class immediately cullable by Android as soon as {@link #onReceive} re turns. To kick off 26 * - This class immediately cullable by Android as soon as {@link #onReceive} re turns. To kick off
24 * longer tasks, you must start a Service. 27 * longer tasks, you must start a Service.
25 */ 28 */
26 public final class PackageReplacedBroadcastReceiver extends BroadcastReceiver { 29 public final class PackageReplacedBroadcastReceiver extends BroadcastReceiver {
27 @Override 30 @Override
28 public void onReceive(Context context, Intent intent) { 31 public void onReceive(final Context context, Intent intent) {
29 if (!Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) retur n; 32 if (!Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) retur n;
33 updateChannelsIfNecessary();
30 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) return; 34 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) return;
31 UpgradeIntentService.startMigrationIfNecessary(context); 35 UpgradeIntentService.startMigrationIfNecessary(context);
32 } 36 }
37
38 private void updateChannelsIfNecessary() {
39 if (!ChannelsUpdater.getInstance().shouldUpdateChannels()) return;
40
41 final PendingResult result = goAsync();
42 new AsyncTask<Void, Void, Void>() {
43 @Override
44 protected Void doInBackground(Void... params) {
45 ChannelsUpdater.getInstance().updateChannels();
46 result.finish();
47 return null;
48 }
49 }
50 .executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
51 }
33 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698