Home | History | Annotate | Download | only in backup
      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 android.cts.backup;
     18 
     19 import com.android.tradefed.log.LogUtil.CLog;
     20 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
     21 import com.android.tradefed.log.LogUtil.CLog;
     22 
     23 import org.junit.After;
     24 import org.junit.Test;
     25 import org.junit.runner.RunWith;
     26 
     27 /**
     28  * Test checking that files created by an app are restored successfully after a backup, but that
     29  * files put in the folder provided by getNoBackupFilesDir() [files/no_backup] are NOT backed up,
     30  * and that files are included/excluded according to rules defined in the manifest.
     31  *
     32  * Invokes device side tests provided by android.cts.backup.fullbackupapp.FullbackupTest and
     33  * android.cts.backup.includeexcludeapp.IncludeExcludeTest.
     34  */
     35 @RunWith(DeviceJUnit4ClassRunner.class)
     36 public class FullbackupRulesHostSideTest extends BaseBackupHostSideTest {
     37 
     38     private static final String FULLBACKUP_TESTS_APP_NAME = "android.cts.backup.fullbackupapp";
     39     private static final String FULLBACKUP_DEVICE_TEST_CLASS_NAME =
     40             FULLBACKUP_TESTS_APP_NAME + ".FullbackupTest";
     41 
     42     private static final String INCLUDE_EXCLUDE_TESTS_APP_NAME =
     43             "android.cts.backup.includeexcludeapp";
     44     private static final String INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME =
     45             INCLUDE_EXCLUDE_TESTS_APP_NAME + ".IncludeExcludeTest";
     46 
     47     @After
     48     public void tearDown() throws Exception {
     49         disableFakeEncryptionOnTransport();
     50     }
     51 
     52     @Test
     53     public void testNoBackupFolder() throws Exception {
     54         if (!mIsBackupSupported) {
     55             CLog.i("android.software.backup feature is not supported on this device");
     56             return;
     57         }
     58 
     59         // Generate the files that are going to be backed up.
     60         checkDeviceTest(FULLBACKUP_TESTS_APP_NAME, FULLBACKUP_DEVICE_TEST_CLASS_NAME,
     61                 "createFiles");
     62 
     63         // Do a backup
     64         String backupnowOutput = backupNow(FULLBACKUP_TESTS_APP_NAME);
     65 
     66         assertBackupIsSuccessful(FULLBACKUP_TESTS_APP_NAME, backupnowOutput);
     67 
     68         // Delete the files
     69         checkDeviceTest(FULLBACKUP_TESTS_APP_NAME, FULLBACKUP_DEVICE_TEST_CLASS_NAME,
     70                 "deleteFilesAfterBackup");
     71 
     72         // Do a restore
     73         String restoreOutput = restore(FULLBACKUP_TESTS_APP_NAME);
     74 
     75         assertRestoreIsSuccessful(restoreOutput);
     76 
     77         // Check that the right files were restored
     78         checkDeviceTest(FULLBACKUP_TESTS_APP_NAME, FULLBACKUP_DEVICE_TEST_CLASS_NAME,
     79                 "checkRestoredFiles");
     80     }
     81 
     82     @Test
     83     public void testIncludeExcludeRules() throws Exception {
     84         if (!mIsBackupSupported) {
     85             CLog.i("android.software.backup feature is not supported on this device");
     86             return;
     87         }
     88 
     89         // Generate the files that are going to be backed up.
     90         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
     91                 "createFiles");
     92 
     93         // Do a backup
     94         String backupNowOutput = backupNow(INCLUDE_EXCLUDE_TESTS_APP_NAME);
     95         assertBackupIsSuccessful(INCLUDE_EXCLUDE_TESTS_APP_NAME, backupNowOutput);
     96 
     97         // Delete the files
     98         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
     99                 "deleteFilesAfterBackup");
    100 
    101         // Do a restore
    102         String restoreOutput = restore(INCLUDE_EXCLUDE_TESTS_APP_NAME);
    103         assertRestoreIsSuccessful(restoreOutput);
    104 
    105         // Check that the right files were restored
    106         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
    107                 "checkRestoredFiles");
    108     }
    109 
    110     @Test
    111     public void testRequireFakeEncryptionFlag_includesFileIfFakeEncryptionEnabled()
    112             throws Exception {
    113         if (!mIsBackupSupported) {
    114             CLog.i("android.software.backup feature is not supported on this device");
    115             return;
    116         }
    117 
    118         enableFakeEncryptionOnTransport();
    119 
    120         // Generate the files that are going to be backed up.
    121         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
    122                 "createFiles");
    123 
    124         // Do a backup
    125         String backupNowOutput = backupNow(INCLUDE_EXCLUDE_TESTS_APP_NAME);
    126         assertBackupIsSuccessful(INCLUDE_EXCLUDE_TESTS_APP_NAME, backupNowOutput);
    127 
    128         // Delete the files
    129         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
    130                 "deleteFilesAfterBackup");
    131 
    132         // Do a restore
    133         String restoreOutput = restore(INCLUDE_EXCLUDE_TESTS_APP_NAME);
    134         assertRestoreIsSuccessful(restoreOutput);
    135 
    136         // Check that the client-side encryption files were restored
    137         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
    138                 "checkRestoredClientSideEncryptionFiles");
    139     }
    140 
    141     @Test
    142     public void testRequireFakeEncryptionFlag_excludesFileIfFakeEncryptionDisabled()
    143             throws Exception {
    144         if (!mIsBackupSupported) {
    145             CLog.i("android.software.backup feature is not supported on this device");
    146             return;
    147         }
    148 
    149         disableFakeEncryptionOnTransport();
    150 
    151         // Generate the files that are going to be backed up.
    152         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
    153                 "createFiles");
    154 
    155         // Do a backup
    156         String backupNowOutput = backupNow(INCLUDE_EXCLUDE_TESTS_APP_NAME);
    157         assertBackupIsSuccessful(INCLUDE_EXCLUDE_TESTS_APP_NAME, backupNowOutput);
    158 
    159         // Delete the files
    160         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
    161                 "deleteFilesAfterBackup");
    162 
    163         // Do a restore
    164         String restoreOutput = restore(INCLUDE_EXCLUDE_TESTS_APP_NAME);
    165         assertRestoreIsSuccessful(restoreOutput);
    166 
    167         // Check that the client-side encryption files were not restored
    168         checkDeviceTest(INCLUDE_EXCLUDE_TESTS_APP_NAME, INCLUDE_EXCLUDE_DEVICE_TEST_CLASS_NAME,
    169                 "checkDidNotRestoreClientSideEncryptionFiles");
    170     }
    171 }
    172