1 /* 2 * Copyright (C) 2013 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.tradefed.targetprep; 18 19 import com.android.tradefed.build.IBuildInfo; 20 import com.android.tradefed.config.Option; 21 import com.android.tradefed.device.DeviceNotAvailableException; 22 import com.android.tradefed.device.ITestDevice; 23 import com.android.tradefed.log.LogUtil.CLog; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 28 /** 29 * A {@link ITargetPreparer} for removing an apk from the system partition before a test run. Note 30 * that the device is rebooted before actual test execution, so the system partition remains 31 * read-only during the test run. 32 */ 33 public class RemoveSystemAppPreparer extends BaseTargetPreparer { 34 @Option(name = "uninstall-system-app", 35 description = "the name of the file to remove (extension included)") 36 private List<String> mFiles= new ArrayList<String>(); 37 38 /** 39 * {@inheritDoc} 40 */ 41 @Override 42 public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError, 43 DeviceNotAvailableException { 44 45 device.remountSystemWritable(); 46 for (String file : mFiles) { 47 CLog.d("Removing system app %s from /system/app", file); 48 device.executeShellCommand(String.format("rm /system/app/%s", file)); 49 CLog.d("Removing system app %s from /system/priv-app", file); 50 device.executeShellCommand(String.format("rm /system/priv-app/%s", file)); 51 } 52 53 // Reboot the device to put /system back into read-only 54 device.reboot(); 55 device.waitForDeviceAvailable(); 56 } 57 58 } 59 60