1 /*
2  * Copyright (C) 2021 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 
17 package com.android.server.tare;
18 
19 import android.annotation.IntDef;
20 import android.util.IndentingPrintWriter;
21 
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 
25 /**
26  * Base class of a modifier that can affect end pricing.
27  */
28 abstract class Modifier {
29     static final int COST_MODIFIER_CHARGING = 0;
30     static final int COST_MODIFIER_DEVICE_IDLE = 1;
31     static final int COST_MODIFIER_POWER_SAVE_MODE = 2;
32     static final int COST_MODIFIER_PROCESS_STATE = 3;
33     static final int NUM_COST_MODIFIERS = COST_MODIFIER_PROCESS_STATE + 1;
34 
35     @IntDef({
36             COST_MODIFIER_CHARGING,
37             COST_MODIFIER_DEVICE_IDLE,
38             COST_MODIFIER_POWER_SAVE_MODE,
39             COST_MODIFIER_PROCESS_STATE,
40     })
41     @Retention(RetentionPolicy.SOURCE)
42     public @interface CostModifier {
43     }
44 
45     /**
46      * Returns a modified cost to produce based on the modifier's state.
47      *
48      * @param ctp Current cost to produce
49      */
getModifiedCostToProduce(long ctp)50     long getModifiedCostToProduce(long ctp) {
51         return ctp;
52     }
53 
54     /**
55      * Returns a modified price based on the modifier's state.
56      *
57      * @param price Current price
58      */
getModifiedPrice(long price)59     long getModifiedPrice(long price) {
60         return price;
61     }
62 
setup()63     void setup() {
64     }
65 
tearDown()66     void tearDown() {
67     }
68 
dump(IndentingPrintWriter pw)69     abstract void dump(IndentingPrintWriter pw);
70 }
71