Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.rollback; |
| 18 | |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.NonNull; |
Richard Uhler | cca637a | 2019-02-27 11:50:48 +0000 | [diff] [blame] | 21 | import android.content.rollback.RollbackInfo; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 22 | |
| 23 | import java.io.File; |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 24 | import java.lang.annotation.Retention; |
| 25 | import java.lang.annotation.RetentionPolicy; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 26 | import java.time.Instant; |
Richard Uhler | 01b0615 | 2019-01-09 13:51:54 +0000 | [diff] [blame] | 27 | import java.util.ArrayList; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 28 | |
| 29 | /** |
Richard Uhler | 01b0615 | 2019-01-09 13:51:54 +0000 | [diff] [blame] | 30 | * Information about a rollback available for a set of atomically installed |
| 31 | * packages. |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 32 | */ |
Richard Uhler | 32f63a7 | 2019-01-09 10:43:52 +0000 | [diff] [blame] | 33 | class RollbackData { |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 34 | @IntDef(flag = true, prefix = { "ROLLBACK_STATE_" }, value = { |
Richard Uhler | e9aaf63 | 2019-03-01 16:03:01 +0000 | [diff] [blame] | 35 | ROLLBACK_STATE_ENABLING, |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 36 | ROLLBACK_STATE_AVAILABLE, |
| 37 | ROLLBACK_STATE_COMMITTED, |
| 38 | }) |
| 39 | @Retention(RetentionPolicy.SOURCE) |
| 40 | @interface RollbackState {} |
| 41 | |
| 42 | /** |
Richard Uhler | e9aaf63 | 2019-03-01 16:03:01 +0000 | [diff] [blame] | 43 | * The rollback is in the process of being enabled. It is not yet |
| 44 | * available for use. |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 45 | */ |
Richard Uhler | e9aaf63 | 2019-03-01 16:03:01 +0000 | [diff] [blame] | 46 | static final int ROLLBACK_STATE_ENABLING = 0; |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * The rollback is currently available. |
| 50 | */ |
| 51 | static final int ROLLBACK_STATE_AVAILABLE = 1; |
| 52 | |
| 53 | /** |
| 54 | * The rollback has been committed. |
| 55 | */ |
| 56 | static final int ROLLBACK_STATE_COMMITTED = 3; |
| 57 | |
Richard Uhler | 01b0615 | 2019-01-09 13:51:54 +0000 | [diff] [blame] | 58 | /** |
Richard Uhler | cca637a | 2019-02-27 11:50:48 +0000 | [diff] [blame] | 59 | * The rollback info for this rollback. |
Richard Uhler | b9d5447 | 2019-01-22 12:50:08 +0000 | [diff] [blame] | 60 | */ |
Richard Uhler | cca637a | 2019-02-27 11:50:48 +0000 | [diff] [blame] | 61 | public final RollbackInfo info; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 62 | |
| 63 | /** |
Richard Uhler | c0e5742 | 2019-01-09 11:25:56 +0000 | [diff] [blame] | 64 | * The directory where the rollback data is stored. |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 65 | */ |
| 66 | public final File backupDir; |
| 67 | |
| 68 | /** |
| 69 | * The time when the upgrade occurred, for purposes of expiring |
| 70 | * rollback data. |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 71 | * |
| 72 | * The timestamp is not applicable for all rollback states, but we make |
| 73 | * sure to keep it non-null to avoid potential errors there. |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 74 | */ |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 75 | public @NonNull Instant timestamp; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 76 | |
Narayan Kamath | bc36f8d | 2019-01-23 12:00:08 +0000 | [diff] [blame] | 77 | /** |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 78 | * The session ID for the staged session if this rollback data represents a staged session, |
| 79 | * {@code -1} otherwise. |
| 80 | */ |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 81 | public final int stagedSessionId; |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 82 | |
| 83 | /** |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 84 | * The current state of the rollback. |
Richard Uhler | e9aaf63 | 2019-03-01 16:03:01 +0000 | [diff] [blame] | 85 | * ENABLING, AVAILABLE, or COMMITTED. |
Richard Uhler | 60ac706 | 2019-02-05 13:25:39 +0000 | [diff] [blame] | 86 | */ |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 87 | public @RollbackState int state; |
Richard Uhler | 60ac706 | 2019-02-05 13:25:39 +0000 | [diff] [blame] | 88 | |
| 89 | /** |
Richard Uhler | ba13ab2 | 2019-02-05 15:27:12 +0000 | [diff] [blame] | 90 | * The id of the post-reboot apk session for a staged install, if any. |
| 91 | */ |
| 92 | public int apkSessionId = -1; |
| 93 | |
| 94 | /** |
Richard Uhler | 479a296 | 2019-02-27 10:59:10 +0000 | [diff] [blame] | 95 | * True if we are expecting the package manager to call restoreUserData |
| 96 | * for this rollback because it has just been committed but the rollback |
| 97 | * has not yet been fully applied. |
Narayan Kamath | bc36f8d | 2019-01-23 12:00:08 +0000 | [diff] [blame] | 98 | */ |
| 99 | // NOTE: All accesses to this field are from the RollbackManager handler thread. |
Richard Uhler | 479a296 | 2019-02-27 10:59:10 +0000 | [diff] [blame] | 100 | public boolean restoreUserDataInProgress = false; |
Narayan Kamath | bc36f8d | 2019-01-23 12:00:08 +0000 | [diff] [blame] | 101 | |
Richard Uhler | cca637a | 2019-02-27 11:50:48 +0000 | [diff] [blame] | 102 | /** |
| 103 | * Constructs a new, empty RollbackData instance. |
| 104 | * |
| 105 | * @param rollbackId the id of the rollback. |
| 106 | * @param backupDir the directory where the rollback data is stored. |
| 107 | * @param stagedSessionId the session id if this is a staged rollback, -1 otherwise. |
| 108 | */ |
| 109 | RollbackData(int rollbackId, File backupDir, int stagedSessionId) { |
| 110 | this.info = new RollbackInfo(rollbackId, |
| 111 | /* packages */ new ArrayList<>(), |
| 112 | /* isStaged */ stagedSessionId != -1, |
| 113 | /* causePackages */ new ArrayList<>(), |
| 114 | /* committedSessionId */ -1); |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 115 | this.backupDir = backupDir; |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 116 | this.stagedSessionId = stagedSessionId; |
Richard Uhler | e9aaf63 | 2019-03-01 16:03:01 +0000 | [diff] [blame] | 117 | this.state = ROLLBACK_STATE_ENABLING; |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 118 | this.timestamp = Instant.now(); |
Richard Uhler | cca637a | 2019-02-27 11:50:48 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Constructs a RollbackData instance with full rollback data information. |
| 123 | */ |
| 124 | RollbackData(RollbackInfo info, File backupDir, Instant timestamp, int stagedSessionId, |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 125 | @RollbackState int state, int apkSessionId, boolean restoreUserDataInProgress) { |
Richard Uhler | cca637a | 2019-02-27 11:50:48 +0000 | [diff] [blame] | 126 | this.info = info; |
| 127 | this.backupDir = backupDir; |
| 128 | this.timestamp = timestamp; |
| 129 | this.stagedSessionId = stagedSessionId; |
Richard Uhler | 6f8a33b | 2019-02-26 10:40:36 +0000 | [diff] [blame] | 130 | this.state = state; |
Richard Uhler | cca637a | 2019-02-27 11:50:48 +0000 | [diff] [blame] | 131 | this.apkSessionId = apkSessionId; |
| 132 | this.restoreUserDataInProgress = restoreUserDataInProgress; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 133 | } |
Richard Uhler | 72fb961 | 2019-02-04 14:37:36 +0000 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * Whether the rollback is for rollback of a staged install. |
| 137 | */ |
| 138 | public boolean isStaged() { |
Richard Uhler | cca637a | 2019-02-27 11:50:48 +0000 | [diff] [blame] | 139 | return info.isStaged(); |
Richard Uhler | 72fb961 | 2019-02-04 14:37:36 +0000 | [diff] [blame] | 140 | } |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 141 | } |