1 /*
2  * Copyright (C) 2017 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.config.Option;
19 import com.android.tradefed.config.OptionCopier;
20 
21 /**
22  * Base implementation class for {@link ITargetPreparer} that allows to control whether the object
23  * is disabled or not.
24  */
25 public abstract class BaseTargetPreparer implements ITargetPreparer {
26 
27     private static final String DISABLE_OPTION_NAME = "disable";
28 
29     @Option(name = DISABLE_OPTION_NAME, description = "disables the target preparer")
30     private boolean mDisable = false;
31 
32     private static final String DISABLE_TEARDOWN_OPTION_NAME = "disable-tear-down";
33 
34     @Option(
35         name = DISABLE_TEARDOWN_OPTION_NAME,
36         description = "disables the clean up step of a target cleaner"
37     )
38     private boolean mDisableTearDown = false;
39 
40     /** {@inheritDoc} */
41     @Override
isDisabled()42     public final boolean isDisabled() {
43         return mDisable;
44     }
45 
46     /** {@inheritDoc} */
47     @Override
isTearDownDisabled()48     public final boolean isTearDownDisabled() {
49         return mDisableTearDown;
50     }
51 
52     /** {@inheritDoc} */
53     @Override
setDisable(boolean isDisabled)54     public final void setDisable(boolean isDisabled) {
55         mDisable = isDisabled;
56         // Update the option this way to mark it as modified.
57         OptionCopier.copyOptionsNoThrow(this, this, DISABLE_OPTION_NAME);
58     }
59 
60     /** {@inheritDoc} */
61     @Override
setDisableTearDown(boolean isDisabled)62     public final void setDisableTearDown(boolean isDisabled) {
63         mDisableTearDown = isDisabled;
64         // Update the option this way to mark it as modified.
65         OptionCopier.copyOptionsNoThrow(this, this, DISABLE_TEARDOWN_OPTION_NAME);
66     }
67 }
68