| /* |
| * Copyright (C) 2017 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License |
| */ |
| |
| package android.cts.backup; |
| |
| import static com.android.compatibility.common.util.BackupUtils.LOCAL_TRANSPORT_TOKEN; |
| |
| import android.platform.test.annotations.AppModeFull; |
| |
| import com.android.compatibility.common.util.BackupUtils; |
| import com.android.tradefed.log.LogUtil.CLog; |
| import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; |
| import com.android.tradefed.log.LogUtil.CLog; |
| |
| import org.junit.After; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| |
| /** |
| * Test checking that files created by an app are restored successfully after a backup, but that |
| * files put in the folder provided by getNoBackupFilesDir() [files/no_backup] are NOT backed up, |
| * and that files are included/excluded according to rules defined in the manifest. |
| * |
| * Invokes device side tests provided by android.cts.backup.fullbackupapp.FullbackupTest and |
| * android.cts.backup.includeexcludeapp.IncludeExcludeTest. |
| */ |
| @RunWith(DeviceJUnit4ClassRunner.class) |
| @AppModeFull |
| public class FullbackupRulesHostSideTest extends BaseBackupHostSideTest { |
| |
| private static final String FULLBACKUP_TESTS_APP_NAME = "android.cts.backup.fullbackupapp"; |
| private static final String FULLBACKUP_DEVICE_TEST_CLASS_NAME = |
| FULLBACKUP_TESTS_APP_NAME + ".FullbackupTest"; |
| |
| private static final String INCLUDE_EXCLUDE_TESTS_APP_NAME = |
| "android.cts.backup.includeexcludeapp"; |
| private static final String INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME = |
| INCLUDE_EXCLUDE_TESTS_APP_NAME + ".IncludeExcludeTest"; |
| |
| @After |
| public void tearDown() throws Exception { |
| disableFakeEncryptionOnTransport(); |
| } |
| |
| @Test |
| public void testNoBackupFolder() throws Exception { |
| if (!mIsBackupSupported) { |
| CLog.i("android.software.backup feature is not supported on this device"); |
| return; |
| } |
| |
| // Generate the files that are going to be backed up. |
| checkDeviceTest(FULLBACKUP_TESTS_APP_NAME, FULLBACKUP_DEVICE_TEST_CLASS_NAME, |
| "createFiles"); |
| |
| // Do a backup |
| getBackupUtils().backupNowAndAssertSuccess(FULLBACKUP_TESTS_APP_NAME); |
| |
| // Delete the files |
| checkDeviceTest(FULLBACKUP_TESTS_APP_NAME, FULLBACKUP_DEVICE_TEST_CLASS_NAME, |
| "deleteFilesAfterBackup"); |
| |
| // Do a restore |
| getBackupUtils().restoreAndAssertSuccess(LOCAL_TRANSPORT_TOKEN, FULLBACKUP_TESTS_APP_NAME); |
| |
| // Check that the right files were restored |
| checkDeviceTest(FULLBACKUP_TESTS_APP_NAME, FULLBACKUP_DEVICE_TEST_CLASS_NAME, |
| "checkRestoredFiles"); |
| } |
| |
| @Test |
| public void testIncludeExcludeRules() throws Exception { |
| if (!mIsBackupSupported) { |
| CLog.i("android.software.backup feature is not supported on this device"); |
| return; |
| } |
| |
| // Generate the files that are going to be backed up. |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "createFiles"); |
| |
| // Do a backup |
| getBackupUtils().backupNowAndAssertSuccess(INCLUDE_EXCLUDE_TESTS_APP_NAME); |
| |
| // Delete the files |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "deleteFilesAfterBackup"); |
| |
| // Do a restore |
| getBackupUtils() |
| .restoreAndAssertSuccess(LOCAL_TRANSPORT_TOKEN, INCLUDE_EXCLUDE_TESTS_APP_NAME); |
| |
| // Check that the right files were restored |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "checkRestoredFiles"); |
| } |
| |
| @Test |
| public void testRequireFakeEncryptionFlag_includesFileIfFakeEncryptionEnabled() |
| throws Exception { |
| if (!mIsBackupSupported) { |
| CLog.i("android.software.backup feature is not supported on this device"); |
| return; |
| } |
| |
| enableFakeEncryptionOnTransport(); |
| |
| // Generate the files that are going to be backed up. |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "createFiles"); |
| |
| // Do a backup |
| getBackupUtils().backupNowAndAssertSuccess(INCLUDE_EXCLUDE_TESTS_APP_NAME); |
| |
| // Delete the files |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "deleteFilesAfterBackup"); |
| |
| // Do a restore |
| getBackupUtils() |
| .restoreAndAssertSuccess(LOCAL_TRANSPORT_TOKEN, INCLUDE_EXCLUDE_TESTS_APP_NAME); |
| |
| // Check that the client-side encryption files were restored |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "checkRestoredClientSideEncryptionFiles"); |
| } |
| |
| @Test |
| public void testRequireFakeEncryptionFlag_excludesFileIfFakeEncryptionDisabled() |
| throws Exception { |
| if (!mIsBackupSupported) { |
| CLog.i("android.software.backup feature is not supported on this device"); |
| return; |
| } |
| |
| disableFakeEncryptionOnTransport(); |
| |
| // Generate the files that are going to be backed up. |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "createFiles"); |
| |
| // Do a backup |
| getBackupUtils().backupNowAndAssertSuccess(INCLUDE_EXCLUDE_TESTS_APP_NAME); |
| |
| // Delete the files |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "deleteFilesAfterBackup"); |
| |
| // Do a restore |
| getBackupUtils() |
| .restoreAndAssertSuccess(LOCAL_TRANSPORT_TOKEN, INCLUDE_EXCLUDE_TESTS_APP_NAME); |
| |
| // Check that the client-side encryption files were not restored |
| checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME, |
| "checkDidNotRestoreClientSideEncryptionFiles"); |
| } |
| } |