1 /*
2  * Copyright (C) 2019 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.cts.net.hostside;
17 
18 import static com.android.cts.net.hostside.NetworkPolicyTestUtils.canChangeActiveNetworkMeteredness;
19 import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isActiveNetworkMetered;
20 import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isAppStandbySupported;
21 import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isBatterySaverSupported;
22 import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isDataSaverSupported;
23 import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isDozeModeSupported;
24 import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isLowRamDevice;
25 
26 public enum Property {
27     BATTERY_SAVER_MODE(1 << 0) {
isSupported()28         public boolean isSupported() { return isBatterySaverSupported(); }
29     },
30 
31     DATA_SAVER_MODE(1 << 1) {
isSupported()32         public boolean isSupported() { return isDataSaverSupported(); }
33     },
34 
~DATA_SAVER_MODE.getValue()35     NO_DATA_SAVER_MODE(~DATA_SAVER_MODE.getValue()) {
36         public boolean isSupported() { return !isDataSaverSupported(); }
37     },
38 
39     DOZE_MODE(1 << 2) {
isSupported()40         public boolean isSupported() { return isDozeModeSupported(); }
41     },
42 
43     APP_STANDBY_MODE(1 << 3) {
isSupported()44         public boolean isSupported() { return isAppStandbySupported(); }
45     },
46 
47     NOT_LOW_RAM_DEVICE(1 << 4) {
isSupported()48         public boolean isSupported() { return !isLowRamDevice(); }
49     },
50 
51     METERED_NETWORK(1 << 5) {
isSupported()52         public boolean isSupported() {
53             return isActiveNetworkMetered(true) || canChangeActiveNetworkMeteredness();
54         }
55     },
56 
~METERED_NETWORK.getValue()57     NON_METERED_NETWORK(~METERED_NETWORK.getValue()) {
58         public boolean isSupported() {
59             return isActiveNetworkMetered(false) || canChangeActiveNetworkMeteredness();
60         }
61     };
62 
63     private int mValue;
64 
Property(int value)65     Property(int value) { mValue = value; }
66 
getValue()67     public int getValue() { return mValue; }
68 
isSupported()69     abstract boolean isSupported();
70 }
71