| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 17 | #define DEBUG false  // STOPSHIP if true | 
| Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 18 | #include "Log.h" | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 19 |  | 
| Salud Lemus | f63fa89 | 2020-08-12 00:56:58 +0000 | [diff] [blame] | 20 | #include "SimpleAtomMatchingTracker.h" | 
| Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 21 |  | 
| Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 22 | namespace android { | 
|  | 23 | namespace os { | 
|  | 24 | namespace statsd { | 
|  | 25 |  | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 26 | using std::unordered_map; | 
|  | 27 | using std::vector; | 
|  | 28 |  | 
| Salud Lemus | f63fa89 | 2020-08-12 00:56:58 +0000 | [diff] [blame] | 29 | SimpleAtomMatchingTracker::SimpleAtomMatchingTracker(const int64_t& id, const int index, | 
|  | 30 | const uint64_t protoHash, | 
|  | 31 | const SimpleAtomMatcher& matcher, | 
|  | 32 | const sp<UidMap>& uidMap) | 
|  | 33 | : AtomMatchingTracker(id, index, protoHash), mMatcher(matcher), mUidMap(uidMap) { | 
| Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 34 | if (!matcher.has_atom_id()) { | 
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 35 | mInitialized = false; | 
|  | 36 | } else { | 
| Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 37 | mAtomIds.insert(matcher.atom_id()); | 
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 38 | mInitialized = true; | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 39 | } | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 40 | } | 
|  | 41 |  | 
| Salud Lemus | f63fa89 | 2020-08-12 00:56:58 +0000 | [diff] [blame] | 42 | SimpleAtomMatchingTracker::~SimpleAtomMatchingTracker() { | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 43 | } | 
|  | 44 |  | 
| Salud Lemus | f63fa89 | 2020-08-12 00:56:58 +0000 | [diff] [blame] | 45 | bool SimpleAtomMatchingTracker::init(const vector<AtomMatcher>& allAtomMatchers, | 
|  | 46 | const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers, | 
|  | 47 | const unordered_map<int64_t, int>& matcherMap, | 
|  | 48 | vector<bool>& stack) { | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 49 | // no need to do anything. | 
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 50 | return mInitialized; | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 51 | } | 
|  | 52 |  | 
| Tej Singh | 090ffd7 | 2020-08-17 20:27:17 -0700 | [diff] [blame] | 53 | bool SimpleAtomMatchingTracker::onConfigUpdated( | 
|  | 54 | const AtomMatcher& matcher, const int index, | 
|  | 55 | const unordered_map<int64_t, int>& atomMatchingTrackerMap) { | 
|  | 56 | mIndex = index; | 
|  | 57 | // Do not need to update mMatcher since the matcher must be identical across the update. | 
|  | 58 | return mInitialized; | 
|  | 59 | } | 
|  | 60 |  | 
| Salud Lemus | f63fa89 | 2020-08-12 00:56:58 +0000 | [diff] [blame] | 61 | void SimpleAtomMatchingTracker::onLogEvent( | 
|  | 62 | const LogEvent& event, const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers, | 
|  | 63 | vector<MatchingState>& matcherResults) { | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 64 | if (matcherResults[mIndex] != MatchingState::kNotComputed) { | 
| Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 65 | VLOG("Matcher %lld already evaluated ", (long long)mId); | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 66 | return; | 
|  | 67 | } | 
|  | 68 |  | 
| Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 69 | if (mAtomIds.find(event.GetTagId()) == mAtomIds.end()) { | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 70 | matcherResults[mIndex] = MatchingState::kNotMatched; | 
|  | 71 | return; | 
|  | 72 | } | 
|  | 73 |  | 
| Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 74 | bool matched = matchesSimple(mUidMap, mMatcher, event); | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 75 | matcherResults[mIndex] = matched ? MatchingState::kMatched : MatchingState::kNotMatched; | 
| Salud Lemus | 8d213db | 2020-08-15 02:53:56 +0000 | [diff] [blame] | 76 | VLOG("Stats SimpleAtomMatcher %lld matched? %d", (long long)mId, matched); | 
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 77 | } | 
|  | 78 |  | 
|  | 79 | }  // namespace statsd | 
|  | 80 | }  // namespace os | 
|  | 81 | }  // namespace android |