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

Commit d42788a9 authored by Adam Metcalf's avatar Adam Metcalf
Browse files

Add RollbackImpactLevel options to PackageManagerShellCommand.

```
42813537:
  -state: available
  -stateDescription:
  -timestamp: 2024-03-26T22:31:09.417925Z
  -rollbackLifetimeMillis: 0
  -rollbackUserImpact: 1
  -isStaged: false
  -originalSessionId: 1081878435
  -packages:
    com.google.android.gmscore.companion 26010 -> 26010 [2]
  -extensionVersions:
    {30=12, 31=12, 33=12, 34=12, 1000000=12}
```

Bug: 291137901
Change-Id: Ia5e0e3a2aba1ab179e05ac064603b3d38bf7d07d
Test: lunch aosp_cf_x86_64_only_phone-trunk_staging-eng && m && acloud create --local-image && adb install --enable-rollback 2 --rollback-impact-level 1 companion.apk
parent f5a43e55
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import static android.content.pm.PackageManager.RESTRICTION_HIDE_NOTIFICATIONS;
import static android.content.pm.PackageManager.RESTRICTION_NONE;

import static com.android.server.LocalManagerRegistry.ManagerNotFoundException;
import static com.android.server.pm.PackageManagerService.DEFAULT_FILE_ACCESS_MODE;

import android.accounts.IAccountManager;
import android.annotation.NonNull;
@@ -45,6 +44,7 @@ import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
import android.content.pm.ArchivedPackageParcel;
import android.content.pm.FeatureInfo;
import android.content.pm.Flags;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageInstaller;
import android.content.pm.IPackageManager;
@@ -3387,6 +3387,18 @@ class PackageManagerShellCommand extends ShellCommand {
                    }
                    sessionParams.setEnableRollback(true, rollbackStrategy);
                    break;
                case "--rollback-impact-level":
                    if (!Flags.recoverabilityDetection()) {
                        throw new IllegalArgumentException("Unknown option " + opt);
                    }
                    int rollbackImpactLevel = Integer.parseInt(peekNextArg());
                    if (rollbackImpactLevel < PackageManager.ROLLBACK_USER_IMPACT_LOW
                            || rollbackImpactLevel
                                    > PackageManager.ROLLBACK_USER_IMPACT_ONLY_MANUAL) {
                        throw new IllegalArgumentException(
                            rollbackImpactLevel + " is not a valid rollback impact level.");
                    }
                    sessionParams.setRollbackImpactLevel(rollbackImpactLevel);
                case "--staged-ready-timeout":
                    params.stagedReadyTimeoutMs = Long.parseLong(getNextArgRequired());
                    break;
@@ -4546,6 +4558,11 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("      --full: cause the app to be installed as a non-ephemeral full app");
        pw.println("      --enable-rollback: enable rollbacks for the upgrade.");
        pw.println("          0=restore (default), 1=wipe, 2=retain");
        if (Flags.recoverabilityDetection()) {
            pw.println(
                    "      --rollback-impact-level: set device impact required for rollback.");
            pw.println("          0=low (default), 1=high, 2=manual only");
        }
        pw.println("      --install-location: force the install location:");
        pw.println("          0=auto, 1=internal only, 2=prefer external");
        pw.println("      --install-reason: indicates why the app is being installed:");
+13 −0
Original line number Diff line number Diff line
@@ -203,6 +203,15 @@ a different `RollbackDataPolicy`, like `ROLLBACK_DATA_POLICY_RETAIN` (1) or
$ adb install --enable-rollback 1 FooV2.apk
```

### Setting Rollback Impact Level

The `adb install` command accepts the `--rollback-impact-level [0/1/2]` flag to control
when a rollback can be performed by `PackageWatchdog`.

The default rollback impact level is `ROLLBACK_USER_IMPACT_LOW` (0). To use a
different impact level, use `ROLLBACK_USER_IMPACT_HIGH` (1) or `ROLLBACK_USER_IMPACT_ONLY_MANUAL`
(2).

### Triggering Rollback Manually

If rollback is available for an application, the pm command can be used to
@@ -225,6 +234,8 @@ $ adb shell dumpsys rollback
469808841:
  -state: committed
  -timestamp: 2019-04-23T14:57:35.944Z
  -rollbackLifetimeMillis: 0
  -rollbackUserImpact: 1
  -packages:
    com.android.tests.rollback.testapp.B 2 -> 1 [0]
  -causePackages:
@@ -232,6 +243,8 @@ $ adb shell dumpsys rollback
649899517:
  -state: committed
  -timestamp: 2019-04-23T12:55:21.342Z
  -rollbackLifetimeMillis: 0
  -rollbackUserImpact: 0
  -stagedSessionId: 343374391
  -packages:
    com.android.tests.rollback.testapex 2 -> 1 [0]
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.annotation.WorkerThread;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.Flags;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
@@ -960,6 +961,9 @@ class Rollback {
        ipw.println("-stateDescription: " + mStateDescription);
        ipw.println("-timestamp: " + getTimestamp());
        ipw.println("-rollbackLifetimeMillis: " + getRollbackLifetimeMillis());
        if (Flags.recoverabilityDetection()) {
            ipw.println("-rollbackImpactLevel: " + info.getRollbackImpactLevel());
        }
        ipw.println("-isStaged: " + isStaged());
        ipw.println("-originalSessionId: " + getOriginalSessionId());
        ipw.println("-packages:");