Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2016 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.backup.cts;
     18 
     19 /**
     20  * Verifies receiving quotaExceeded() callback on full backup.
     21  *
     22  * Uses test app that creates large file and receives the callback.
     23  * {@link com.android.internal.backup.LocalTransport} is used, it has size quota 25MB.
     24  */
     25 public class FullBackupQuotaTest extends BaseBackupCtsTest {
     26 
     27     private static final String BACKUP_APP_NAME = "android.backup.app";
     28 
     29     // Should be the same as LocalTransport.FULL_BACKUP_SIZE_QUOTA
     30     private static final int LOCAL_TRANSPORT_BACKUP_QUOTA = 25 * 1024 * 1024;
     31     private static final int LOCAL_TRANSPORT_EXCEEDING_FILE_SIZE = 30 * 1024 * 1024;
     32 
     33     private static final int TIMEOUT_SECONDS = 30;
     34 
     35     public void testQuotaExceeded() throws Exception {
     36         if (!isBackupSupported()) {
     37             return;
     38         }
     39         String separator = markLogcat();
     40         // Launch test app and create file exceeding limit for local transport
     41         createTestFileOfSize(BACKUP_APP_NAME, LOCAL_TRANSPORT_EXCEEDING_FILE_SIZE);
     42 
     43         // Request backup and wait for quota exceeded event in logcat
     44         exec("bmgr backupnow " + BACKUP_APP_NAME);
     45         waitForLogcat(TIMEOUT_SECONDS,separator,
     46             "Quota exceeded!");
     47     }
     48 
     49     public void testQuotaReported() throws Exception {
     50         if (!isBackupSupported()) {
     51             return;
     52         }
     53         // get the app out of (possibly) stopped state so that backup can be run
     54         exec("cmd activity broadcast -a android.backup.app.ACTION_WAKE_UP " +
     55                 "-n android.backup.app/.WakeUpReceiver");
     56 
     57         // give it 3s for the broadcast to be delivered
     58         try {
     59             Thread.sleep(3000);
     60         } catch (InterruptedException e) {}
     61 
     62         String separator = markLogcat();
     63         exec("bmgr backupnow " + BACKUP_APP_NAME);
     64         waitForLogcat(TIMEOUT_SECONDS,separator,
     65             "quota is " + LOCAL_TRANSPORT_BACKUP_QUOTA);
     66     }
     67 
     68 }
     69