Extract "remove apk" code to simplify setApkInternal().
The only time `status == null` was when coming from `removeApk()`. By moving the logic out of `setApkInternal()` into `removeApk()` it makes it easier to reason about `setApkInternal()` as it now does less. Also, it was doubling up on the `syncrhonized (appMapping)` and `if (entry != null)` logic which is no longer required, because `removeApk()` was already doing that. While here, also make explicit the fact that `status` can no longer be `null`.
This commit is contained in:
parent
30d3f8efcc
commit
d00de69974
@ -6,6 +6,7 @@ import android.content.ContentResolver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
@ -108,21 +109,14 @@ public class AppUpdateStatusManager {
|
|||||||
return returnValues;
|
return returnValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setApkInternal(Apk apk, Status status, PendingIntent intent) {
|
private void setApkInternal(Apk apk, @NonNull Status status, PendingIntent intent) {
|
||||||
if (apk == null) {
|
if (apk == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (appMapping) {
|
synchronized (appMapping) {
|
||||||
AppUpdateStatus entry = appMapping.get(apk.getUrl());
|
AppUpdateStatus entry = appMapping.get(apk.getUrl());
|
||||||
if (status == null) {
|
if (entry != null) {
|
||||||
// Remove
|
|
||||||
Utils.debugLog(LOGTAG, "Remove APK " + apk.apkName);
|
|
||||||
if (entry != null) {
|
|
||||||
appMapping.remove(apk.getUrl());
|
|
||||||
notifyRemove(entry);
|
|
||||||
}
|
|
||||||
} else if (entry != null) {
|
|
||||||
// Update
|
// Update
|
||||||
Utils.debugLog(LOGTAG, "Update APK " + apk.apkName + " state to " + status.name());
|
Utils.debugLog(LOGTAG, "Update APK " + apk.apkName + " state to " + status.name());
|
||||||
boolean isStatusUpdate = (entry.status != status);
|
boolean isStatusUpdate = (entry.status != status);
|
||||||
@ -203,11 +197,11 @@ public class AppUpdateStatusManager {
|
|||||||
* @param status The current status of the app
|
* @param status The current status of the app
|
||||||
* @param pendingIntent Action when notification is clicked. Can be null for default action(s)
|
* @param pendingIntent Action when notification is clicked. Can be null for default action(s)
|
||||||
*/
|
*/
|
||||||
public void addApk(Apk apk, Status status, PendingIntent pendingIntent) {
|
public void addApk(Apk apk, @NonNull Status status, PendingIntent pendingIntent) {
|
||||||
setApkInternal(apk, status, pendingIntent);
|
setApkInternal(apk, status, pendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateApk(String key, Status status, PendingIntent pendingIntent) {
|
public void updateApk(String key, @NonNull Status status, PendingIntent pendingIntent) {
|
||||||
synchronized (appMapping) {
|
synchronized (appMapping) {
|
||||||
AppUpdateStatus entry = appMapping.get(key);
|
AppUpdateStatus entry = appMapping.get(key);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
@ -231,7 +225,9 @@ public class AppUpdateStatusManager {
|
|||||||
synchronized (appMapping) {
|
synchronized (appMapping) {
|
||||||
AppUpdateStatus entry = appMapping.get(key);
|
AppUpdateStatus entry = appMapping.get(key);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
setApkInternal(entry.apk, null, null); // remove
|
Utils.debugLog(LOGTAG, "Remove APK " + entry.apk.apkName);
|
||||||
|
appMapping.remove(entry.apk.getUrl());
|
||||||
|
notifyRemove(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user