• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define DEBUG false  // STOPSHIP if true
18 #include "Log.h"
19 
20 #include <android/os/IIncidentManager.h>
21 #include <android/os/IncidentReportArgs.h>
22 #include <binder/IServiceManager.h>
23 
24 #include "external/Perfetto.h"
25 #include "frameworks/base/libs/incident/proto/android/os/header.pb.h"
26 #include "subscriber/IncidentdReporter.h"
27 #include "subscriber/SubscriberReporter.h"
28 
29 namespace android {
30 namespace os {
31 namespace statsd {
32 
triggerSubscribers(const int64_t rule_id,const MetricDimensionKey & dimensionKey,const ConfigKey & configKey,const std::vector<Subscription> & subscriptions)33 void triggerSubscribers(const int64_t rule_id,
34                         const MetricDimensionKey& dimensionKey,
35                         const ConfigKey& configKey,
36                         const std::vector<Subscription>& subscriptions) {
37     VLOG("informSubscribers called.");
38     if (subscriptions.empty()) {
39         VLOG("No Subscriptions were associated.");
40         return;
41     }
42 
43     for (const Subscription& subscription : subscriptions) {
44         if (subscription.probability_of_informing() < 1
45                 && ((float)rand() / RAND_MAX) >= subscription.probability_of_informing()) {
46             // Note that due to float imprecision, 0.0 and 1.0 might not truly mean never/always.
47             // The config writer was advised to use -0.1 and 1.1 for never/always.
48             ALOGI("Fate decided that a subscriber would not be informed.");
49             continue;
50         }
51         switch (subscription.subscriber_information_case()) {
52             case Subscription::SubscriberInformationCase::kIncidentdDetails:
53                 if (!GenerateIncidentReport(subscription.incidentd_details(), rule_id, configKey)) {
54                     ALOGW("Failed to generate incident report.");
55                 }
56                 break;
57             case Subscription::SubscriberInformationCase::kPerfettoDetails:
58                 if (!CollectPerfettoTraceAndUploadToDropbox(subscription.perfetto_details(),
59                                                             rule_id, configKey)) {
60                     ALOGW("Failed to generate perfetto traces.");
61                 }
62                 break;
63             case Subscription::SubscriberInformationCase::kBroadcastSubscriberDetails:
64                 SubscriberReporter::getInstance().alertBroadcastSubscriber(configKey, subscription,
65                                                                            dimensionKey);
66                 break;
67             default:
68                 break;
69         }
70     }
71 }
72 
73 
74 }  // namespace statsd
75 }  // namespace os
76 }  // namespace android
77