Loading app/src/main/java/org/lineageos/updater/UpdateImporter.java +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class UpdateImporter { private static final int REQUEST_PICK = 9061; private static final String TAG = "UpdateImporter"; private static final String MIME_ZIP = "application/zip"; private static final String FILE_NAME = "localUpdate.zip"; public static final String FILE_NAME = "localUpdate.zip"; private static final String METADATA_PATH = "META-INF/com/android/metadata"; private static final String METADATA_TIMESTAMP_KEY = "post-timestamp="; private static final String METADATA_ANDROID_SDK_KEY = "post-sdk-level="; Loading app/src/main/java/org/lineageos/updater/UpdatesActivity.java +9 −1 Original line number Diff line number Diff line Loading @@ -121,6 +121,10 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport super.onCreate(savedInstanceState); setContentView(R.layout.activity_updates); if (UpdaterService.isDeviceRebooted()) { Utils.removeInstalledUpdate(this); } mUpdateImporter = new UpdateImporter(this, this); UiModeManager uiModeManager = getSystemService(UiModeManager.class); Loading Loading @@ -395,9 +399,11 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport if (sortedUpdates.isEmpty()) { findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); findViewById(R.id.content).setVisibility(View.GONE); findViewById(R.id.available_update_header).setVisibility(View.GONE); } else { findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); findViewById(R.id.content).setVisibility(View.VISIBLE); findViewById(R.id.available_update_header).setVisibility(View.VISIBLE); sortedUpdates.sort((u1, u2) -> Long.compare(u2.getTimestamp(), u1.getTimestamp())); for (UpdateInfo update : sortedUpdates) { updateIds.add(update.getDownloadId()); Loading Loading @@ -558,6 +564,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport } } else { findViewById(R.id.content).setVisibility(View.GONE); findViewById(R.id.available_update_header).setVisibility(View.GONE); findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); findViewById(R.id.refresh_progress).setVisibility(View.VISIBLE); } Loading @@ -575,6 +582,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport if (mAdapter.getItemCount() > 0) { findViewById(R.id.content).setVisibility(View.VISIBLE); findViewById(R.id.available_update_header).setVisibility(View.VISIBLE); } else { findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); } Loading app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java +1 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { } Utils.cleanupDownloadsDir(context); Utils.removeLocalUpdate(context); // Reset resume or update check failed on reboot editor.putBoolean(Constants.AUTO_UPDATE_CHECK_FAILED, false).apply(); Loading app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +9 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,8 @@ public class UpdaterService extends Service { private static ConnectivityManager.NetworkCallback mConnectionStateMonitor; private static ConnectivityManager mConnectivityManager; private static boolean mDeviceRebooted = true; @Override public void onCreate() { super.onCreate(); Loading Loading @@ -267,6 +269,10 @@ public class UpdaterService extends Service { return mUpdaterController; } public static boolean isDeviceRebooted() { return mDeviceRebooted; } private void tryStopSelf() { if (isNetworkCallBackActive || areNotificationsActive()) return; if (!mHasClients && !mUpdaterController.hasActiveDownloads() && Loading @@ -286,6 +292,8 @@ public class UpdaterService extends Service { private void handleUpdateStatusChange(UpdateInfo update) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = pref.edit(); mNotificationBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); mDeviceRebooted = false; switch (update.getStatus()) { case DELETED: { notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); Loading Loading @@ -495,6 +503,7 @@ public class UpdaterService extends Service { mNotificationBuilder.setTicker(text); mNotificationBuilder.setOngoing(true); mNotificationBuilder.setAutoCancel(false); mNotificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX); mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true); Loading app/src/main/java/org/lineageos/updater/misc/Utils.java +14 −3 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.lineageos.updater.R; import org.lineageos.updater.UpdateImporter; import org.lineageos.updater.UpdatesDbHelper; import org.lineageos.updater.controller.UpdaterController; import org.lineageos.updater.controller.UpdaterService; Loading Loading @@ -426,6 +427,14 @@ public class Utils { } } public static void removeLocalUpdate(Context context) { File downloadPath = getDownloadPath(context); File localUpdate = new File(downloadPath, UpdateImporter.FILE_NAME); if (localUpdate.exists()) { Log.d(TAG, "Deleting local update: " + localUpdate.delete()); } } /** * Cleanup the download directory, which is assumed to be a privileged location * the user can't access and that might have stale files. This can happen if Loading Loading @@ -488,9 +497,11 @@ public class Utils { public static void removeInstalledUpdate(Context context) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); String downloadId = pref.getString(Constants.PREF_NEEDS_DELETE_ID, null); if (downloadId != null) { UpdaterController controller = UpdaterController.getInstance(context); if (controller != null && downloadId != null) { if (controller != null) { controller.deleteUpdate(downloadId); } pref.edit().remove(Constants.PREF_NEEDS_DELETE_ID).apply(); } } Loading Loading
app/src/main/java/org/lineageos/updater/UpdateImporter.java +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class UpdateImporter { private static final int REQUEST_PICK = 9061; private static final String TAG = "UpdateImporter"; private static final String MIME_ZIP = "application/zip"; private static final String FILE_NAME = "localUpdate.zip"; public static final String FILE_NAME = "localUpdate.zip"; private static final String METADATA_PATH = "META-INF/com/android/metadata"; private static final String METADATA_TIMESTAMP_KEY = "post-timestamp="; private static final String METADATA_ANDROID_SDK_KEY = "post-sdk-level="; Loading
app/src/main/java/org/lineageos/updater/UpdatesActivity.java +9 −1 Original line number Diff line number Diff line Loading @@ -121,6 +121,10 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport super.onCreate(savedInstanceState); setContentView(R.layout.activity_updates); if (UpdaterService.isDeviceRebooted()) { Utils.removeInstalledUpdate(this); } mUpdateImporter = new UpdateImporter(this, this); UiModeManager uiModeManager = getSystemService(UiModeManager.class); Loading Loading @@ -395,9 +399,11 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport if (sortedUpdates.isEmpty()) { findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); findViewById(R.id.content).setVisibility(View.GONE); findViewById(R.id.available_update_header).setVisibility(View.GONE); } else { findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); findViewById(R.id.content).setVisibility(View.VISIBLE); findViewById(R.id.available_update_header).setVisibility(View.VISIBLE); sortedUpdates.sort((u1, u2) -> Long.compare(u2.getTimestamp(), u1.getTimestamp())); for (UpdateInfo update : sortedUpdates) { updateIds.add(update.getDownloadId()); Loading Loading @@ -558,6 +564,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport } } else { findViewById(R.id.content).setVisibility(View.GONE); findViewById(R.id.available_update_header).setVisibility(View.GONE); findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); findViewById(R.id.refresh_progress).setVisibility(View.VISIBLE); } Loading @@ -575,6 +582,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport if (mAdapter.getItemCount() > 0) { findViewById(R.id.content).setVisibility(View.VISIBLE); findViewById(R.id.available_update_header).setVisibility(View.VISIBLE); } else { findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); } Loading
app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java +1 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { } Utils.cleanupDownloadsDir(context); Utils.removeLocalUpdate(context); // Reset resume or update check failed on reboot editor.putBoolean(Constants.AUTO_UPDATE_CHECK_FAILED, false).apply(); Loading
app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +9 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,8 @@ public class UpdaterService extends Service { private static ConnectivityManager.NetworkCallback mConnectionStateMonitor; private static ConnectivityManager mConnectivityManager; private static boolean mDeviceRebooted = true; @Override public void onCreate() { super.onCreate(); Loading Loading @@ -267,6 +269,10 @@ public class UpdaterService extends Service { return mUpdaterController; } public static boolean isDeviceRebooted() { return mDeviceRebooted; } private void tryStopSelf() { if (isNetworkCallBackActive || areNotificationsActive()) return; if (!mHasClients && !mUpdaterController.hasActiveDownloads() && Loading @@ -286,6 +292,8 @@ public class UpdaterService extends Service { private void handleUpdateStatusChange(UpdateInfo update) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = pref.edit(); mNotificationBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); mDeviceRebooted = false; switch (update.getStatus()) { case DELETED: { notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); Loading Loading @@ -495,6 +503,7 @@ public class UpdaterService extends Service { mNotificationBuilder.setTicker(text); mNotificationBuilder.setOngoing(true); mNotificationBuilder.setAutoCancel(false); mNotificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX); mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true); Loading
app/src/main/java/org/lineageos/updater/misc/Utils.java +14 −3 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.lineageos.updater.R; import org.lineageos.updater.UpdateImporter; import org.lineageos.updater.UpdatesDbHelper; import org.lineageos.updater.controller.UpdaterController; import org.lineageos.updater.controller.UpdaterService; Loading Loading @@ -426,6 +427,14 @@ public class Utils { } } public static void removeLocalUpdate(Context context) { File downloadPath = getDownloadPath(context); File localUpdate = new File(downloadPath, UpdateImporter.FILE_NAME); if (localUpdate.exists()) { Log.d(TAG, "Deleting local update: " + localUpdate.delete()); } } /** * Cleanup the download directory, which is assumed to be a privileged location * the user can't access and that might have stale files. This can happen if Loading Loading @@ -488,9 +497,11 @@ public class Utils { public static void removeInstalledUpdate(Context context) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); String downloadId = pref.getString(Constants.PREF_NEEDS_DELETE_ID, null); if (downloadId != null) { UpdaterController controller = UpdaterController.getInstance(context); if (controller != null && downloadId != null) { if (controller != null) { controller.deleteUpdate(downloadId); } pref.edit().remove(Constants.PREF_NEEDS_DELETE_ID).apply(); } } Loading