Fix Android Studio warnings.
Type parameters can be ommited if defined and declared in same statement. `onStart()` is deprecated and not required, as we target APIs > 5. `Intent.FLAG_ACTIVITY_CLEAR_TASK` is not supported on APIs < 11 but we target 8.
This commit is contained in:
parent
ef75f30701
commit
da8a142510
@ -66,20 +66,20 @@ public class InstallManagerService extends Service {
|
||||
* matching the {@link App}s in {@code ACTIVE_APPS}. The key is the download URL, as
|
||||
* in {@link Apk#getUrl()} or {@code urlString}.
|
||||
*/
|
||||
private static final HashMap<String, Apk> ACTIVE_APKS = new HashMap<String, Apk>(3);
|
||||
private static final HashMap<String, Apk> ACTIVE_APKS = new HashMap<>(3);
|
||||
|
||||
/**
|
||||
* The collection of {@link App}s that are actively going through this whole process,
|
||||
* matching the {@link Apk}s in {@code ACTIVE_APKS}. The key is the
|
||||
* {@code packageName} of the app.
|
||||
*/
|
||||
private static final HashMap<String, App> ACTIVE_APPS = new HashMap<String, App>(3);
|
||||
private static final HashMap<String, App> ACTIVE_APPS = new HashMap<>(3);
|
||||
|
||||
/**
|
||||
* The array of active {@link BroadcastReceiver}s for each active APK. The key is the
|
||||
* download URL, as in {@link Apk#getUrl()} or {@code urlString}.
|
||||
*/
|
||||
private final HashMap<String, BroadcastReceiver[]> receivers = new HashMap<String, BroadcastReceiver[]>(3);
|
||||
private final HashMap<String, BroadcastReceiver[]> receivers = new HashMap<>(3);
|
||||
|
||||
/**
|
||||
* Get the app name based on a {@code urlString} key. The app name needs
|
||||
@ -91,7 +91,7 @@ public class InstallManagerService extends Service {
|
||||
* <p>
|
||||
* TODO <b>delete me once InstallerService exists</b>
|
||||
*/
|
||||
private static final HashMap<String, String> TEMP_HACK_APP_NAMES = new HashMap<String, String>(3);
|
||||
private static final HashMap<String, String> TEMP_HACK_APP_NAMES = new HashMap<>(3);
|
||||
|
||||
private LocalBroadcastManager localBroadcastManager;
|
||||
private NotificationManager notificationManager;
|
||||
|
@ -30,6 +30,7 @@ import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.PatternMatcher;
|
||||
import android.os.Process;
|
||||
import android.support.v4.content.IntentCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@ -109,14 +110,14 @@ public class DownloaderService extends Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
super.onStart(intent, startId);
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Utils.debugLog(TAG, "Received Intent for downloading: " + intent + " (with a startId of " + startId + ")");
|
||||
String uriString = intent.getDataString();
|
||||
if (uriString == null) {
|
||||
Log.e(TAG, "Received Intent with no URI: " + intent);
|
||||
return;
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
if (ACTION_CANCEL.equals(intent.getAction())) {
|
||||
Utils.debugLog(TAG, "Cancelling download of " + uriString);
|
||||
Integer whatToRemove = uriString.hashCode();
|
||||
@ -139,26 +140,21 @@ public class DownloaderService extends Service {
|
||||
} else {
|
||||
Log.e(TAG, "Received Intent with unknown action: " + intent);
|
||||
}
|
||||
|
||||
return START_REDELIVER_INTENT; // if killed before completion, retry Intent
|
||||
}
|
||||
|
||||
public static PendingIntent getCancelPendingIntent(Context context, String urlString) {
|
||||
Intent cancelIntent = new Intent(context.getApplicationContext(), DownloaderService.class)
|
||||
.setData(Uri.parse(urlString))
|
||||
.setAction(ACTION_CANCEL)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
return PendingIntent.getService(context.getApplicationContext(),
|
||||
urlString.hashCode(),
|
||||
cancelIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Utils.debugLog(TAG, "onStartCommand " + intent);
|
||||
onStart(intent, startId);
|
||||
return START_REDELIVER_INTENT; // if killed before completion, retry Intent
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Utils.debugLog(TAG, "Destroying downloader service. Will move to background and stop our Looper.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user