Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 198cb3aa authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch '2502-u-updater_package' into 'v1-u'

Fix updater issues

See merge request !196
parents 6691538c 95024927
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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=";
+9 −1
Original line number Diff line number Diff line
@@ -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);
@@ -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());
@@ -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);
        }
@@ -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);
        }
+1 −0
Original line number Diff line number Diff line
@@ -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();
+9 −0
Original line number Diff line number Diff line
@@ -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();
@@ -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() &&
@@ -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);
@@ -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);
+14 −3
Original line number Diff line number Diff line
@@ -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;
@@ -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
@@ -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