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 | |
| 19 | import android.content.rollback.PackageRollbackInfo; |
| 20 | |
| 21 | import java.io.File; |
| 22 | import java.time.Instant; |
Richard Uhler | 01b0615 | 2019-01-09 13:51:54 +0000 | [diff] [blame] | 23 | import java.util.ArrayList; |
| 24 | import java.util.List; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 25 | |
| 26 | /** |
Richard Uhler | 01b0615 | 2019-01-09 13:51:54 +0000 | [diff] [blame] | 27 | * Information about a rollback available for a set of atomically installed |
| 28 | * packages. |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 29 | */ |
Richard Uhler | 32f63a7 | 2019-01-09 10:43:52 +0000 | [diff] [blame] | 30 | class RollbackData { |
Richard Uhler | 01b0615 | 2019-01-09 13:51:54 +0000 | [diff] [blame] | 31 | /** |
Richard Uhler | b9d5447 | 2019-01-22 12:50:08 +0000 | [diff] [blame] | 32 | * A unique identifier for this rollback. |
| 33 | */ |
| 34 | public final int rollbackId; |
| 35 | |
| 36 | /** |
Richard Uhler | 01b0615 | 2019-01-09 13:51:54 +0000 | [diff] [blame] | 37 | * The per-package rollback information. |
| 38 | */ |
| 39 | public final List<PackageRollbackInfo> packages = new ArrayList<>(); |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 40 | |
| 41 | /** |
Richard Uhler | c0e5742 | 2019-01-09 11:25:56 +0000 | [diff] [blame] | 42 | * The directory where the rollback data is stored. |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 43 | */ |
| 44 | public final File backupDir; |
| 45 | |
| 46 | /** |
| 47 | * The time when the upgrade occurred, for purposes of expiring |
| 48 | * rollback data. |
| 49 | */ |
Richard Uhler | 2d7c7f0d | 2019-01-04 09:18:21 +0000 | [diff] [blame] | 50 | public Instant timestamp; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 51 | |
Narayan Kamath | bc36f8d | 2019-01-23 12:00:08 +0000 | [diff] [blame] | 52 | /** |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 53 | * The session ID for the staged session if this rollback data represents a staged session, |
| 54 | * {@code -1} otherwise. |
| 55 | */ |
| 56 | public int stagedSessionId; |
| 57 | |
| 58 | /** |
Richard Uhler | 60ac706 | 2019-02-05 13:25:39 +0000 | [diff] [blame] | 59 | * A flag to indicate whether the rollback should be considered available |
| 60 | * for use. This will always be true for rollbacks of non-staged sessions. |
| 61 | * For rollbacks of staged sessions, this is not set to true until after |
| 62 | * the staged session has been applied. |
| 63 | */ |
| 64 | public boolean isAvailable; |
| 65 | |
| 66 | /** |
Richard Uhler | ba13ab2 | 2019-02-05 15:27:12 +0000 | [diff] [blame^] | 67 | * The id of the post-reboot apk session for a staged install, if any. |
| 68 | */ |
| 69 | public int apkSessionId = -1; |
| 70 | |
| 71 | /** |
Narayan Kamath | bc36f8d | 2019-01-23 12:00:08 +0000 | [diff] [blame] | 72 | * Whether this Rollback is currently in progress. This field is true from the point |
| 73 | * we commit a {@code PackageInstaller} session containing these packages to the point the |
| 74 | * {@code PackageInstaller} calls into the {@code onFinished} callback. |
| 75 | */ |
| 76 | // NOTE: All accesses to this field are from the RollbackManager handler thread. |
| 77 | public boolean inProgress = false; |
| 78 | |
Richard Uhler | 60ac706 | 2019-02-05 13:25:39 +0000 | [diff] [blame] | 79 | RollbackData(int rollbackId, File backupDir, int stagedSessionId, boolean isAvailable) { |
Richard Uhler | b9d5447 | 2019-01-22 12:50:08 +0000 | [diff] [blame] | 80 | this.rollbackId = rollbackId; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 81 | this.backupDir = backupDir; |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 82 | this.stagedSessionId = stagedSessionId; |
Richard Uhler | 60ac706 | 2019-02-05 13:25:39 +0000 | [diff] [blame] | 83 | this.isAvailable = isAvailable; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 84 | } |
Richard Uhler | 72fb961 | 2019-02-04 14:37:36 +0000 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Whether the rollback is for rollback of a staged install. |
| 88 | */ |
| 89 | public boolean isStaged() { |
| 90 | return stagedSessionId != -1; |
| 91 | } |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 92 | } |