1 /* 2 * Copyright (C) 2014 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 package com.android.cts.managedprofile; 17 18 import android.app.admin.DevicePolicyManager; 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.os.Process; 22 import android.os.UserHandle; 23 import android.os.UserManager; 24 25 import com.android.cts.managedprofile.BaseManagedProfileTest.BasicAdminReceiver; 26 27 import org.junit.Ignore; 28 29 /** 30 * Test wipeData() for use in managed profile. If called from a managed profile, wipeData() should 31 * remove the current managed profile. Also, no erasing of external storage should be allowed. 32 */ 33 public class WipeDataTest extends BaseManagedProfileTest { 34 35 private UserManager mUserManager; 36 37 @Override setUp()38 protected void setUp() throws Exception { 39 super.setUp(); 40 // Make sure we are running in a managed profile, otherwise risk wiping the primary user's 41 // data. 42 assertTrue(mDevicePolicyManager.isAdminActive(ADMIN_RECEIVER_COMPONENT)); 43 assertTrue(mDevicePolicyManager.isProfileOwnerApp(ADMIN_RECEIVER_COMPONENT.getPackageName())); 44 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); 45 } 46 testWipeData()47 public void testWipeData() throws InterruptedException { 48 UserHandle currentUser = Process.myUserHandle(); 49 assertTrue(mUserManager.getUserProfiles().contains(currentUser)); 50 51 mDevicePolicyManager.wipeData(0); 52 53 // ACTION_MANAGED_PROFILE_REMOVED is only sent to parent user. 54 // As a result, we have to poll in order to know when the profile 55 // is actually removed. 56 long epoch = System.currentTimeMillis(); 57 while (System.currentTimeMillis() - epoch <= 10 * 1000) { 58 if (!mUserManager.getUserProfiles().contains(currentUser)) { 59 break; 60 } 61 Thread.sleep(250); 62 } 63 64 // Verify the profile is deleted 65 assertFalse(mUserManager.getUserProfiles().contains(currentUser)); 66 } 67 } 68