Commit e7218e4f authored by Joy Ming's avatar Joy Ming Committed by Commit Bot

[Downloads notification] Add debugging logs.

Since unswipeable notification issues are ephemeral and hard to
to reproduce, adding logs with the 'DownloadFg' tag that will be visible
in logcat if a bugreport is taken.

Bug: 752675, b/73846764
Change-Id: I8272b690906ae16165a232c1679fce124e70410d
Reviewed-on: https://chromium-review.googlesource.com/943929
Commit-Queue: Joy Ming <jming@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540989}
parent 6513c0a1
......@@ -20,6 +20,7 @@ import android.support.annotation.Nullable;
import android.support.v4.app.ServiceCompat;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.AppHooks;
......@@ -27,6 +28,7 @@ import org.chromium.chrome.browser.AppHooks;
* Keep-alive foreground service for downloads.
*/
public class DownloadForegroundService extends Service {
private static final String TAG = "DownloadFg";
private static final String KEY_PERSISTED_NOTIFICATION_ID = "PersistedNotificationId";
private final IBinder mBinder = new LocalBinder();
......@@ -73,6 +75,9 @@ public class DownloadForegroundService extends Service {
*/
public void startOrUpdateForegroundService(int newNotificationId, Notification newNotification,
int oldNotificationId, Notification oldNotification) {
Log.w(TAG,
"startOrUpdateForegroundService new: " + newNotificationId
+ ", old: " + oldNotificationId);
// Handle notifications and start foreground.
if (oldNotificationId == INVALID_NOTIFICATION_ID && oldNotification == null) {
// If there is no old notification or old notification id, just start foreground.
......@@ -118,6 +123,9 @@ public class DownloadForegroundService extends Service {
public boolean stopDownloadForegroundService(
@StopForegroundNotification int stopForegroundNotification, int pinnedNotificationId,
Notification pinnedNotification) {
Log.w(TAG,
"stopDownloadForegroundService status: " + stopForegroundNotification
+ ", id: " + pinnedNotificationId);
// Record when stopping foreground.
DownloadNotificationUmaHelper.recordForegroundServiceLifecycleHistogram(
DownloadNotificationUmaHelper.ForegroundLifecycle.STOP);
......@@ -190,8 +198,10 @@ public class DownloadForegroundService extends Service {
// Alert observers that the service restarted with null intent.
// Pass along the id of the notification that was pinned to the service when it died so
// that the observers can do any corrections (ie. relaunch notification) if needed.
int persistedNotificationId = getPersistedNotificationId();
Log.w(TAG, "onStartCommand intent: " + null + ", id: " + persistedNotificationId);
DownloadForegroundServiceObservers.alertObserversServiceRestarted(
getPersistedNotificationId());
persistedNotificationId);
clearPersistedNotificationId();
// Allow observers to restart service on their own, if needed.
......@@ -280,11 +290,13 @@ public class DownloadForegroundService extends Service {
@VisibleForTesting
void startForegroundInternal(int notificationId, Notification notification) {
Log.w(TAG, "startForegroundInternal id: " + notificationId);
startForeground(notificationId, notification);
}
@VisibleForTesting
void stopForegroundInternal(int flags) {
Log.w(TAG, "stopForegroundInternal flags: " + flags);
ServiceCompat.stopForeground(this, flags);
}
......
......@@ -48,7 +48,7 @@ public class DownloadForegroundServiceManager {
}
}
private static final String TAG = "DownloadFgSManager";
private static final String TAG = "DownloadFg";
@VisibleForTesting
final Map<Integer, DownloadUpdate> mDownloadUpdateQueue = new HashMap<>();
......@@ -66,6 +66,10 @@ public class DownloadForegroundServiceManager {
public void updateDownloadStatus(Context context, DownloadStatus downloadStatus,
int notificationId, Notification notification) {
if (downloadStatus != DownloadStatus.IN_PROGRESS) {
Log.w(TAG,
"updateDownloadStatus status: " + downloadStatus + ", id: " + notificationId);
}
mDownloadUpdateQueue.put(notificationId,
new DownloadUpdate(notificationId, notification, downloadStatus, context));
processDownloadUpdateQueue(false /* not isProcessingPending */);
......@@ -171,6 +175,7 @@ public class DownloadForegroundServiceManager {
@VisibleForTesting
void startAndBindService(Context context) {
Log.w(TAG, "startAndBindService");
mIsServiceBound = true;
startAndBindServiceInternal(context);
}
......@@ -185,6 +190,7 @@ public class DownloadForegroundServiceManager {
private final ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
Log.w(TAG, "onServiceConnected");
if (!(service instanceof DownloadForegroundService.LocalBinder)) {
Log.w(TAG,
"Not from DownloadNotificationService, do not connect."
......@@ -199,6 +205,7 @@ public class DownloadForegroundServiceManager {
@Override
public void onServiceDisconnected(ComponentName componentName) {
Log.w(TAG, "onServiceDisconnected");
mBoundService = null;
}
};
......@@ -207,6 +214,7 @@ public class DownloadForegroundServiceManager {
@VisibleForTesting
void startOrUpdateForegroundService(int notificationId, Notification notification) {
Log.w(TAG, "startOrUpdateForegroundService id: " + notificationId);
if (mBoundService != null && notificationId != INVALID_NOTIFICATION_ID
&& notification != null) {
// If there was an originally pinned notification, get its id and notification.
......@@ -227,6 +235,7 @@ public class DownloadForegroundServiceManager {
@VisibleForTesting
void stopAndUnbindService(DownloadStatus downloadStatus) {
Log.w(TAG, "stopAndUnbindService status: " + downloadStatus);
Preconditions.checkNotNull(mBoundService);
mIsServiceBound = false;
......
......@@ -501,6 +501,7 @@ public class DownloadNotificationService extends Service {
@VisibleForTesting
@TargetApi(Build.VERSION_CODES.N)
void stopForegroundInternal(boolean killNotification) {
Log.w(TAG, "stopForegroundInternal killNotification: " + killNotification);
if (!useForegroundService()) return;
stopForeground(killNotification ? STOP_FOREGROUND_REMOVE : STOP_FOREGROUND_DETACH);
}
......@@ -511,6 +512,7 @@ public class DownloadNotificationService extends Service {
*/
@VisibleForTesting
void startForegroundInternal() {
Log.w(TAG, "startForegroundInternal");
if (!useForegroundService()) return;
Notification notification =
buildSummaryNotification(getApplicationContext(), mNotificationManager);
......@@ -570,6 +572,7 @@ public class DownloadNotificationService extends Service {
* @param id The {@link ContentId} of the download that has been started and should be tracked.
*/
private void startTrackingInProgressDownload(ContentId id) {
Log.w(TAG, "startTrackingInProgressDownload");
if (mDownloadsInProgress.size() == 0) startForegroundInternal();
if (!mDownloadsInProgress.contains(id)) mDownloadsInProgress.add(id);
}
......@@ -586,6 +589,7 @@ public class DownloadNotificationService extends Service {
* potentially bad state where we cannot dismiss the notification.
*/
private void stopTrackingInProgressDownload(ContentId id, boolean allowStopForeground) {
Log.w(TAG, "stopTrackingInProgressDownload");
mDownloadsInProgress.remove(id);
if (allowStopForeground && mDownloadsInProgress.size() == 0) stopForegroundInternal(false);
}
......@@ -630,6 +634,7 @@ public class DownloadNotificationService extends Service {
*/
@SuppressLint("NewApi") // useForegroundService guards StatusBarNotification.getNotification
boolean hideSummaryNotificationIfNecessary(int notificationIdToIgnore) {
Log.w(TAG, "hideSummaryNotificationIfNecessary id: " + notificationIdToIgnore);
if (mDownloadsInProgress.size() > 0) return false;
if (useForegroundService()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment