1 /*
2  * Copyright (C) 2023 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.device.connection;
17 
18 import com.android.tradefed.device.DeviceNotAvailableException;
19 import com.android.tradefed.device.ITestDevice;
20 import com.android.tradefed.targetprep.TargetSetupError;
21 
22 /** Abstract connection representation. */
23 public abstract class AbstractConnection {
24 
25     /**
26      * Initialize the connection of the device.
27      *
28      * @throws TargetSetupError
29      * @throws DeviceNotAvailableException
30      */
initializeConnection()31     public void initializeConnection() throws TargetSetupError, DeviceNotAvailableException {
32         // Empty by default
33     }
34 
35     /** Notify when doAdbReboot is called. */
notifyAdbRebootCalled()36     public void notifyAdbRebootCalled() {
37         // Empty by default
38     }
39 
40     /**
41      * Reconnect the connection to the device.
42      *
43      * @param serial The device serial number.
44      * @throws DeviceNotAvailableException
45      */
reconnect(String serial)46     public void reconnect(String serial) throws DeviceNotAvailableException {
47         // Empty by default
48     }
49 
50     /**
51      * Reconnect the connection to the device for the recovery routine.
52      *
53      * @param serial The device serial number.
54      * @throws DeviceNotAvailableException
55      */
reconnectForRecovery(String serial)56     public void reconnectForRecovery(String serial) throws DeviceNotAvailableException {
57         reconnect(serial);
58     }
59 
60     /** Clean up the connection. */
tearDownConnection()61     public void tearDownConnection() {
62         // Empty by default
63     }
64 
65     /**
66      * Recover the given device with device reset.
67      *
68      * @param device the {@link ITestDevice} is used for device reset handler.
69      * @param snapshotId the snapshotId is used for fetching the correct snapshot to restore.
70      * @param dnae the {@link DeviceNotAvailableException} is existing device not available
71      *     exception.
72      * @throws DeviceNotAvailableException if fail on device recovery.
73      */
recoverVirtualDevice( ITestDevice device, String snapshotId, DeviceNotAvailableException dnae)74     public void recoverVirtualDevice(
75             ITestDevice device, String snapshotId, DeviceNotAvailableException dnae)
76             throws DeviceNotAvailableException {
77         throw dnae;
78     }
79 
80     /**
81      * Snapshot the given device
82      *
83      * @param device the {@link ITestDevice} is used for device snapshot handler.
84      * @param snapshotId the snapshotId is the name of the snapshot that will be saved.
85      * @param dnae the {@link DeviceNotAvailableException} is existing device not available
86      *     exception.
87      * @throws DeviceNotAvailableException if fail on device recovery.
88      */
snapshotDevice(ITestDevice device, String snapshotId)89     public void snapshotDevice(ITestDevice device, String snapshotId)
90             throws DeviceNotAvailableException {
91         // Empty by default
92     }
93 }
94