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 com.android.cts.customizationapp; 18 19 import android.app.WallpaperManager; 20 import android.content.Context; 21 import android.graphics.Bitmap; 22 import android.os.UserManager; 23 import android.test.AndroidTestCase; 24 25 import com.android.compatibility.common.util.BitmapUtils; 26 import com.android.cts.customizationapp.R; 27 28 /** 29 * Test class to check different restrictions, that are connected to the device customization. 30 * The test verifies that non-admin app can't circumvent restriction. The tested restriction is 31 * {@link UserManager#DISALLOW_SET_WALLPAPER}. There is no non-admin API for setting the user icon, 32 * that would allow to test {@link UserManager#DISALLOW_SET_USER_ICON} restriction in this test. 33 */ 34 public class CustomizationTest extends AndroidTestCase { 35 private static final int WAITING_TIME_MS = 3 * 1000; 36 testSetWallpaper_disallowed()37 public void testSetWallpaper_disallowed() throws Exception { 38 final WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext); 39 final Bitmap originalWallpaper = BitmapUtils.getWallpaperBitmap(mContext); 40 final Bitmap referenceWallpaper = BitmapUtils.generateRandomBitmap(97, 73); 41 final UserManager userManager = 42 (UserManager) mContext.getSystemService(Context.USER_SERVICE); 43 assertTrue(userManager.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER)); 44 45 // Checking setBitmap() method. 46 wallpaperManager.setBitmap(referenceWallpaper); 47 Thread.sleep(WAITING_TIME_MS); 48 Bitmap newWallpaper = BitmapUtils.getWallpaperBitmap(mContext); 49 assertTrue(BitmapUtils.compareBitmaps(newWallpaper, originalWallpaper)); 50 51 // Checking setStream() method. 52 wallpaperManager.setStream(BitmapUtils.bitmapToInputStream(referenceWallpaper)); 53 Thread.sleep(WAITING_TIME_MS); 54 newWallpaper = BitmapUtils.getWallpaperBitmap(mContext); 55 assertTrue(BitmapUtils.compareBitmaps(newWallpaper, originalWallpaper)); 56 57 // Checking setResource() method. 58 wallpaperManager.setResource(R.raw.wallpaper); 59 Thread.sleep(WAITING_TIME_MS); 60 newWallpaper = BitmapUtils.getWallpaperBitmap(mContext); 61 assertTrue(BitmapUtils.compareBitmaps(newWallpaper, originalWallpaper)); 62 } 63 } 64