Merge branch 'installer-manager-cosmetic-changes' into 'master'
Installer manager cosmetic changes This branch as some cosmetic code changes related to the `InstallManagerService`. I have a few more that I'll be throwing in here too as I go along. By and large, it is renaming, annotating, minor refactoring. The semantics should not change at all with this change, any fixes to the `InstallManagerService` will be done through separate MRs. They are from issues listed in [this comment](https://gitlab.com/fdroid/fdroidclient/merge_requests/278#note_11762414) during my CR and testing of !278. I realise that cosmetic changes often come with baggage because we all have slightly different ideas of what Java code should look like, but in general, I will strive to only make changes if I believe strongly that they will: * Improve understanding of the code (i.e. renaming, extracting methods) * Prevent future errors by new contributors (e.g. @NonNull/@Nullable annotations, extracting classes to encapsulate logic which requires developers to know they need to change multiple things at once) I try not to make changes because: * I have a different opinion about formatting. * Hopefully any other unreasonable or disagreeable reason. See merge request !282
This commit is contained in:
commit
b2f7fbd980
@ -842,7 +842,7 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog,
|
public void onClick(DialogInterface dialog,
|
||||||
int whichButton) {
|
int whichButton) {
|
||||||
startDownload(apk);
|
initiateInstall(apk);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.no,
|
builder.setNegativeButton(R.string.no,
|
||||||
@ -871,10 +871,10 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
alert.show();
|
alert.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
startDownload(apk);
|
initiateInstall(apk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startDownload(Apk apk) {
|
private void initiateInstall(Apk apk) {
|
||||||
activeDownloadUrlString = apk.getUrl();
|
activeDownloadUrlString = apk.getUrl();
|
||||||
registerDownloaderReceivers();
|
registerDownloaderReceivers();
|
||||||
headerFragment.startProgress();
|
headerFragment.startProgress();
|
||||||
|
@ -15,6 +15,7 @@ import android.support.v4.app.NotificationCompat;
|
|||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.fdroid.fdroid.AppDetails;
|
import org.fdroid.fdroid.AppDetails;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
@ -65,20 +66,20 @@ public class InstallManagerService extends Service {
|
|||||||
* matching the {@link App}s in {@code ACTIVE_APPS}. The key is the download URL, as
|
* matching the {@link App}s in {@code ACTIVE_APPS}. The key is the download URL, as
|
||||||
* in {@link Apk#getUrl()} or {@code urlString}.
|
* 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,
|
* 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
|
* matching the {@link Apk}s in {@code ACTIVE_APKS}. The key is the
|
||||||
* {@code packageName} of the app.
|
* {@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
|
* 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}.
|
* 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
|
* Get the app name based on a {@code urlString} key. The app name needs
|
||||||
@ -90,7 +91,7 @@ public class InstallManagerService extends Service {
|
|||||||
* <p>
|
* <p>
|
||||||
* TODO <b>delete me once InstallerService exists</b>
|
* 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 LocalBroadcastManager localBroadcastManager;
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
@ -132,6 +133,12 @@ public class InstallManagerService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
Utils.debugLog(TAG, "onStartCommand " + intent);
|
Utils.debugLog(TAG, "onStartCommand " + intent);
|
||||||
|
|
||||||
|
if (!ACTION_INSTALL.equals(intent.getAction())) {
|
||||||
|
Log.i(TAG, "Ignoring " + intent + " as it is not an " + ACTION_INSTALL + " intent");
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
String urlString = intent.getDataString();
|
String urlString = intent.getDataString();
|
||||||
Apk apk = ACTIVE_APKS.get(urlString);
|
Apk apk = ACTIVE_APKS.get(urlString);
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ import android.os.Looper;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.PatternMatcher;
|
import android.os.PatternMatcher;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.support.v4.content.IntentCompat;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -109,14 +110,14 @@ public class DownloaderService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(Intent intent, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
super.onStart(intent, startId);
|
|
||||||
Utils.debugLog(TAG, "Received Intent for downloading: " + intent + " (with a startId of " + startId + ")");
|
Utils.debugLog(TAG, "Received Intent for downloading: " + intent + " (with a startId of " + startId + ")");
|
||||||
String uriString = intent.getDataString();
|
String uriString = intent.getDataString();
|
||||||
if (uriString == null) {
|
if (uriString == null) {
|
||||||
Log.e(TAG, "Received Intent with no URI: " + intent);
|
Log.e(TAG, "Received Intent with no URI: " + intent);
|
||||||
return;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ACTION_CANCEL.equals(intent.getAction())) {
|
if (ACTION_CANCEL.equals(intent.getAction())) {
|
||||||
Utils.debugLog(TAG, "Cancelling download of " + uriString);
|
Utils.debugLog(TAG, "Cancelling download of " + uriString);
|
||||||
Integer whatToRemove = uriString.hashCode();
|
Integer whatToRemove = uriString.hashCode();
|
||||||
@ -139,26 +140,21 @@ public class DownloaderService extends Service {
|
|||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Received Intent with unknown action: " + intent);
|
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) {
|
public static PendingIntent getCancelPendingIntent(Context context, String urlString) {
|
||||||
Intent cancelIntent = new Intent(context.getApplicationContext(), DownloaderService.class)
|
Intent cancelIntent = new Intent(context.getApplicationContext(), DownloaderService.class)
|
||||||
.setData(Uri.parse(urlString))
|
.setData(Uri.parse(urlString))
|
||||||
.setAction(ACTION_CANCEL)
|
.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(),
|
return PendingIntent.getService(context.getApplicationContext(),
|
||||||
urlString.hashCode(),
|
urlString.hashCode(),
|
||||||
cancelIntent,
|
cancelIntent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
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
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
Utils.debugLog(TAG, "Destroying downloader service. Will move to background and stop our Looper.");
|
Utils.debugLog(TAG, "Destroying downloader service. Will move to background and stop our Looper.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user