blob: 2e6edfef556e23bcda6afcc357d11f99cc6888f3 [file] [log] [blame]
Joe Onorato9fc9edf2017-10-15 20:08:52 -07001/*
2 * Copyright (C) 2017 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#include "config/ConfigManager.h"
18
19#include "stats_util.h"
20
21#include <vector>
22
23#include <stdio.h>
24
25namespace android {
26namespace os {
27namespace statsd {
28
29static StatsdConfig build_fake_config();
30
31ConfigManager::ConfigManager() {
32}
33
34ConfigManager::~ConfigManager() {
35}
36
37void ConfigManager::Startup() {
38 // TODO: Implement me -- read from storage and call onto all of the listeners.
39 // Instead, we'll just make a fake one.
40
41 // this should be called from StatsService when it receives a statsd_config
Yao Chen7ee94152017-11-17 09:44:40 -080042 UpdateConfig(ConfigKey(1000, "fake"), build_fake_config());
Joe Onorato9fc9edf2017-10-15 20:08:52 -070043}
44
45void ConfigManager::AddListener(const sp<ConfigListener>& listener) {
46 mListeners.push_back(listener);
47}
48
49void ConfigManager::UpdateConfig(const ConfigKey& key, const StatsdConfig& config) {
50 // Add to map
51 mConfigs[key] = config;
52 // Why doesn't this work? mConfigs.insert({key, config});
53
54 // Save to disk
55 update_saved_configs();
56
57 // Tell everyone
58 for (auto& listener : mListeners) {
59 listener->OnConfigUpdated(key, config);
60 }
61}
62
David Chenadaf8b32017-11-03 15:42:08 -070063void ConfigManager::SetConfigReceiver(const ConfigKey& key, const string& pkg, const string& cls) {
64 mConfigReceivers[key] = pair<string, string>(pkg, cls);
65}
66
67void ConfigManager::RemoveConfigReceiver(const ConfigKey& key) {
68 mConfigReceivers.erase(key);
69}
70
Joe Onorato9fc9edf2017-10-15 20:08:52 -070071void ConfigManager::RemoveConfig(const ConfigKey& key) {
72 unordered_map<ConfigKey, StatsdConfig>::iterator it = mConfigs.find(key);
73 if (it != mConfigs.end()) {
74 // Remove from map
75 mConfigs.erase(it);
76
77 // Save to disk
78 update_saved_configs();
79
80 // Tell everyone
81 for (auto& listener : mListeners) {
82 listener->OnConfigRemoved(key);
83 }
84 }
85 // If we didn't find it, just quietly ignore it.
86}
87
88void ConfigManager::RemoveConfigs(int uid) {
89 vector<ConfigKey> removed;
90
91 for (auto it = mConfigs.begin(); it != mConfigs.end();) {
92 // Remove from map
93 if (it->first.GetUid() == uid) {
94 removed.push_back(it->first);
95 it = mConfigs.erase(it);
David Chenadaf8b32017-11-03 15:42:08 -070096 mConfigReceivers.erase(it->first);
Joe Onorato9fc9edf2017-10-15 20:08:52 -070097 } else {
98 it++;
99 }
100 }
101
102 // Remove separately so if they do anything in the callback they can't mess up our iteration.
103 for (auto& key : removed) {
104 // Tell everyone
105 for (auto& listener : mListeners) {
106 listener->OnConfigRemoved(key);
107 }
108 }
109}
110
111void ConfigManager::Dump(FILE* out) {
112 fprintf(out, "CONFIGURATIONS (%d)\n", (int)mConfigs.size());
113 fprintf(out, " uid name\n");
114 for (unordered_map<ConfigKey, StatsdConfig>::const_iterator it = mConfigs.begin();
115 it != mConfigs.end(); it++) {
116 fprintf(out, " %6d %s\n", it->first.GetUid(), it->first.GetName().c_str());
117 // TODO: Print the contents of the config too.
118 }
119}
120
121void ConfigManager::update_saved_configs() {
122 // TODO: Implement me -- write to disk.
123}
124
125static StatsdConfig build_fake_config() {
126 // HACK: Hard code a test metric for counting screen on events...
127 StatsdConfig config;
Yangster-macd1815dc2017-11-13 21:43:15 -0800128 config.set_name("12345");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700129
Yao Chen5154a3792017-10-30 22:57:06 -0700130 int WAKE_LOCK_TAG_ID = 1111; // put a fake id here to make testing easier.
Yao Chen729093d2017-10-16 10:33:26 -0700131 int WAKE_LOCK_UID_KEY_ID = 1;
Yao Chen5154a3792017-10-30 22:57:06 -0700132 int WAKE_LOCK_NAME_KEY = 3;
133 int WAKE_LOCK_STATE_KEY = 4;
Yao Chen729093d2017-10-16 10:33:26 -0700134 int WAKE_LOCK_ACQUIRE_VALUE = 1;
135 int WAKE_LOCK_RELEASE_VALUE = 0;
136
137 int APP_USAGE_ID = 12345;
138 int APP_USAGE_UID_KEY_ID = 1;
139 int APP_USAGE_STATE_KEY = 2;
140 int APP_USAGE_FOREGROUND = 1;
141 int APP_USAGE_BACKGROUND = 0;
142
Bookatzc1a050a2017-10-10 15:49:28 -0700143 int SCREEN_EVENT_TAG_ID = 29;
Yao Chen729093d2017-10-16 10:33:26 -0700144 int SCREEN_EVENT_STATE_KEY = 1;
145 int SCREEN_EVENT_ON_VALUE = 2;
146 int SCREEN_EVENT_OFF_VALUE = 1;
147
Bookatzc1a050a2017-10-10 15:49:28 -0700148 int UID_PROCESS_STATE_TAG_ID = 27;
Yao Chen729093d2017-10-16 10:33:26 -0700149 int UID_PROCESS_STATE_UID_KEY = 1;
150
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700151 int KERNEL_WAKELOCK_TAG_ID = 1004;
Chenjie Yub3dda412017-10-24 13:41:59 -0700152 int KERNEL_WAKELOCK_NAME_KEY = 4;
153
Yangster1d4d6862017-10-31 12:58:51 -0700154 int DEVICE_TEMPERATURE_TAG_ID = 33;
155 int DEVICE_TEMPERATURE_KEY = 1;
156
Yao Chen729093d2017-10-16 10:33:26 -0700157 // Count Screen ON events.
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700158 CountMetric* metric = config.add_count_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800159 metric->set_name("1");
Yao Chen729093d2017-10-16 10:33:26 -0700160 metric->set_what("SCREEN_TURNED_ON");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700161 metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
162
Bookatzd3606c72017-10-19 10:13:49 -0700163 // Anomaly threshold for screen-on count.
Yangster-macd1815dc2017-11-13 21:43:15 -0800164 Alert* alert = config.add_alerts();
165 alert->set_name("1");
Bookatzd3606c72017-10-19 10:13:49 -0700166 alert->set_number_of_buckets(6);
167 alert->set_trigger_if_sum_gt(10);
168 alert->set_refractory_period_secs(30);
169
Yao Chen729093d2017-10-16 10:33:26 -0700170 // Count process state changes, slice by uid.
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700171 metric = config.add_count_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800172 metric->set_name("2");
Yao Chen729093d2017-10-16 10:33:26 -0700173 metric->set_what("PROCESS_STATE_CHANGE");
174 metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
175 KeyMatcher* keyMatcher = metric->add_dimension();
176 keyMatcher->set_key(UID_PROCESS_STATE_UID_KEY);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700177
Yang Lu3eba6212017-10-25 19:54:45 -0700178 // Anomaly threshold for background count.
Yangster-macd1815dc2017-11-13 21:43:15 -0800179 alert = config.add_alerts();
180 alert->set_name("2");
Yang Lu3eba6212017-10-25 19:54:45 -0700181 alert->set_number_of_buckets(4);
182 alert->set_trigger_if_sum_gt(30);
183 alert->set_refractory_period_secs(20);
184
Yao Chen729093d2017-10-16 10:33:26 -0700185 // Count process state changes, slice by uid, while SCREEN_IS_OFF
186 metric = config.add_count_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800187 metric->set_name("3");
Yao Chen729093d2017-10-16 10:33:26 -0700188 metric->set_what("PROCESS_STATE_CHANGE");
189 metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
190 keyMatcher = metric->add_dimension();
191 keyMatcher->set_key(UID_PROCESS_STATE_UID_KEY);
192 metric->set_condition("SCREEN_IS_OFF");
193
Yao Chen5110bed2017-10-23 12:50:02 -0700194 // Count wake lock, slice by uid, while SCREEN_IS_ON and app in background
Yao Chen729093d2017-10-16 10:33:26 -0700195 metric = config.add_count_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800196 metric->set_name("4");
Yao Chen729093d2017-10-16 10:33:26 -0700197 metric->set_what("APP_GET_WL");
198 metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
199 keyMatcher = metric->add_dimension();
200 keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID);
201 metric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
202 EventConditionLink* link = metric->add_links();
203 link->set_condition("APP_IS_BACKGROUND");
204 link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
205 link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
206
Yao Chen5154a3792017-10-30 22:57:06 -0700207 // Duration of an app holding any wl, while screen on and app in background, slice by uid
Yao Chen729093d2017-10-16 10:33:26 -0700208 DurationMetric* durationMetric = config.add_duration_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800209 durationMetric->set_name("5");
Yao Chen729093d2017-10-16 10:33:26 -0700210 durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
211 durationMetric->set_type(DurationMetric_AggregationType_DURATION_SUM);
212 keyMatcher = durationMetric->add_dimension();
213 keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID);
Yao Chen967b2052017-11-07 16:36:43 -0800214 durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
Yao Chen5c925ad2017-11-15 14:15:46 -0800215 durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
Yao Chen729093d2017-10-16 10:33:26 -0700216 link = durationMetric->add_links();
217 link->set_condition("APP_IS_BACKGROUND");
218 link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
219 link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
220
Yao Chen5154a3792017-10-30 22:57:06 -0700221 // max Duration of an app holding any wl, while screen on and app in background, slice by uid
222 durationMetric = config.add_duration_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800223 durationMetric->set_name("6");
Yao Chen5154a3792017-10-30 22:57:06 -0700224 durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
225 durationMetric->set_type(DurationMetric_AggregationType_DURATION_MAX_SPARSE);
226 keyMatcher = durationMetric->add_dimension();
227 keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID);
Yao Chen967b2052017-11-07 16:36:43 -0800228 durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
Yao Chen5c925ad2017-11-15 14:15:46 -0800229 durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
Yao Chen5154a3792017-10-30 22:57:06 -0700230 link = durationMetric->add_links();
231 link->set_condition("APP_IS_BACKGROUND");
232 link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
233 link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
234
235 // Duration of an app holding any wl, while screen on and app in background
236 durationMetric = config.add_duration_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800237 durationMetric->set_name("7");
Yao Chen5154a3792017-10-30 22:57:06 -0700238 durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
239 durationMetric->set_type(DurationMetric_AggregationType_DURATION_MAX_SPARSE);
Yao Chen967b2052017-11-07 16:36:43 -0800240 durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
Yao Chen5c925ad2017-11-15 14:15:46 -0800241 durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
Yao Chen5154a3792017-10-30 22:57:06 -0700242 link = durationMetric->add_links();
243 link->set_condition("APP_IS_BACKGROUND");
244 link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
245 link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
246
247 // Duration of screen on time.
248 durationMetric = config.add_duration_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800249 durationMetric->set_name("8");
Yangster1d4d6862017-10-31 12:58:51 -0700250 durationMetric->mutable_bucket()->set_bucket_size_millis(10 * 1000L);
Yao Chen5154a3792017-10-30 22:57:06 -0700251 durationMetric->set_type(DurationMetric_AggregationType_DURATION_SUM);
252 durationMetric->set_what("SCREEN_IS_ON");
253
Chenjie Yub3dda412017-10-24 13:41:59 -0700254 // Value metric to count KERNEL_WAKELOCK when screen turned on
255 ValueMetric* valueMetric = config.add_value_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800256 valueMetric->set_name("6");
Chenjie Yub3dda412017-10-24 13:41:59 -0700257 valueMetric->set_what("KERNEL_WAKELOCK");
258 valueMetric->set_value_field(1);
259 valueMetric->set_condition("SCREEN_IS_ON");
260 keyMatcher = valueMetric->add_dimension();
261 keyMatcher->set_key(KERNEL_WAKELOCK_NAME_KEY);
262 // This is for testing easier. We should never set bucket size this small.
263 valueMetric->mutable_bucket()->set_bucket_size_millis(60 * 1000L);
264
Yao Chen5110bed2017-10-23 12:50:02 -0700265 // Add an EventMetric to log process state change events.
266 EventMetric* eventMetric = config.add_event_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800267 eventMetric->set_name("9");
Yao Chen5110bed2017-10-23 12:50:02 -0700268 eventMetric->set_what("SCREEN_TURNED_ON");
269
Yangster1d4d6862017-10-31 12:58:51 -0700270 // Add an GaugeMetric.
271 GaugeMetric* gaugeMetric = config.add_gauge_metric();
Yangster-macd1815dc2017-11-13 21:43:15 -0800272 gaugeMetric->set_name("10");
Yangster1d4d6862017-10-31 12:58:51 -0700273 gaugeMetric->set_what("DEVICE_TEMPERATURE");
274 gaugeMetric->set_gauge_field(DEVICE_TEMPERATURE_KEY);
275 gaugeMetric->mutable_bucket()->set_bucket_size_millis(60 * 1000L);
276
Yao Chen729093d2017-10-16 10:33:26 -0700277 // Event matchers............
Yangster1d4d6862017-10-31 12:58:51 -0700278 LogEntryMatcher* temperatureEntryMatcher = config.add_log_entry_matcher();
279 temperatureEntryMatcher->set_name("DEVICE_TEMPERATURE");
280 temperatureEntryMatcher->mutable_simple_log_entry_matcher()->set_tag(
281 DEVICE_TEMPERATURE_TAG_ID);
282
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700283 LogEntryMatcher* eventMatcher = config.add_log_entry_matcher();
Yao Chen729093d2017-10-16 10:33:26 -0700284 eventMatcher->set_name("SCREEN_TURNED_ON");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700285 SimpleLogEntryMatcher* simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
Yao Chen729093d2017-10-16 10:33:26 -0700286 simpleLogEntryMatcher->set_tag(SCREEN_EVENT_TAG_ID);
287 KeyValueMatcher* keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
288 keyValueMatcher->mutable_key_matcher()->set_key(SCREEN_EVENT_STATE_KEY);
289 keyValueMatcher->set_eq_int(SCREEN_EVENT_ON_VALUE);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700290
291 eventMatcher = config.add_log_entry_matcher();
Yao Chen729093d2017-10-16 10:33:26 -0700292 eventMatcher->set_name("SCREEN_TURNED_OFF");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700293 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
Yao Chen729093d2017-10-16 10:33:26 -0700294 simpleLogEntryMatcher->set_tag(SCREEN_EVENT_TAG_ID);
295 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
296 keyValueMatcher->mutable_key_matcher()->set_key(SCREEN_EVENT_STATE_KEY);
297 keyValueMatcher->set_eq_int(SCREEN_EVENT_OFF_VALUE);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700298
Yao Chen729093d2017-10-16 10:33:26 -0700299 eventMatcher = config.add_log_entry_matcher();
300 eventMatcher->set_name("PROCESS_STATE_CHANGE");
301 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
302 simpleLogEntryMatcher->set_tag(UID_PROCESS_STATE_TAG_ID);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700303
Yao Chen729093d2017-10-16 10:33:26 -0700304 eventMatcher = config.add_log_entry_matcher();
305 eventMatcher->set_name("APP_GOES_BACKGROUND");
306 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
307 simpleLogEntryMatcher->set_tag(APP_USAGE_ID);
308 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
309 keyValueMatcher->mutable_key_matcher()->set_key(APP_USAGE_STATE_KEY);
310 keyValueMatcher->set_eq_int(APP_USAGE_BACKGROUND);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700311
Yao Chen729093d2017-10-16 10:33:26 -0700312 eventMatcher = config.add_log_entry_matcher();
313 eventMatcher->set_name("APP_GOES_FOREGROUND");
314 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
315 simpleLogEntryMatcher->set_tag(APP_USAGE_ID);
316 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
317 keyValueMatcher->mutable_key_matcher()->set_key(APP_USAGE_STATE_KEY);
318 keyValueMatcher->set_eq_int(APP_USAGE_FOREGROUND);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700319
Yao Chen729093d2017-10-16 10:33:26 -0700320 eventMatcher = config.add_log_entry_matcher();
321 eventMatcher->set_name("APP_GET_WL");
322 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
323 simpleLogEntryMatcher->set_tag(WAKE_LOCK_TAG_ID);
324 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
325 keyValueMatcher->mutable_key_matcher()->set_key(WAKE_LOCK_STATE_KEY);
326 keyValueMatcher->set_eq_int(WAKE_LOCK_ACQUIRE_VALUE);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700327
Yao Chen729093d2017-10-16 10:33:26 -0700328 eventMatcher = config.add_log_entry_matcher();
329 eventMatcher->set_name("APP_RELEASE_WL");
330 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
331 simpleLogEntryMatcher->set_tag(WAKE_LOCK_TAG_ID);
332 keyValueMatcher = simpleLogEntryMatcher->add_key_value_matcher();
333 keyValueMatcher->mutable_key_matcher()->set_key(WAKE_LOCK_STATE_KEY);
334 keyValueMatcher->set_eq_int(WAKE_LOCK_RELEASE_VALUE);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700335
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700336 // pulled events
337 eventMatcher = config.add_log_entry_matcher();
338 eventMatcher->set_name("KERNEL_WAKELOCK");
339 simpleLogEntryMatcher = eventMatcher->mutable_simple_log_entry_matcher();
340 simpleLogEntryMatcher->set_tag(KERNEL_WAKELOCK_TAG_ID);
341
Yao Chen729093d2017-10-16 10:33:26 -0700342 // Conditions.............
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700343 Condition* condition = config.add_condition();
344 condition->set_name("SCREEN_IS_ON");
345 SimpleCondition* simpleCondition = condition->mutable_simple_condition();
Yao Chen729093d2017-10-16 10:33:26 -0700346 simpleCondition->set_start("SCREEN_TURNED_ON");
347 simpleCondition->set_stop("SCREEN_TURNED_OFF");
Yao Chen967b2052017-11-07 16:36:43 -0800348 simpleCondition->set_count_nesting(false);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700349
350 condition = config.add_condition();
351 condition->set_name("SCREEN_IS_OFF");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700352 simpleCondition = condition->mutable_simple_condition();
Yao Chen729093d2017-10-16 10:33:26 -0700353 simpleCondition->set_start("SCREEN_TURNED_OFF");
354 simpleCondition->set_stop("SCREEN_TURNED_ON");
Yao Chen967b2052017-11-07 16:36:43 -0800355 simpleCondition->set_count_nesting(false);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700356
357 condition = config.add_condition();
Yao Chen729093d2017-10-16 10:33:26 -0700358 condition->set_name("APP_IS_BACKGROUND");
359 simpleCondition = condition->mutable_simple_condition();
360 simpleCondition->set_start("APP_GOES_BACKGROUND");
361 simpleCondition->set_stop("APP_GOES_FOREGROUND");
Yao Chen5154a3792017-10-30 22:57:06 -0700362 KeyMatcher* condition_dimension1 = simpleCondition->add_dimension();
363 condition_dimension1->set_key(APP_USAGE_UID_KEY_ID);
Yao Chen967b2052017-11-07 16:36:43 -0800364 simpleCondition->set_count_nesting(false);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700365
366 condition = config.add_condition();
Yao Chen729093d2017-10-16 10:33:26 -0700367 condition->set_name("APP_IS_BACKGROUND_AND_SCREEN_ON");
368 Condition_Combination* combination_condition = condition->mutable_combination();
369 combination_condition->set_operation(LogicalOperation::AND);
370 combination_condition->add_condition("APP_IS_BACKGROUND");
371 combination_condition->add_condition("SCREEN_IS_ON");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700372
Yao Chen5154a3792017-10-30 22:57:06 -0700373 condition = config.add_condition();
Yao Chen967b2052017-11-07 16:36:43 -0800374 condition->set_name("WL_HELD_PER_APP_PER_NAME");
Yao Chen5154a3792017-10-30 22:57:06 -0700375 simpleCondition = condition->mutable_simple_condition();
376 simpleCondition->set_start("APP_GET_WL");
377 simpleCondition->set_stop("APP_RELEASE_WL");
378 KeyMatcher* condition_dimension = simpleCondition->add_dimension();
379 condition_dimension->set_key(WAKE_LOCK_UID_KEY_ID);
380 condition_dimension = simpleCondition->add_dimension();
381 condition_dimension->set_key(WAKE_LOCK_NAME_KEY);
Yao Chen967b2052017-11-07 16:36:43 -0800382 simpleCondition->set_count_nesting(true);
383
384 condition = config.add_condition();
385 condition->set_name("WL_HELD_PER_APP");
386 simpleCondition = condition->mutable_simple_condition();
387 simpleCondition->set_start("APP_GET_WL");
388 simpleCondition->set_stop("APP_RELEASE_WL");
389 simpleCondition->set_initial_value(SimpleCondition_InitialValue_FALSE);
390 condition_dimension = simpleCondition->add_dimension();
391 condition_dimension->set_key(WAKE_LOCK_UID_KEY_ID);
392 simpleCondition->set_count_nesting(true);
Yao Chen5154a3792017-10-30 22:57:06 -0700393
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700394 return config;
395}
396
397} // namespace statsd
398} // namespace os
399} // namespace android