Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.backup; |
| 18 | |
| 19 | import static junit.framework.Assert.assertEquals; |
| 20 | import static junit.framework.Assert.assertFalse; |
| 21 | import static junit.framework.Assert.assertNull; |
| 22 | import static junit.framework.Assert.assertTrue; |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 23 | import static junit.framework.Assert.fail; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 24 | |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 25 | import static org.mockito.Mockito.reset; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 26 | import static org.mockito.Mockito.verify; |
| 27 | import static org.mockito.Mockito.verifyNoMoreInteractions; |
| 28 | import static org.mockito.Mockito.when; |
| 29 | |
Artem Iglikov | c92eb46 | 2017-04-21 09:56:35 +0100 | [diff] [blame] | 30 | import android.app.backup.BackupManager; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 31 | import android.app.backup.IBackupManagerMonitor; |
| 32 | import android.app.backup.IBackupObserver; |
| 33 | import android.app.backup.IFullBackupRestoreObserver; |
| 34 | import android.content.ComponentName; |
| 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 37 | import android.content.pm.PackageManager; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 38 | import android.os.IBinder; |
| 39 | import android.os.ParcelFileDescriptor; |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 40 | import android.os.Process; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 41 | import android.os.RemoteException; |
| 42 | import android.os.UserHandle; |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 43 | import android.platform.test.annotations.Presubmit; |
| 44 | import android.support.test.filters.SmallTest; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 45 | import android.support.test.runner.AndroidJUnit4; |
| 46 | |
| 47 | import org.junit.Before; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 48 | import org.junit.Test; |
| 49 | import org.junit.runner.RunWith; |
| 50 | import org.mockito.Mock; |
| 51 | import org.mockito.MockitoAnnotations; |
| 52 | |
| 53 | import java.io.File; |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 54 | import java.io.FileDescriptor; |
| 55 | import java.io.IOException; |
| 56 | import java.io.PrintWriter; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 57 | |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 58 | @SmallTest |
| 59 | @Presubmit |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 60 | @RunWith(AndroidJUnit4.class) |
| 61 | public class TrampolineTest { |
| 62 | private static final String PACKAGE_NAME = "some.package.name"; |
| 63 | private static final String TRANSPORT_NAME = "some.transport.name"; |
| 64 | private static final String CURRENT_PASSWORD = "current_password"; |
| 65 | private static final String NEW_PASSWORD = "new_password"; |
| 66 | private static final String ENCRYPTION_PASSWORD = "encryption_password"; |
| 67 | private static final String DATA_MANAGEMENT_LABEL = "data_management_label"; |
| 68 | private static final String DESTINATION_STRING = "destination_string"; |
| 69 | private static final String[] PACKAGE_NAMES = |
| 70 | new String[]{"some.package.name._1", "some.package.name._2"}; |
| 71 | private static final String[] TRANSPORTS = |
| 72 | new String[]{"some.transport.name._1", "some.transport.name._2"}; |
| 73 | private static final ComponentName TRANSPORT_COMPONENT_NAME = new ComponentName("package", |
| 74 | "class"); |
| 75 | private static final ComponentName[] TRANSPORT_COMPONENTS = new ComponentName[]{ |
| 76 | new ComponentName("package1", "class1"), |
| 77 | new ComponentName("package2", "class2") |
| 78 | }; |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 79 | private final int NON_USER_SYSTEM = UserHandle.USER_SYSTEM + 1; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 80 | |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 81 | @Mock private BackupManagerService mBackupManagerServiceMock; |
| 82 | @Mock private RefactoredBackupManagerService mRefactoredBackupManagerServiceMock; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 83 | @Mock private Context mContextMock; |
| 84 | @Mock private File mSuppressFileMock; |
| 85 | @Mock private File mSuppressFileParentMock; |
| 86 | @Mock private IBinder mAgentMock; |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 87 | @Mock private ParcelFileDescriptor mParcelFileDescriptorMock; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 88 | @Mock private IFullBackupRestoreObserver mFullBackupRestoreObserverMock; |
| 89 | @Mock private IBackupObserver mBackupObserverMock; |
| 90 | @Mock private IBackupManagerMonitor mBackupManagerMonitorMock; |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 91 | @Mock private PrintWriter mPrintWriterMock; |
| 92 | |
| 93 | private FileDescriptor mFileDescriptorStub = new FileDescriptor(); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 94 | |
| 95 | private TrampolineTestable mTrampoline; |
| 96 | |
| 97 | @Before |
| 98 | public void setUp() { |
| 99 | MockitoAnnotations.initMocks(this); |
| 100 | |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 101 | TrampolineTestable.sRefactoredBackupManagerServiceMock = |
| 102 | mRefactoredBackupManagerServiceMock; |
| 103 | TrampolineTestable.sBackupManagerServiceMock = mBackupManagerServiceMock; |
| 104 | TrampolineTestable.sSuppressFile = mSuppressFileMock; |
| 105 | TrampolineTestable.sCallingUid = Process.SYSTEM_UID; |
| 106 | TrampolineTestable.sRefactoredServiceEnabled = false; |
| 107 | TrampolineTestable.sBackupDisabled = false; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 108 | |
| 109 | when(mSuppressFileMock.getParentFile()).thenReturn(mSuppressFileParentMock); |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 110 | |
| 111 | mTrampoline = new TrampolineTestable(mContextMock); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Test |
| 115 | public void constructor_createsSuppressFileDirectory() { |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 116 | verify(mSuppressFileParentMock).mkdirs(); |
| 117 | } |
| 118 | |
| 119 | @Test |
| 120 | public void initialize_forUserSystem_successfullyInitialized() { |
| 121 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 122 | |
| 123 | assertTrue(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 124 | } |
| 125 | |
| 126 | // The BackupManagerService can only be initialized by USER_SYSTEM, so we check that if any |
| 127 | // other user trying to initialize it leaves it non-active. |
| 128 | @Test |
| 129 | public void initialize_forNonUserSystem_nonInitialized() { |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 130 | mTrampoline.initialize(NON_USER_SYSTEM); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 131 | |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 132 | assertFalse(mTrampoline.isBackupServiceActive(NON_USER_SYSTEM)); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Test |
| 136 | public void initialize_globallyDisabled_nonInitialized() { |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 137 | TrampolineTestable.sBackupDisabled = true; |
| 138 | |
| 139 | TrampolineTestable trampoline = new TrampolineTestable(mContextMock); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 140 | trampoline.initialize(UserHandle.USER_SYSTEM); |
| 141 | |
| 142 | assertFalse(trampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 143 | } |
| 144 | |
| 145 | // Verify that BackupManagerService is not initialized if suppress file exists. |
| 146 | @Test |
| 147 | public void initialize_suppressFileExists_nonInitialized() { |
| 148 | when(mSuppressFileMock.exists()).thenReturn(true); |
| 149 | |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 150 | TrampolineTestable trampoline = new TrampolineTestable(mContextMock); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 151 | trampoline.initialize(UserHandle.USER_SYSTEM); |
| 152 | |
| 153 | assertFalse(trampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 154 | } |
| 155 | |
| 156 | @Test |
| 157 | public void isBackupServiceActive_calledBeforeInitialize_returnsFalse() { |
| 158 | assertFalse(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 159 | } |
| 160 | |
| 161 | @Test |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 162 | public void createService_refactoredServiceEnabled() { |
| 163 | TrampolineTestable.sRefactoredServiceEnabled = true; |
| 164 | |
| 165 | assertEquals(mRefactoredBackupManagerServiceMock, mTrampoline.createService()); |
| 166 | } |
| 167 | |
| 168 | @Test |
| 169 | public void createService_refactoredServiceDisabled() { |
| 170 | TrampolineTestable.sRefactoredServiceEnabled = false; |
| 171 | |
| 172 | assertEquals(mBackupManagerServiceMock, mTrampoline.createService()); |
| 173 | } |
| 174 | |
| 175 | @Test |
| 176 | public void setBackupServiceActive_callerSystemUid_serviceCreated() { |
| 177 | TrampolineTestable.sCallingUid = Process.SYSTEM_UID; |
| 178 | |
| 179 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, true); |
| 180 | |
| 181 | assertTrue(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 182 | } |
| 183 | |
| 184 | @Test |
| 185 | public void setBackupServiceActive_callerRootUid_serviceCreated() { |
| 186 | TrampolineTestable.sCallingUid = Process.ROOT_UID; |
| 187 | |
| 188 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, true); |
| 189 | |
| 190 | assertTrue(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 191 | } |
| 192 | |
| 193 | @Test |
| 194 | public void setBackupServiceActive_callerNonRootNonSystem_securityExceptionThrown() { |
| 195 | TrampolineTestable.sCallingUid = Process.FIRST_APPLICATION_UID; |
| 196 | |
| 197 | try { |
| 198 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, true); |
| 199 | fail(); |
| 200 | } catch (SecurityException expected) { |
| 201 | } |
| 202 | |
| 203 | assertFalse(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 204 | } |
| 205 | |
| 206 | @Test |
| 207 | public void setBackupServiceActive_backupDisabled_ignored() { |
| 208 | TrampolineTestable.sBackupDisabled = true; |
| 209 | TrampolineTestable trampoline = new TrampolineTestable(mContextMock); |
| 210 | |
| 211 | trampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, true); |
| 212 | |
| 213 | assertFalse(trampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 214 | } |
| 215 | |
| 216 | @Test |
| 217 | public void setBackupServiceActive_nonUserSystem_ignored() { |
| 218 | mTrampoline.setBackupServiceActive(NON_USER_SYSTEM, true); |
| 219 | |
| 220 | assertFalse(mTrampoline.isBackupServiceActive(NON_USER_SYSTEM)); |
| 221 | } |
| 222 | |
| 223 | @Test |
| 224 | public void setBackupServiceActive_alreadyActive_ignored() { |
| 225 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, true); |
| 226 | assertTrue(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 227 | assertEquals(1, mTrampoline.getCreateServiceCallsCount()); |
| 228 | |
| 229 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, true); |
| 230 | assertTrue(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 231 | assertEquals(1, mTrampoline.getCreateServiceCallsCount()); |
| 232 | } |
| 233 | |
| 234 | @Test |
| 235 | public void setBackupServiceActive_makeActive_serviceCreatedAndSuppressFileDeleted() { |
| 236 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, true); |
| 237 | |
| 238 | assertTrue(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 239 | verify(mSuppressFileMock).delete(); |
| 240 | } |
| 241 | |
| 242 | @Test |
| 243 | public void setBackupServiceActive_makeNonActive_serviceDeletedAndSuppressFileCreated() |
| 244 | throws IOException { |
| 245 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 246 | assertTrue(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 247 | |
| 248 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, false); |
| 249 | |
| 250 | assertFalse(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 251 | verify(mSuppressFileMock).createNewFile(); |
| 252 | } |
| 253 | |
| 254 | @Test |
| 255 | public void |
| 256 | setBackupServiceActive_makeNonActive_serviceDeletedAndSuppressFileCreated_ioExceptionHandled() |
| 257 | throws IOException { |
| 258 | when(mSuppressFileMock.createNewFile()).thenThrow(new IOException()); |
| 259 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 260 | assertTrue(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 261 | |
| 262 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, false); |
| 263 | |
| 264 | assertFalse(mTrampoline.isBackupServiceActive(UserHandle.USER_SYSTEM)); |
| 265 | verify(mSuppressFileMock).createNewFile(); |
| 266 | } |
| 267 | |
| 268 | @Test |
| 269 | public void setBackupServiceActive_makeNonActive_alreadyNonActive_ignored() throws IOException { |
| 270 | reset(mSuppressFileMock); |
| 271 | |
| 272 | mTrampoline.setBackupServiceActive(UserHandle.USER_SYSTEM, false); |
| 273 | |
| 274 | verifyNoMoreInteractions(mSuppressFileMock); |
| 275 | } |
| 276 | |
| 277 | @Test |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 278 | public void dataChanged_calledBeforeInitialize_ignored() throws RemoteException { |
| 279 | mTrampoline.dataChanged(PACKAGE_NAME); |
| 280 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 281 | } |
| 282 | |
| 283 | @Test |
| 284 | public void dataChanged_forwarded() throws RemoteException { |
| 285 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 286 | mTrampoline.dataChanged(PACKAGE_NAME); |
| 287 | verify(mBackupManagerServiceMock).dataChanged(PACKAGE_NAME); |
| 288 | } |
| 289 | |
| 290 | @Test |
| 291 | public void clearBackupData_calledBeforeInitialize_ignored() throws RemoteException { |
| 292 | mTrampoline.clearBackupData(TRANSPORT_NAME, PACKAGE_NAME); |
| 293 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 294 | } |
| 295 | |
| 296 | @Test |
| 297 | public void clearBackupData_forwarded() throws RemoteException { |
| 298 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 299 | mTrampoline.clearBackupData(TRANSPORT_NAME, PACKAGE_NAME); |
| 300 | verify(mBackupManagerServiceMock).clearBackupData(TRANSPORT_NAME, PACKAGE_NAME); |
| 301 | } |
| 302 | |
| 303 | @Test |
| 304 | public void agentConnected_calledBeforeInitialize_ignored() throws RemoteException { |
| 305 | mTrampoline.agentConnected(PACKAGE_NAME, mAgentMock); |
| 306 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 307 | } |
| 308 | |
| 309 | @Test |
| 310 | public void agentConnected_forwarded() throws RemoteException { |
| 311 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 312 | mTrampoline.agentConnected(PACKAGE_NAME, mAgentMock); |
| 313 | verify(mBackupManagerServiceMock).agentConnected(PACKAGE_NAME, mAgentMock); |
| 314 | } |
| 315 | |
| 316 | @Test |
| 317 | public void agentDisconnected_calledBeforeInitialize_ignored() throws RemoteException { |
| 318 | mTrampoline.agentDisconnected(PACKAGE_NAME); |
| 319 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 320 | } |
| 321 | |
| 322 | @Test |
| 323 | public void agentDisconnected_forwarded() throws RemoteException { |
| 324 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 325 | mTrampoline.agentDisconnected(PACKAGE_NAME); |
| 326 | verify(mBackupManagerServiceMock).agentDisconnected(PACKAGE_NAME); |
| 327 | } |
| 328 | |
| 329 | @Test |
| 330 | public void restoreAtInstall_calledBeforeInitialize_ignored() throws RemoteException { |
| 331 | mTrampoline.restoreAtInstall(PACKAGE_NAME, 123); |
| 332 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 333 | } |
| 334 | |
| 335 | @Test |
| 336 | public void restoreAtInstall_forwarded() throws RemoteException { |
| 337 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 338 | mTrampoline.restoreAtInstall(PACKAGE_NAME, 123); |
| 339 | verify(mBackupManagerServiceMock).restoreAtInstall(PACKAGE_NAME, 123); |
| 340 | } |
| 341 | |
| 342 | @Test |
| 343 | public void setBackupEnabled_calledBeforeInitialize_ignored() throws RemoteException { |
| 344 | mTrampoline.setBackupEnabled(true); |
| 345 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 346 | } |
| 347 | |
| 348 | @Test |
| 349 | public void setBackupEnabled_forwarded() throws RemoteException { |
| 350 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 351 | mTrampoline.setBackupEnabled(true); |
| 352 | verify(mBackupManagerServiceMock).setBackupEnabled(true); |
| 353 | } |
| 354 | |
| 355 | @Test |
| 356 | public void setAutoRestore_calledBeforeInitialize_ignored() throws RemoteException { |
| 357 | mTrampoline.setAutoRestore(true); |
| 358 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 359 | } |
| 360 | |
| 361 | @Test |
| 362 | public void setAutoRestore_forwarded() throws RemoteException { |
| 363 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 364 | mTrampoline.setAutoRestore(true); |
| 365 | verify(mBackupManagerServiceMock).setAutoRestore(true); |
| 366 | } |
| 367 | |
| 368 | @Test |
| 369 | public void setBackupProvisioned_calledBeforeInitialize_ignored() throws RemoteException { |
| 370 | mTrampoline.setBackupProvisioned(true); |
| 371 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 372 | } |
| 373 | |
| 374 | @Test |
| 375 | public void setBackupProvisioned_forwarded() throws RemoteException { |
| 376 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 377 | mTrampoline.setBackupProvisioned(true); |
| 378 | verify(mBackupManagerServiceMock).setBackupProvisioned(true); |
| 379 | } |
| 380 | |
| 381 | @Test |
| 382 | public void isBackupEnabled_calledBeforeInitialize_ignored() throws RemoteException { |
| 383 | assertFalse(mTrampoline.isBackupEnabled()); |
| 384 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 385 | } |
| 386 | |
| 387 | @Test |
| 388 | public void isBackupEnabled_forwarded() throws RemoteException { |
| 389 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 390 | mTrampoline.isBackupEnabled(); |
| 391 | verify(mBackupManagerServiceMock).isBackupEnabled(); |
| 392 | } |
| 393 | |
| 394 | @Test |
| 395 | public void setBackupPassword_calledBeforeInitialize_ignored() throws RemoteException { |
| 396 | mTrampoline.setBackupPassword(CURRENT_PASSWORD, NEW_PASSWORD); |
| 397 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 398 | } |
| 399 | |
| 400 | @Test |
| 401 | public void setBackupPassword_forwarded() throws RemoteException { |
| 402 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 403 | mTrampoline.setBackupPassword(CURRENT_PASSWORD, NEW_PASSWORD); |
| 404 | verify(mBackupManagerServiceMock).setBackupPassword(CURRENT_PASSWORD, NEW_PASSWORD); |
| 405 | } |
| 406 | |
| 407 | @Test |
| 408 | public void hasBackupPassword_calledBeforeInitialize_ignored() throws RemoteException { |
| 409 | assertFalse(mTrampoline.hasBackupPassword()); |
| 410 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 411 | } |
| 412 | |
| 413 | @Test |
| 414 | public void hasBackupPassword_forwarded() throws RemoteException { |
| 415 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 416 | mTrampoline.hasBackupPassword(); |
| 417 | verify(mBackupManagerServiceMock).hasBackupPassword(); |
| 418 | } |
| 419 | |
| 420 | @Test |
| 421 | public void backupNow_calledBeforeInitialize_ignored() throws RemoteException { |
| 422 | mTrampoline.backupNow(); |
| 423 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 424 | } |
| 425 | |
| 426 | @Test |
| 427 | public void backupNow_forwarded() throws RemoteException { |
| 428 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 429 | mTrampoline.backupNow(); |
| 430 | verify(mBackupManagerServiceMock).backupNow(); |
| 431 | } |
| 432 | |
| 433 | @Test |
| 434 | public void adbBackup_calledBeforeInitialize_ignored() throws RemoteException { |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 435 | mTrampoline.adbBackup(mParcelFileDescriptorMock, true, true, true, true, true, true, true, |
| 436 | true, |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 437 | PACKAGE_NAMES); |
| 438 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 439 | } |
| 440 | |
| 441 | @Test |
| 442 | public void adbBackup_forwarded() throws RemoteException { |
| 443 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 444 | mTrampoline.adbBackup(mParcelFileDescriptorMock, true, true, true, true, true, true, true, |
| 445 | true, |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 446 | PACKAGE_NAMES); |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 447 | verify(mBackupManagerServiceMock).adbBackup(mParcelFileDescriptorMock, true, true, true, |
| 448 | true, |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 449 | true, true, true, true, PACKAGE_NAMES); |
| 450 | } |
| 451 | |
| 452 | @Test |
| 453 | public void fullTransportBackup_calledBeforeInitialize_ignored() throws RemoteException { |
| 454 | mTrampoline.fullTransportBackup(PACKAGE_NAMES); |
| 455 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 456 | } |
| 457 | |
| 458 | @Test |
| 459 | public void fullTransportBackup_forwarded() throws RemoteException { |
| 460 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 461 | mTrampoline.fullTransportBackup(PACKAGE_NAMES); |
| 462 | verify(mBackupManagerServiceMock).fullTransportBackup(PACKAGE_NAMES); |
| 463 | } |
| 464 | |
| 465 | @Test |
| 466 | public void adbRestore_calledBeforeInitialize_ignored() throws RemoteException { |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 467 | mTrampoline.adbRestore(mParcelFileDescriptorMock); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 468 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 469 | } |
| 470 | |
| 471 | @Test |
| 472 | public void adbRestore_forwarded() throws RemoteException { |
| 473 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 474 | mTrampoline.adbRestore(mParcelFileDescriptorMock); |
| 475 | verify(mBackupManagerServiceMock).adbRestore(mParcelFileDescriptorMock); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | @Test |
| 479 | public void acknowledgeFullBackupOrRestore_calledBeforeInitialize_ignored() |
| 480 | throws RemoteException { |
| 481 | mTrampoline.acknowledgeFullBackupOrRestore(123, true, CURRENT_PASSWORD, ENCRYPTION_PASSWORD, |
| 482 | mFullBackupRestoreObserverMock); |
| 483 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 484 | } |
| 485 | |
| 486 | @Test |
| 487 | public void acknowledgeFullBackupOrRestore_forwarded() throws RemoteException { |
| 488 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 489 | mTrampoline.acknowledgeFullBackupOrRestore(123, true, CURRENT_PASSWORD, ENCRYPTION_PASSWORD, |
| 490 | mFullBackupRestoreObserverMock); |
| 491 | verify(mBackupManagerServiceMock).acknowledgeAdbBackupOrRestore(123, true, CURRENT_PASSWORD, |
| 492 | ENCRYPTION_PASSWORD, mFullBackupRestoreObserverMock); |
| 493 | } |
| 494 | |
| 495 | @Test |
| 496 | public void getCurrentTransport_calledBeforeInitialize_ignored() throws RemoteException { |
| 497 | assertNull(mTrampoline.getCurrentTransport()); |
| 498 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 499 | } |
| 500 | |
| 501 | @Test |
| 502 | public void getCurrentTransport_forwarded() throws RemoteException { |
| 503 | when(mBackupManagerServiceMock.getCurrentTransport()).thenReturn(TRANSPORT_NAME); |
| 504 | |
| 505 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 506 | |
| 507 | assertEquals(TRANSPORT_NAME, mTrampoline.getCurrentTransport()); |
| 508 | verify(mBackupManagerServiceMock).getCurrentTransport(); |
| 509 | } |
| 510 | |
| 511 | @Test |
| 512 | public void listAllTransports_calledBeforeInitialize_ignored() throws RemoteException { |
| 513 | assertNull(mTrampoline.listAllTransports()); |
| 514 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 515 | } |
| 516 | |
| 517 | @Test |
| 518 | public void listAllTransports_forwarded() throws RemoteException { |
| 519 | when(mBackupManagerServiceMock.listAllTransports()).thenReturn(TRANSPORTS); |
| 520 | |
| 521 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 522 | assertEquals(TRANSPORTS, mTrampoline.listAllTransports()); |
| 523 | verify(mBackupManagerServiceMock).listAllTransports(); |
| 524 | } |
| 525 | |
| 526 | @Test |
| 527 | public void listAllTransportComponents_calledBeforeInitialize_ignored() throws RemoteException { |
| 528 | assertNull(mTrampoline.listAllTransportComponents()); |
| 529 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 530 | } |
| 531 | |
| 532 | @Test |
| 533 | public void listAllTransportComponents_forwarded() throws RemoteException { |
| 534 | when(mBackupManagerServiceMock.listAllTransportComponents()).thenReturn( |
| 535 | TRANSPORT_COMPONENTS); |
| 536 | |
| 537 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 538 | assertEquals(TRANSPORT_COMPONENTS, mTrampoline.listAllTransportComponents()); |
| 539 | verify(mBackupManagerServiceMock).listAllTransportComponents(); |
| 540 | } |
| 541 | |
| 542 | @Test |
| 543 | public void getTransportWhitelist_calledBeforeInitialize_ignored() throws RemoteException { |
| 544 | assertNull(mTrampoline.getTransportWhitelist()); |
| 545 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 546 | } |
| 547 | |
| 548 | @Test |
| 549 | public void getTransportWhitelist_forwarded() throws RemoteException { |
| 550 | when(mBackupManagerServiceMock.getTransportWhitelist()).thenReturn(TRANSPORTS); |
| 551 | |
| 552 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 553 | assertEquals(TRANSPORTS, mTrampoline.getTransportWhitelist()); |
| 554 | verify(mBackupManagerServiceMock).getTransportWhitelist(); |
| 555 | } |
| 556 | |
| 557 | @Test |
| 558 | public void selectBackupTransport_calledBeforeInitialize_ignored() throws RemoteException { |
| 559 | mTrampoline.selectBackupTransport(TRANSPORT_NAME); |
| 560 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 561 | } |
| 562 | |
| 563 | @Test |
| 564 | public void selectBackupTransport_forwarded() throws RemoteException { |
| 565 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 566 | mTrampoline.selectBackupTransport(TRANSPORT_NAME); |
| 567 | verify(mBackupManagerServiceMock).selectBackupTransport(TRANSPORT_NAME); |
| 568 | } |
| 569 | |
| 570 | @Test |
| 571 | public void selectBackupTransportAsync_calledBeforeInitialize_ignored() throws RemoteException { |
| 572 | mTrampoline.selectBackupTransportAsync(TRANSPORT_COMPONENT_NAME, null); |
| 573 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 574 | } |
| 575 | |
| 576 | @Test |
| 577 | public void selectBackupTransportAsync_forwarded() throws RemoteException { |
| 578 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 579 | mTrampoline.selectBackupTransportAsync(TRANSPORT_COMPONENT_NAME, null); |
| 580 | verify(mBackupManagerServiceMock).selectBackupTransportAsync(TRANSPORT_COMPONENT_NAME, |
| 581 | null); |
| 582 | } |
| 583 | |
| 584 | @Test |
| 585 | public void getConfigurationIntent_calledBeforeInitialize_ignored() throws RemoteException { |
| 586 | mTrampoline.getConfigurationIntent(TRANSPORT_NAME); |
| 587 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 588 | } |
| 589 | |
| 590 | @Test |
| 591 | public void getConfigurationIntent_forwarded() throws RemoteException { |
| 592 | Intent configurationIntentStub = new Intent(); |
| 593 | when(mBackupManagerServiceMock.getConfigurationIntent(TRANSPORT_NAME)).thenReturn( |
| 594 | configurationIntentStub); |
| 595 | |
| 596 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 597 | assertEquals(configurationIntentStub, mTrampoline.getConfigurationIntent(TRANSPORT_NAME)); |
| 598 | verify(mBackupManagerServiceMock).getConfigurationIntent(TRANSPORT_NAME); |
| 599 | } |
| 600 | |
| 601 | @Test |
| 602 | public void getDestinationString_calledBeforeInitialize_ignored() throws RemoteException { |
| 603 | assertNull(mTrampoline.getDestinationString(TRANSPORT_NAME)); |
| 604 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 605 | } |
| 606 | |
| 607 | @Test |
| 608 | public void getDestinationString_forwarded() throws RemoteException { |
| 609 | when(mBackupManagerServiceMock.getDestinationString(TRANSPORT_NAME)).thenReturn( |
| 610 | DESTINATION_STRING); |
| 611 | |
| 612 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 613 | assertEquals(DESTINATION_STRING, mTrampoline.getDestinationString(TRANSPORT_NAME)); |
| 614 | verify(mBackupManagerServiceMock).getDestinationString(TRANSPORT_NAME); |
| 615 | } |
| 616 | |
| 617 | @Test |
| 618 | public void getDataManagementIntent_calledBeforeInitialize_ignored() throws RemoteException { |
| 619 | assertNull(mTrampoline.getDataManagementIntent(TRANSPORT_NAME)); |
| 620 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 621 | } |
| 622 | |
| 623 | @Test |
| 624 | public void getDataManagementIntent_forwarded() throws RemoteException { |
| 625 | Intent dataManagementIntent = new Intent(); |
| 626 | when(mBackupManagerServiceMock.getDataManagementIntent(TRANSPORT_NAME)).thenReturn( |
| 627 | dataManagementIntent); |
| 628 | |
| 629 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 630 | assertEquals(dataManagementIntent, mTrampoline.getDataManagementIntent(TRANSPORT_NAME)); |
| 631 | verify(mBackupManagerServiceMock).getDataManagementIntent(TRANSPORT_NAME); |
| 632 | } |
| 633 | |
| 634 | @Test |
| 635 | public void getDataManagementLabel_calledBeforeInitialize_ignored() throws RemoteException { |
| 636 | assertNull(mTrampoline.getDataManagementLabel(TRANSPORT_NAME)); |
| 637 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 638 | } |
| 639 | |
| 640 | @Test |
| 641 | public void getDataManagementLabel_forwarded() throws RemoteException { |
| 642 | when(mBackupManagerServiceMock.getDataManagementLabel(TRANSPORT_NAME)).thenReturn( |
| 643 | DATA_MANAGEMENT_LABEL); |
| 644 | |
| 645 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 646 | assertEquals(DATA_MANAGEMENT_LABEL, mTrampoline.getDataManagementLabel(TRANSPORT_NAME)); |
| 647 | verify(mBackupManagerServiceMock).getDataManagementLabel(TRANSPORT_NAME); |
| 648 | } |
| 649 | |
| 650 | @Test |
| 651 | public void beginRestoreSession_calledBeforeInitialize_ignored() throws RemoteException { |
| 652 | mTrampoline.beginRestoreSession(PACKAGE_NAME, TRANSPORT_NAME); |
| 653 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 654 | } |
| 655 | |
| 656 | @Test |
| 657 | public void beginRestoreSession_forwarded() throws RemoteException { |
| 658 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 659 | mTrampoline.beginRestoreSession(PACKAGE_NAME, TRANSPORT_NAME); |
| 660 | verify(mBackupManagerServiceMock).beginRestoreSession(PACKAGE_NAME, TRANSPORT_NAME); |
| 661 | } |
| 662 | |
| 663 | @Test |
| 664 | public void opComplete_calledBeforeInitialize_ignored() throws RemoteException { |
| 665 | mTrampoline.opComplete(1, 2); |
| 666 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 667 | } |
| 668 | |
| 669 | @Test |
| 670 | public void opComplete_forwarded() throws RemoteException { |
| 671 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 672 | mTrampoline.opComplete(1, 2); |
| 673 | verify(mBackupManagerServiceMock).opComplete(1, 2); |
| 674 | } |
| 675 | |
| 676 | @Test |
| 677 | public void getAvailableRestoreToken_calledBeforeInitialize_ignored() throws RemoteException { |
| 678 | assertEquals(0, mTrampoline.getAvailableRestoreToken(PACKAGE_NAME)); |
| 679 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 680 | } |
| 681 | |
| 682 | @Test |
| 683 | public void getAvailableRestoreToken_forwarded() throws RemoteException { |
| 684 | when(mBackupManagerServiceMock.getAvailableRestoreToken(PACKAGE_NAME)).thenReturn(123L); |
| 685 | |
| 686 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 687 | assertEquals(123, mTrampoline.getAvailableRestoreToken(PACKAGE_NAME)); |
| 688 | verify(mBackupManagerServiceMock).getAvailableRestoreToken(PACKAGE_NAME); |
| 689 | } |
| 690 | |
| 691 | @Test |
| 692 | public void isAppEligibleForBackup_calledBeforeInitialize_ignored() throws RemoteException { |
| 693 | assertFalse(mTrampoline.isAppEligibleForBackup(PACKAGE_NAME)); |
| 694 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 695 | } |
| 696 | |
| 697 | @Test |
| 698 | public void isAppEligibleForBackup_forwarded() throws RemoteException { |
| 699 | when(mBackupManagerServiceMock.isAppEligibleForBackup(PACKAGE_NAME)).thenReturn(true); |
| 700 | |
| 701 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 702 | assertTrue(mTrampoline.isAppEligibleForBackup(PACKAGE_NAME)); |
| 703 | verify(mBackupManagerServiceMock).isAppEligibleForBackup(PACKAGE_NAME); |
| 704 | } |
| 705 | |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 706 | @Test |
| 707 | public void requestBackup_calledBeforeInitialize_ignored() throws RemoteException { |
Artem Iglikov | c92eb46 | 2017-04-21 09:56:35 +0100 | [diff] [blame] | 708 | assertEquals(BackupManager.ERROR_BACKUP_NOT_ALLOWED, mTrampoline.requestBackup( |
| 709 | PACKAGE_NAMES, mBackupObserverMock, mBackupManagerMonitorMock, 123)); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 710 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 711 | } |
| 712 | |
| 713 | @Test |
| 714 | public void requestBackup_forwarded() throws RemoteException { |
| 715 | when(mBackupManagerServiceMock.requestBackup(PACKAGE_NAMES, mBackupObserverMock, |
| 716 | mBackupManagerMonitorMock, 123)).thenReturn(456); |
| 717 | |
| 718 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 719 | assertEquals(456, mTrampoline.requestBackup(PACKAGE_NAMES, mBackupObserverMock, |
| 720 | mBackupManagerMonitorMock, 123)); |
| 721 | verify(mBackupManagerServiceMock).requestBackup(PACKAGE_NAMES, mBackupObserverMock, |
| 722 | mBackupManagerMonitorMock, 123); |
| 723 | } |
| 724 | |
| 725 | @Test |
| 726 | public void cancelBackups_calledBeforeInitialize_ignored() throws RemoteException { |
| 727 | mTrampoline.cancelBackups(); |
| 728 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 729 | } |
| 730 | |
| 731 | @Test |
| 732 | public void cancelBackups_forwarded() throws RemoteException { |
| 733 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 734 | mTrampoline.cancelBackups(); |
| 735 | verify(mBackupManagerServiceMock).cancelBackups(); |
| 736 | } |
| 737 | |
| 738 | @Test |
| 739 | public void beginFullBackup_calledBeforeInitialize_ignored() throws RemoteException { |
| 740 | mTrampoline.beginFullBackup(new FullBackupJob()); |
| 741 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 742 | } |
| 743 | |
| 744 | @Test |
| 745 | public void beginFullBackup_forwarded() throws RemoteException { |
| 746 | FullBackupJob fullBackupJob = new FullBackupJob(); |
| 747 | when(mBackupManagerServiceMock.beginFullBackup(fullBackupJob)).thenReturn(true); |
| 748 | |
| 749 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 750 | assertTrue(mTrampoline.beginFullBackup(fullBackupJob)); |
| 751 | verify(mBackupManagerServiceMock).beginFullBackup(fullBackupJob); |
| 752 | } |
| 753 | |
| 754 | @Test |
| 755 | public void endFullBackup_calledBeforeInitialize_ignored() throws RemoteException { |
| 756 | mTrampoline.endFullBackup(); |
| 757 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 758 | } |
| 759 | |
| 760 | @Test |
| 761 | public void endFullBackup_forwarded() throws RemoteException { |
| 762 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 763 | mTrampoline.endFullBackup(); |
| 764 | verify(mBackupManagerServiceMock).endFullBackup(); |
| 765 | } |
| 766 | |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 767 | @Test |
| 768 | public void dump_callerDoesNotHavePermission_ignored() throws RemoteException { |
| 769 | when(mContextMock.checkCallingOrSelfPermission( |
| 770 | android.Manifest.permission.DUMP)).thenReturn( |
| 771 | PackageManager.PERMISSION_DENIED); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 772 | |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 773 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 774 | |
| 775 | mTrampoline.dump(mFileDescriptorStub, mPrintWriterMock, new String[0]); |
| 776 | |
| 777 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 778 | } |
| 779 | |
| 780 | @Test |
| 781 | public void dump_calledBeforeInitialize_ignored() throws RemoteException { |
| 782 | when(mContextMock.checkCallingOrSelfPermission( |
| 783 | android.Manifest.permission.DUMP)).thenReturn( |
| 784 | PackageManager.PERMISSION_GRANTED); |
| 785 | |
| 786 | mTrampoline.dump(mFileDescriptorStub, mPrintWriterMock, new String[0]); |
| 787 | |
| 788 | verifyNoMoreInteractions(mBackupManagerServiceMock); |
| 789 | } |
| 790 | |
| 791 | @Test |
| 792 | public void dump_callerHasPermission_forwarded() throws RemoteException { |
| 793 | when(mContextMock.checkCallingOrSelfPermission( |
| 794 | android.Manifest.permission.DUMP)).thenReturn( |
| 795 | PackageManager.PERMISSION_GRANTED); |
| 796 | |
| 797 | mTrampoline.initialize(UserHandle.USER_SYSTEM); |
| 798 | |
| 799 | mTrampoline.dump(mFileDescriptorStub, mPrintWriterMock, null); |
| 800 | |
| 801 | verify(mBackupManagerServiceMock).dump(mFileDescriptorStub, mPrintWriterMock, null); |
| 802 | } |
| 803 | |
| 804 | private static class TrampolineTestable extends Trampoline { |
| 805 | static boolean sBackupDisabled = false; |
| 806 | static boolean sRefactoredServiceEnabled = false; |
| 807 | static File sSuppressFile = null; |
| 808 | static int sCallingUid = -1; |
| 809 | static BackupManagerService sBackupManagerServiceMock = null; |
| 810 | static RefactoredBackupManagerService sRefactoredBackupManagerServiceMock = null; |
| 811 | private int mCreateServiceCallsCount = 0; |
| 812 | |
| 813 | TrampolineTestable(Context context) { |
| 814 | super(context); |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | @Override |
| 818 | protected BackupManagerServiceInterface createService() { |
Artem Iglikov | e5263c6 | 2017-04-21 13:23:16 +0100 | [diff] [blame^] | 819 | mCreateServiceCallsCount++; |
| 820 | return super.createService(); |
| 821 | } |
| 822 | |
| 823 | @Override |
| 824 | public boolean isBackupDisabled() { |
| 825 | return sBackupDisabled; |
| 826 | } |
| 827 | |
| 828 | @Override |
| 829 | public File getSuppressFile() { |
| 830 | return sSuppressFile; |
| 831 | } |
| 832 | |
| 833 | @Override |
| 834 | protected int binderGetCallingUid() { |
| 835 | return sCallingUid; |
| 836 | } |
| 837 | |
| 838 | @Override |
| 839 | protected boolean isRefactoredServiceEnabled() { |
| 840 | return sRefactoredServiceEnabled; |
| 841 | } |
| 842 | |
| 843 | @Override |
| 844 | protected BackupManagerServiceInterface createRefactoredBackupManagerService() { |
| 845 | return sRefactoredBackupManagerServiceMock; |
| 846 | } |
| 847 | |
| 848 | @Override |
| 849 | protected BackupManagerServiceInterface createBackupManagerService() { |
| 850 | return sBackupManagerServiceMock; |
| 851 | } |
| 852 | |
| 853 | int getCreateServiceCallsCount() { |
| 854 | return mCreateServiceCallsCount; |
Artem Iglikov | 6052ef5 | 2017-04-20 17:23:39 +0100 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | } |