1 /*
2  * Copyright (C) 2018 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.powermodel;
18 
19 import java.util.HashMap;
20 
21 import com.google.common.collect.ImmutableCollection;
22 import com.google.common.collect.ImmutableMap;
23 import com.google.common.collect.ImmutableSet;
24 
25 public class AppActivity extends AppInfo {
26 
27     private ImmutableMap<Component, ComponentActivity> mComponents;
28     // TODO: power rails
29     // private ImmutableMap<Component, PowerRailActivity> mRails;
30 
AppActivity()31     private AppActivity() {
32     }
33 
34     /**
35      * Returns the {@link ComponentActivity} for the {@link Component} provided,
36      * or null if this AppActivity does not have that component.
37      * @more
38      * If there is no ComponentActivity for a particular Component, then
39      * there was no usage associated with that app for the app in question.
40      */
getComponentActivity(Component component)41     public ComponentActivity getComponentActivity(Component component) {
42         return mComponents.get(component);
43     }
44 
getComponents()45     public ImmutableSet<Component> getComponents() {
46         return mComponents.keySet();
47     }
48 
getComponentActivities()49     public ImmutableMap<Component,ComponentActivity> getComponentActivities() {
50         return mComponents;
51     }
52 
53     // TODO: power rails
54     // public ComponentActivity getPowerRail(Component component) {
55     //     return mComponents.get(component);
56     // }
57     //
58     // public Set<Component> getPowerRails() {
59     //     return mComponents.keySet();
60     // }
61 
62     public static class Builder extends AppInfo.Builder<AppActivity> {
63         private HashMap<Component, ComponentActivity> mComponents = new HashMap();
64         // TODO power rails.
65 
Builder()66         public Builder() {
67         }
68 
build()69         public AppActivity build() {
70             final AppActivity result = new AppActivity();
71             init(result);
72             result.mComponents = ImmutableMap.copyOf(mComponents);
73             return result;
74         }
75 
addComponentActivity(Component component, ComponentActivity activity)76         public void addComponentActivity(Component component, ComponentActivity activity) {
77             mComponents.put(component, activity);
78         }
79     }
80 }
81