Commit 7afdf84a by olly Committed by Oliver Woodman

Fix DownloadService notification flicker

This type of flicker was visible (at least on my S8) whenever starting
the demo app process (from being properly killed) when other notifications
(e.g. completed download notification) was present.

This change passes whether the service was started as foreground through
the intent, and only applies the show-notification-on-stop hack if it
was. It's only necessary to start as foreground if your app is not already
in the foreground, so it's not necessary to do this from activity/ui
components.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=195594930
parent 983fe9cc
...@@ -126,7 +126,7 @@ public class DownloadTracker implements DownloadManager.Listener { ...@@ -126,7 +126,7 @@ public class DownloadTracker implements DownloadManager.Listener {
if (isDownloaded(uri)) { if (isDownloaded(uri)) {
DownloadAction removeAction = DownloadAction removeAction =
getDownloadHelper(uri, extension).getRemoveAction(Util.getUtf8Bytes(name)); getDownloadHelper(uri, extension).getRemoveAction(Util.getUtf8Bytes(name));
addDownloadAction(removeAction); startServiceWithAction(removeAction);
} else { } else {
StartDownloadDialogHelper helper = StartDownloadDialogHelper helper =
new StartDownloadDialogHelper(activity, getDownloadHelper(uri, extension), name); new StartDownloadDialogHelper(activity, getDownloadHelper(uri, extension), name);
...@@ -197,11 +197,11 @@ public class DownloadTracker implements DownloadManager.Listener { ...@@ -197,11 +197,11 @@ public class DownloadTracker implements DownloadManager.Listener {
} }
trackedDownloadStates.put(action.uri, action); trackedDownloadStates.put(action.uri, action);
handleTrackedDownloadStatesChanged(); handleTrackedDownloadStatesChanged();
addDownloadAction(action); startServiceWithAction(action);
} }
private void addDownloadAction(DownloadAction action) { private void startServiceWithAction(DownloadAction action) {
DownloadService.addDownloadAction(context, DemoDownloadService.class, action); DownloadService.startWithAction(context, DemoDownloadService.class, action, false);
} }
private DownloadHelper getDownloadHelper(Uri uri, String extension) { private DownloadHelper getDownloadHelper(Uri uri, String extension) {
......
...@@ -91,10 +91,12 @@ public class SampleChooserActivity extends Activity ...@@ -91,10 +91,12 @@ public class SampleChooserActivity extends Activity
} }
downloadTracker = ((DemoApplication) getApplication()).getDownloadTracker(); downloadTracker = ((DemoApplication) getApplication()).getDownloadTracker();
startDownloadServiceForeground();
SampleListLoader loaderTask = new SampleListLoader(); SampleListLoader loaderTask = new SampleListLoader();
loaderTask.execute(uris); loaderTask.execute(uris);
// Ping the download service in case it's not running (but should be).
startService(
new Intent(this, DemoDownloadService.class).setAction(DownloadService.ACTION_INIT));
} }
@Override @Override
...@@ -115,11 +117,6 @@ public class SampleChooserActivity extends Activity ...@@ -115,11 +117,6 @@ public class SampleChooserActivity extends Activity
sampleAdapter.notifyDataSetChanged(); sampleAdapter.notifyDataSetChanged();
} }
private void startDownloadServiceForeground() {
Intent intent = new Intent(DownloadService.ACTION_INIT).setPackage(getPackageName());
Util.startForegroundService(this, intent);
}
private void onSampleGroups(final List<SampleGroup> groups, boolean sawError) { private void onSampleGroups(final List<SampleGroup> groups, boolean sawError) {
if (sawError) { if (sawError) {
Toast.makeText(getApplicationContext(), R.string.sample_list_load_error, Toast.LENGTH_LONG) Toast.makeText(getApplicationContext(), R.string.sample_list_load_error, Toast.LENGTH_LONG)
......
...@@ -229,8 +229,7 @@ public class DownloadServiceDashTest { ...@@ -229,8 +229,7 @@ public class DownloadServiceDashTest {
@Override @Override
public void run() { public void run() {
Intent startIntent = Intent startIntent =
DownloadService.createAddDownloadActionIntent( DownloadService.buildAddActionIntent(context, DownloadService.class, action, false);
context, DownloadService.class, action);
dashDownloadService.onStartCommand(startIntent, 0, 0); dashDownloadService.onStartCommand(startIntent, 0, 0);
} }
}); });
......
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 sign in to comment