1 /*
2  * Copyright (C) 2022 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 distributed under the
11  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12  * KIND, either express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 package android.platform.uiautomator_helpers
16 
17 import android.os.Build
18 import java.time.Duration
19 
20 private const val CUTTLEFISH = "cutf_cvm"
21 private const val CUTTLEFISH_FACTOR = 5L
22 
23 /** Platform-dependent duration utils (specifically targeting Cuttlefish)
24  *  For physical (non-emulator) devices, the timeout is unchanged,
25  *  the if the Build.HARDWARE is Cuttlefish, we increase the factor by 5.
26  */
27 object DurationUtils {
28 
29     /**
30      * For non-cuttlefish platforms, leave the timeout unchanged, otherwise
31      * increase the delay to compensate for slower performance.
32      */
platformAdjustnull33     fun Duration.platformAdjust() =
34         if (Build.HARDWARE == CUTTLEFISH)
35 	    this.multipliedBy(CUTTLEFISH_FACTOR)
36         else
37 	    this
38 }
39