| Vova Sharaienko | 3092c96 | 2021-02-01 23:38:12 +0000 | [diff] [blame] | 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 | #define DEBUG false // STOPSHIP if true | 
|  | 18 | #define LOG_TAG "StatsAidl" | 
|  | 19 |  | 
|  | 20 | #include <log/log.h> | 
|  | 21 | #include <statslog.h> | 
|  | 22 |  | 
|  | 23 | #include "StatsAidl.h" | 
|  | 24 |  | 
|  | 25 | namespace aidl { | 
|  | 26 | namespace android { | 
|  | 27 | namespace frameworks { | 
|  | 28 | namespace stats { | 
|  | 29 |  | 
|  | 30 | StatsHal::StatsHal() {} | 
|  | 31 |  | 
|  | 32 | ndk::ScopedAStatus StatsHal::reportVendorAtom(const VendorAtom& vendorAtom) { | 
|  | 33 | std::string reverseDomainName = (std::string) vendorAtom.reverseDomainName; | 
|  | 34 | if (vendorAtom.atomId < 100000 || vendorAtom.atomId >= 200000) { | 
|  | 35 | ALOGE("Atom ID %ld is not a valid vendor atom ID", (long) vendorAtom.atomId); | 
|  | 36 | return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage( | 
|  | 37 | -1, "Not a valid vendor atom ID"); | 
|  | 38 | } | 
|  | 39 | if (reverseDomainName.length() > 50) { | 
|  | 40 | ALOGE("Vendor atom reverse domain name %s is too long.", reverseDomainName.c_str()); | 
|  | 41 | return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage( | 
|  | 42 | -1, "Vendor atom reverse domain name is too long"); | 
|  | 43 | } | 
|  | 44 | AStatsEvent* event = AStatsEvent_obtain(); | 
|  | 45 | AStatsEvent_setAtomId(event, vendorAtom.atomId); | 
|  | 46 | AStatsEvent_writeString(event, vendorAtom.reverseDomainName.c_str()); | 
|  | 47 | for (const auto& atomValue : vendorAtom.values) { | 
|  | 48 | switch (atomValue.getTag()) { | 
|  | 49 | case VendorAtomValue::intValue: | 
|  | 50 | AStatsEvent_writeInt32(event, | 
|  | 51 | atomValue.get<VendorAtomValue::intValue>()); | 
|  | 52 | break; | 
|  | 53 | case VendorAtomValue::longValue: | 
|  | 54 | AStatsEvent_writeInt64(event, | 
|  | 55 | atomValue.get<VendorAtomValue::longValue>()); | 
|  | 56 | break; | 
|  | 57 | case VendorAtomValue::floatValue: | 
|  | 58 | AStatsEvent_writeFloat(event, | 
|  | 59 | atomValue.get<VendorAtomValue::floatValue>()); | 
|  | 60 | break; | 
|  | 61 | case VendorAtomValue::stringValue: | 
|  | 62 | AStatsEvent_writeString(event, | 
|  | 63 | atomValue.get<VendorAtomValue::stringValue>().c_str()); | 
|  | 64 | break; | 
| Vova Sharaienko | 3c28887 | 2022-04-08 05:53:43 +0000 | [diff] [blame] | 65 | case VendorAtomValue::boolValue: | 
|  | 66 | AStatsEvent_writeBool(event, | 
|  | 67 | atomValue.get<VendorAtomValue::boolValue>()); | 
|  | 68 | break; | 
| Vova Sharaienko | 3092c96 | 2021-02-01 23:38:12 +0000 | [diff] [blame] | 69 | } | 
|  | 70 | } | 
|  | 71 | AStatsEvent_build(event); | 
|  | 72 | const int ret = AStatsEvent_write(event); | 
|  | 73 | AStatsEvent_release(event); | 
|  | 74 |  | 
|  | 75 | return ret <= 0 ? | 
|  | 76 | ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(ret, "report atom failed") : | 
|  | 77 | ndk::ScopedAStatus::ok(); | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | }  // namespace stats | 
|  | 81 | }  // namespace frameworks | 
|  | 82 | }  // namespace android | 
|  | 83 | }  // namespace aidl |