Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 19 | import static org.junit.Assert.assertEquals; |
| 20 | import static org.junit.Assert.assertFalse; |
| 21 | import static org.junit.Assert.assertNull; |
| 22 | import static org.junit.Assert.assertTrue; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 23 | import static org.mockito.ArgumentMatchers.eq; |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 24 | import static org.mockito.Matchers.anyInt; |
| 25 | import static org.mockito.Matchers.anyString; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 26 | import static org.mockito.Mockito.doReturn; |
| 27 | import static org.mockito.Mockito.mock; |
| 28 | import static org.mockito.Mockito.spy; |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 29 | import static org.mockito.Mockito.when; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 30 | |
| 31 | import android.content.pm.VersionedPackage; |
| 32 | import android.content.rollback.PackageRollbackInfo; |
| 33 | import android.content.rollback.PackageRollbackInfo.RestoreInfo; |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 34 | import android.content.rollback.RollbackInfo; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 35 | import android.util.IntArray; |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 36 | import android.util.SparseLongArray; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 37 | |
| 38 | import com.android.server.pm.Installer; |
| 39 | |
| 40 | import org.junit.Test; |
| 41 | import org.junit.runner.RunWith; |
| 42 | import org.junit.runners.JUnit4; |
| 43 | import org.mockito.InOrder; |
| 44 | import org.mockito.Mockito; |
| 45 | |
| 46 | import java.io.File; |
| 47 | import java.util.ArrayList; |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 48 | import java.util.Arrays; |
| 49 | import java.util.Collections; |
| 50 | import java.util.List; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 51 | |
| 52 | @RunWith(JUnit4.class) |
| 53 | public class AppDataRollbackHelperTest { |
| 54 | |
| 55 | @Test |
| 56 | public void testSnapshotAppData() throws Exception { |
| 57 | Installer installer = mock(Installer.class); |
| 58 | AppDataRollbackHelper helper = spy(new AppDataRollbackHelper(installer)); |
| 59 | |
| 60 | // All users are unlocked so we should snapshot data for them. |
| 61 | doReturn(true).when(helper).isUserCredentialLocked(eq(10)); |
| 62 | doReturn(true).when(helper).isUserCredentialLocked(eq(11)); |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 63 | PackageRollbackInfo info = createPackageRollbackInfo("com.foo.bar", new int[]{10, 11}); |
| 64 | helper.snapshotAppData(5, info); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 65 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 66 | assertEquals(2, info.getPendingBackups().size()); |
| 67 | assertEquals(10, info.getPendingBackups().get(0)); |
| 68 | assertEquals(11, info.getPendingBackups().get(1)); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 69 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 70 | assertEquals(0, info.getCeSnapshotInodes().size()); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 71 | |
| 72 | InOrder inOrder = Mockito.inOrder(installer); |
| 73 | inOrder.verify(installer).snapshotAppData( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 74 | eq("com.foo.bar"), eq(10), eq(5), eq(Installer.FLAG_STORAGE_DE)); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 75 | inOrder.verify(installer).snapshotAppData( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 76 | eq("com.foo.bar"), eq(11), eq(5), eq(Installer.FLAG_STORAGE_DE)); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 77 | inOrder.verifyNoMoreInteractions(); |
| 78 | |
| 79 | // One of the users is unlocked but the other isn't |
| 80 | doReturn(false).when(helper).isUserCredentialLocked(eq(10)); |
| 81 | doReturn(true).when(helper).isUserCredentialLocked(eq(11)); |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 82 | when(installer.snapshotAppData(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(239L); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 83 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 84 | PackageRollbackInfo info2 = createPackageRollbackInfo("com.foo.bar", new int[]{10, 11}); |
| 85 | helper.snapshotAppData(7, info2); |
| 86 | assertEquals(1, info2.getPendingBackups().size()); |
| 87 | assertEquals(11, info2.getPendingBackups().get(0)); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 88 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 89 | assertEquals(1, info2.getCeSnapshotInodes().size()); |
| 90 | assertEquals(239L, info2.getCeSnapshotInodes().get(10)); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 91 | |
| 92 | inOrder = Mockito.inOrder(installer); |
| 93 | inOrder.verify(installer).snapshotAppData( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 94 | eq("com.foo.bar"), eq(10), eq(7), |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 95 | eq(Installer.FLAG_STORAGE_CE | Installer.FLAG_STORAGE_DE)); |
| 96 | inOrder.verify(installer).snapshotAppData( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 97 | eq("com.foo.bar"), eq(11), eq(7), eq(Installer.FLAG_STORAGE_DE)); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 98 | inOrder.verifyNoMoreInteractions(); |
| 99 | } |
| 100 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 101 | private static PackageRollbackInfo createPackageRollbackInfo(String packageName, |
| 102 | final int[] installedUsers) { |
| 103 | return new PackageRollbackInfo( |
| 104 | new VersionedPackage(packageName, 2), new VersionedPackage(packageName, 1), |
| 105 | new IntArray(), new ArrayList<>(), false, IntArray.wrap(installedUsers), |
| 106 | new SparseLongArray()); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 109 | private static PackageRollbackInfo createPackageRollbackInfo(String packageName) { |
| 110 | return createPackageRollbackInfo(packageName, new int[] {}); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Test |
| 114 | public void testRestoreAppDataSnapshot_pendingBackupForUser() throws Exception { |
| 115 | Installer installer = mock(Installer.class); |
| 116 | AppDataRollbackHelper helper = spy(new AppDataRollbackHelper(installer)); |
| 117 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 118 | PackageRollbackInfo info = createPackageRollbackInfo("com.foo"); |
| 119 | IntArray pendingBackups = info.getPendingBackups(); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 120 | pendingBackups.add(10); |
| 121 | pendingBackups.add(11); |
| 122 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 123 | assertTrue(helper.restoreAppData(13 /* rollbackId */, info, 10 /* userId */, 1 /* appId */, |
| 124 | "seinfo")); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 125 | |
| 126 | // Should only require FLAG_STORAGE_DE here because we have a pending backup that we |
| 127 | // didn't manage to execute. |
| 128 | InOrder inOrder = Mockito.inOrder(installer); |
| 129 | inOrder.verify(installer).restoreAppDataSnapshot( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 130 | eq("com.foo"), eq(1) /* appId */, eq("seinfo"), eq(10) /* userId */, |
| 131 | eq(13) /* rollbackId */, eq(Installer.FLAG_STORAGE_DE)); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 132 | inOrder.verifyNoMoreInteractions(); |
| 133 | |
| 134 | assertEquals(1, pendingBackups.size()); |
| 135 | assertEquals(11, pendingBackups.get(0)); |
| 136 | } |
| 137 | |
| 138 | @Test |
| 139 | public void testRestoreAppDataSnapshot_availableBackupForLockedUser() throws Exception { |
| 140 | Installer installer = mock(Installer.class); |
| 141 | AppDataRollbackHelper helper = spy(new AppDataRollbackHelper(installer)); |
| 142 | doReturn(true).when(helper).isUserCredentialLocked(eq(10)); |
| 143 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 144 | PackageRollbackInfo info = createPackageRollbackInfo("com.foo"); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 145 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 146 | assertTrue(helper.restoreAppData(73 /* rollbackId */, info, 10 /* userId */, 1 /* appId */, |
| 147 | "seinfo")); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 148 | |
| 149 | InOrder inOrder = Mockito.inOrder(installer); |
| 150 | inOrder.verify(installer).restoreAppDataSnapshot( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 151 | eq("com.foo"), eq(1) /* appId */, eq("seinfo"), eq(10) /* userId */, |
| 152 | eq(73) /* rollbackId */, eq(Installer.FLAG_STORAGE_DE)); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 153 | inOrder.verifyNoMoreInteractions(); |
| 154 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 155 | ArrayList<RestoreInfo> pendingRestores = info.getPendingRestores(); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 156 | assertEquals(1, pendingRestores.size()); |
| 157 | assertEquals(10, pendingRestores.get(0).userId); |
| 158 | assertEquals(1, pendingRestores.get(0).appId); |
| 159 | assertEquals("seinfo", pendingRestores.get(0).seInfo); |
| 160 | } |
| 161 | |
| 162 | @Test |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 163 | public void testRestoreAppDataSnapshot_availableBackupForUnlockedUser() throws Exception { |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 164 | Installer installer = mock(Installer.class); |
| 165 | AppDataRollbackHelper helper = spy(new AppDataRollbackHelper(installer)); |
| 166 | doReturn(false).when(helper).isUserCredentialLocked(eq(10)); |
| 167 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 168 | PackageRollbackInfo info = createPackageRollbackInfo("com.foo"); |
| 169 | assertFalse(helper.restoreAppData(101 /* rollbackId */, info, 10 /* userId */, |
| 170 | 1 /* appId */, "seinfo")); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 171 | |
| 172 | InOrder inOrder = Mockito.inOrder(installer); |
| 173 | inOrder.verify(installer).restoreAppDataSnapshot( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 174 | eq("com.foo"), eq(1) /* appId */, eq("seinfo"), eq(10) /* userId */, |
| 175 | eq(101) /* rollbackId */, |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 176 | eq(Installer.FLAG_STORAGE_DE | Installer.FLAG_STORAGE_CE)); |
| 177 | inOrder.verifyNoMoreInteractions(); |
| 178 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 179 | ArrayList<RestoreInfo> pendingRestores = info.getPendingRestores(); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 180 | assertEquals(0, pendingRestores.size()); |
| 181 | } |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 182 | |
| 183 | @Test |
| 184 | public void destroyAppData() throws Exception { |
| 185 | Installer installer = mock(Installer.class); |
| 186 | AppDataRollbackHelper helper = new AppDataRollbackHelper(installer); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 187 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 188 | PackageRollbackInfo info = createPackageRollbackInfo("com.foo.bar"); |
| 189 | info.putCeSnapshotInode(11, 239L); |
| 190 | helper.destroyAppDataSnapshot(5 /* rollbackId */, info, 10 /* userId */); |
| 191 | helper.destroyAppDataSnapshot(5 /* rollbackId */, info, 11 /* userId */); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 192 | |
| 193 | InOrder inOrder = Mockito.inOrder(installer); |
| 194 | inOrder.verify(installer).destroyAppDataSnapshot( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 195 | eq("com.foo.bar"), eq(10) /* userId */, eq(0L) /* ceSnapshotInode */, |
| 196 | eq(5) /* rollbackId */, eq(Installer.FLAG_STORAGE_DE)); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 197 | inOrder.verify(installer).destroyAppDataSnapshot( |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 198 | eq("com.foo.bar"), eq(11) /* userId */, eq(239L) /* ceSnapshotInode */, |
| 199 | eq(5) /* rollbackId */, eq(Installer.FLAG_STORAGE_DE | Installer.FLAG_STORAGE_CE)); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 200 | inOrder.verifyNoMoreInteractions(); |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 201 | |
| 202 | assertEquals(0, info.getCeSnapshotInodes().size()); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | @Test |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 206 | public void commitPendingBackupAndRestoreForUser() throws Exception { |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 207 | Installer installer = mock(Installer.class); |
| 208 | AppDataRollbackHelper helper = new AppDataRollbackHelper(installer); |
| 209 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 210 | when(installer.snapshotAppData(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(53L); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 211 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 212 | // This one should be backed up. |
| 213 | PackageRollbackInfo pendingBackup = createPackageRollbackInfo("com.foo", new int[]{37, 73}); |
| 214 | pendingBackup.addPendingBackup(37); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 215 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 216 | // Nothing should be done for this one. |
| 217 | PackageRollbackInfo wasRecentlyRestored = createPackageRollbackInfo("com.bar", |
| 218 | new int[]{37, 73}); |
| 219 | wasRecentlyRestored.addPendingBackup(37); |
| 220 | wasRecentlyRestored.getPendingRestores().add( |
| 221 | new RestoreInfo(37 /* userId */, 239 /* appId*/, "seInfo")); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 222 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 223 | // This one should be restored |
| 224 | PackageRollbackInfo pendingRestore = createPackageRollbackInfo("com.abc", |
| 225 | new int[]{37, 73}); |
| 226 | pendingRestore.putCeSnapshotInode(37, 1543L); |
| 227 | pendingRestore.getPendingRestores().add( |
| 228 | new RestoreInfo(37 /* userId */, 57 /* appId*/, "seInfo")); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 229 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 230 | // This one shouldn't be processed, because it hasn't pending backups/restores for userId |
| 231 | // 37. |
| 232 | PackageRollbackInfo ignoredInfo = createPackageRollbackInfo("com.bar", |
| 233 | new int[]{3, 73}); |
| 234 | wasRecentlyRestored.addPendingBackup(3); |
| 235 | wasRecentlyRestored.addPendingBackup(73); |
| 236 | wasRecentlyRestored.getPendingRestores().add( |
| 237 | new RestoreInfo(73 /* userId */, 239 /* appId*/, "seInfo")); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 238 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 239 | RollbackData dataWithPendingBackup = new RollbackData(101, new File("/does/not/exist"), -1, |
| 240 | true); |
| 241 | dataWithPendingBackup.packages.add(pendingBackup); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 242 | |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 243 | RollbackData dataWithRecentRestore = new RollbackData(17239, new File("/does/not/exist"), |
| 244 | -1, true); |
| 245 | dataWithRecentRestore.packages.add(wasRecentlyRestored); |
| 246 | |
| 247 | RollbackData dataForDifferentUser = new RollbackData(17239, new File("/does/not/exist"), |
| 248 | -1, true); |
| 249 | dataForDifferentUser.packages.add(ignoredInfo); |
| 250 | |
| 251 | RollbackInfo rollbackInfo = new RollbackInfo(17239, |
| 252 | Arrays.asList(pendingRestore, wasRecentlyRestored), false); |
| 253 | |
| 254 | List<RollbackData> changed = helper.commitPendingBackupAndRestoreForUser(37, |
| 255 | Arrays.asList(dataWithPendingBackup, dataWithRecentRestore, dataForDifferentUser), |
| 256 | Collections.singletonList(rollbackInfo)); |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 257 | InOrder inOrder = Mockito.inOrder(installer); |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 258 | |
| 259 | // Check that pending backup and restore for the same package mutually destroyed each other. |
| 260 | assertEquals(-1, wasRecentlyRestored.getPendingBackups().indexOf(37)); |
| 261 | assertNull(wasRecentlyRestored.getRestoreInfo(37)); |
| 262 | |
| 263 | // Check that backup was performed. |
| 264 | inOrder.verify(installer).snapshotAppData(eq("com.foo"), eq(37), eq(101), |
| 265 | eq(Installer.FLAG_STORAGE_CE)); |
| 266 | assertEquals(-1, pendingBackup.getPendingBackups().indexOf(37)); |
| 267 | assertEquals(53, pendingBackup.getCeSnapshotInodes().get(37)); |
| 268 | |
| 269 | // Check that changed returns correct RollbackData. |
| 270 | assertEquals(2, changed.size()); |
| 271 | assertEquals(dataWithPendingBackup, changed.get(0)); |
| 272 | assertEquals(dataWithRecentRestore, changed.get(1)); |
| 273 | |
| 274 | // Check that restore was performed. |
| 275 | inOrder.verify(installer).restoreAppDataSnapshot( |
| 276 | eq("com.abc"), eq(57) /* appId */, eq("seInfo"), eq(37) /* userId */, |
| 277 | eq(17239) /* rollbackId */, eq(Installer.FLAG_STORAGE_CE)); |
| 278 | assertNull(pendingRestore.getRestoreInfo(37)); |
| 279 | |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 280 | inOrder.verifyNoMoreInteractions(); |
| 281 | } |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 282 | } |