Use provider helper methods instead of manually invoking.
The fact that Cursors are used with the apk provider is more of an implementation detail (to some extent). It is a crappy, leaky implementation right now, but still an implementation detail.
This commit is contained in:
parent
28b7d69e60
commit
0409a7dcd6
@ -27,7 +27,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -478,42 +477,24 @@ public class UpdateService extends IntentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void performUpdateNotification() {
|
private void performUpdateNotification() {
|
||||||
Cursor cursor = getContentResolver().query(
|
List<App> canUpdate = AppProvider.Helper.findCanUpdate(this, Schema.AppMetadataTable.Cols.ALL);
|
||||||
AppProvider.getCanUpdateUri(),
|
if (canUpdate.size() > 0) {
|
||||||
Schema.AppMetadataTable.Cols.ALL,
|
showAppUpdatesNotification(canUpdate);
|
||||||
null, null, null);
|
|
||||||
if (cursor != null) {
|
|
||||||
if (cursor.getCount() > 0) {
|
|
||||||
showAppUpdatesNotification(cursor);
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void autoDownloadUpdates(Context context) {
|
public static void autoDownloadUpdates(Context context) {
|
||||||
Cursor cursor = context.getContentResolver().query(
|
List<App> canUpdate = AppProvider.Helper.findCanUpdate(context, Schema.AppMetadataTable.Cols.ALL);
|
||||||
AppProvider.getCanUpdateUri(),
|
for (App app : canUpdate) {
|
||||||
Schema.AppMetadataTable.Cols.ALL,
|
Apk apk = ApkProvider.Helper.findSuggestedApk(context, app);
|
||||||
null, null, null);
|
InstallManagerService.queue(context, app, apk);
|
||||||
if (cursor != null) {
|
|
||||||
cursor.moveToFirst();
|
|
||||||
for (int i = 0; i < cursor.getCount(); i++) {
|
|
||||||
App app = new App(cursor);
|
|
||||||
Apk apk = ApkProvider.Helper.findSuggestedApk(context, app);
|
|
||||||
InstallManagerService.queue(context, app, apk);
|
|
||||||
cursor.moveToNext();
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAppUpdatesNotification(Cursor hasUpdates) {
|
private void showAppUpdatesNotification(List<App> canUpdate) {
|
||||||
if (hasUpdates != null) {
|
if (canUpdate.size() > 0) {
|
||||||
hasUpdates.moveToFirst();
|
List<Apk> apksToUpdate = new ArrayList<>(canUpdate.size());
|
||||||
List<Apk> apksToUpdate = new ArrayList<>(hasUpdates.getCount());
|
for (App app : canUpdate) {
|
||||||
for (int i = 0; i < hasUpdates.getCount(); i++) {
|
|
||||||
App app = new App(hasUpdates);
|
|
||||||
hasUpdates.moveToNext();
|
|
||||||
apksToUpdate.add(ApkProvider.Helper.findSuggestedApk(this, app));
|
apksToUpdate.add(ApkProvider.Helper.findSuggestedApk(this, app));
|
||||||
}
|
}
|
||||||
appUpdateStatusManager.addApks(apksToUpdate, AppUpdateStatusManager.Status.UpdateAvailable);
|
appUpdateStatusManager.addApks(apksToUpdate, AppUpdateStatusManager.Status.UpdateAvailable);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user