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.backup.cts; 18 19 import android.platform.test.annotations.AppModeFull; 20 21 /** 22 * Verifies receiving quotaExceeded() callback on full backup. 23 * 24 * Uses test app that creates large file and receives the callback. 25 * {@link com.android.localtransport.LocalTransport} is used, it has size quota 25MB. 26 */ 27 @AppModeFull 28 public class KeyValueQuotaTest extends BaseBackupCtsTest { 29 30 private static final String BACKUP_APP_NAME = "android.backup.kvapp"; 31 32 // Should be the same as LocalTransport. KEY_VALUE_BACKUP_SIZE_QUOTA 33 private static final int LOCAL_TRANSPORT_BACKUP_QUOTA = 5 * 1024 * 1024; 34 private static final int LOCAL_TRANSPORT_EXCEEDING_FILE_SIZE = 6 * 1024 * 1024; 35 36 private static final int TIMEOUT_SECONDS = 30; 37 testQuotaExceeded()38 public void testQuotaExceeded() throws Exception { 39 if (!isBackupSupported()) { 40 return; 41 } 42 String separator = markLogcat(); 43 // Launch test app and create file exceeding limit for local transport 44 createTestFileOfSize(BACKUP_APP_NAME, LOCAL_TRANSPORT_EXCEEDING_FILE_SIZE); 45 46 // Request backup and wait for quota exceeded event in logcat 47 getBackupUtils().backupNowSync(BACKUP_APP_NAME); 48 waitForLogcat(TIMEOUT_SECONDS, separator, 49 "Quota exceeded!"); 50 } 51 testQuotaReported()52 public void testQuotaReported() throws Exception { 53 if (!isBackupSupported()) { 54 return; 55 } 56 // Launch the main activity so the app qualifies for backup. 57 createTestFileOfSize(BACKUP_APP_NAME, 1); 58 59 String separator = markLogcat(); 60 getBackupUtils().backupNowSync(BACKUP_APP_NAME); 61 waitForLogcat(TIMEOUT_SECONDS, separator, 62 "quota is " + LOCAL_TRANSPORT_BACKUP_QUOTA); 63 } 64 65 } 66