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

Commit ba13ab29 authored by Richard Uhler's avatar Richard Uhler
Browse files

Track the apkSessionId associated with a staged install.

Because the apk session will need special handling when enabling
rollback for it.

Bug: 112431924
Test: atest RollbackTest
Change-Id: Id95e9dd69495be0640610c1a80ac0cf5a6c14256
parent 6fa7d13e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -63,6 +63,11 @@ class RollbackData {
     */
    public boolean isAvailable;

    /**
     * The id of the post-reboot apk session for a staged install, if any.
     */
    public int apkSessionId = -1;

    /**
     * Whether this Rollback is currently in progress. This field is true from the point
     * we commit a {@code PackageInstaller} session containing these packages to the point the
+22 −1
Original line number Diff line number Diff line
@@ -930,7 +930,28 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {

    @Override
    public void notifyStagedApkSession(int originalSessionId, int apkSessionId) {
        // TODO: Handle this callback.
        getHandler().post(() -> {
            RollbackData rd = null;
            synchronized (mLock) {
                ensureRollbackDataLoadedLocked();
                for (int i = 0; i < mAvailableRollbacks.size(); ++i) {
                    RollbackData data = mAvailableRollbacks.get(i);
                    if (data.stagedSessionId == originalSessionId) {
                        data.apkSessionId = apkSessionId;
                        rd = data;
                        break;
                    }
                }
            }

            if (rd != null) {
                try {
                    mRollbackStore.saveAvailableRollback(rd);
                } catch (IOException ioe) {
                    Log.e(TAG, "Unable to save rollback info for : " + rd.rollbackId, ioe);
                }
            }
        });
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -248,6 +248,7 @@ class RollbackStore {
            dataJson.put("timestamp", data.timestamp.toString());
            dataJson.put("stagedSessionId", data.stagedSessionId);
            dataJson.put("isAvailable", data.isAvailable);
            dataJson.put("apkSessionId", data.apkSessionId);

            PrintWriter pw = new PrintWriter(new File(data.backupDir, "rollback.json"));
            pw.println(dataJson.toString());
@@ -313,6 +314,7 @@ class RollbackStore {
                    stagedSessionId, isAvailable);
            data.packages.addAll(packageRollbackInfosFromJson(dataJson.getJSONArray("packages")));
            data.timestamp = Instant.parse(dataJson.getString("timestamp"));
            data.apkSessionId = dataJson.getInt("apkSessionId");
            return data;
        } catch (JSONException | DateTimeParseException e) {
            throw new IOException(e);