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 /** 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 KeyValueQuotaTest extends BaseBackupCtsTest { 26 27 private static final String BACKUP_APP_NAME = "android.backup.kvapp"; 28 29 // Should be the same as LocalTransport. KEY_VALUE_BACKUP_SIZE_QUOTA 30 private static final int LOCAL_TRANSPORT_BACKUP_QUOTA = 5 * 1024 * 1024; 31 private static final int LOCAL_TRANSPORT_EXCEEDING_FILE_SIZE = 6 * 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 // Launch the main activity so the app qualifies for backup. 54 createTestFileOfSize(BACKUP_APP_NAME, 1); 55 56 String separator = markLogcat(); 57 exec("bmgr backupnow " + BACKUP_APP_NAME); 58 waitForLogcat(TIMEOUT_SECONDS, separator, 59 "quota is " + LOCAL_TRANSPORT_BACKUP_QUOTA); 60 } 61 62 } 63