Home | History | Annotate | Download | only in targetprep
      1 /*
      2  * Copyright (C) 2012 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.tradefed.targetprep;
     17 
     18 import com.android.tradefed.build.IBuildInfo;
     19 import com.android.tradefed.config.Option;
     20 import com.android.tradefed.config.OptionClass;
     21 import com.android.tradefed.device.DeviceNotAvailableException;
     22 import com.android.tradefed.device.ITestDevice;
     23 
     24 import java.util.ArrayList;
     25 import java.util.Collection;
     26 
     27 /** A {@link ITargetPreparer} that wipes user data on the device. */
     28 @OptionClass(alias = "erase-user-data")
     29 public class EraseUserDataPreparer extends BaseTargetPreparer {
     30 
     31     @Option(name="wipe-skip-list", description=
     32             "list of /data subdirectories to NOT wipe when doing UserDataFlashOption.TESTS_ZIP")
     33         private Collection<String> mDataWipeSkipList = new ArrayList<String>();
     34 
     35     @Option(name="wait-for-available",
     36             description="Wait until device is available for testing before performing erase")
     37     private boolean mWaitForAvailable = false;
     38 
     39     private ITestsZipInstaller mTestsZipInstaller = null;
     40 
     41     /**
     42      * {@inheritDoc}
     43      */
     44     @Override
     45     public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
     46             BuildError, DeviceNotAvailableException {
     47         if (isDisabled()) {
     48             return;
     49         }
     50         if (mWaitForAvailable) {
     51             device.waitForDeviceAvailable();
     52         }
     53 
     54         device.enableAdbRoot();
     55         if (mTestsZipInstaller == null) {
     56             if (mDataWipeSkipList.isEmpty()) {
     57                 // Maintain backwards compatibility
     58                 // TODO: deprecate and remove
     59                 mDataWipeSkipList.add("media");
     60             }
     61             mTestsZipInstaller = new DefaultTestsZipInstaller(mDataWipeSkipList);
     62         }
     63         mTestsZipInstaller.deleteData(device);
     64         device.reboot();
     65     }
     66 }
     67