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.device.DeviceNotAvailableException;
     21 import com.android.tradefed.device.ITestDevice;
     22 
     23 import java.util.ArrayList;
     24 import java.util.Collection;
     25 
     26 /** A {@link ITargetPreparer} that stops services on the device. */
     27 public class StopServicesSetup extends BaseTargetPreparer {
     28 
     29     @Option(name = "stop-framework", description = "stop the framework. Default true.")
     30     private boolean mStopFramework = true;
     31 
     32     @Option(name = "service", description = "the service to stop on the device. Can be repeated.")
     33     private Collection<String> mServices = new ArrayList<String>();
     34 
     35     /**
     36      * {@inheritDoc}
     37      */
     38     @Override
     39     public void setUp(ITestDevice device, IBuildInfo buildInfo) throws DeviceNotAvailableException {
     40         if (mStopFramework) {
     41             device.executeShellCommand("stop");
     42         }
     43 
     44         for (String service : mServices) {
     45             device.executeShellCommand(String.format("stop %s", service));
     46         }
     47     }
     48 
     49     /**
     50      * Specify whether to stop the framework.
     51      */
     52     public void setStopFramework(boolean stopFramework) {
     53         mStopFramework = stopFramework;
     54     }
     55 
     56     /**
     57      * Adds a service to the list of services.
     58      */
     59     public void addService(String service) {
     60         mServices.add(service);
     61     }
     62 }
     63