1 /*
2  * Copyright (C) 2023 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 #pragma once
18 
19 #include <string>
20 
21 namespace android {
22 namespace os {
23 namespace statsd {
24 
25 using std::hash;
26 using std::string;
27 
28 /**
29  * A config key that uses a package name instead of a uid. Generally, ConfigKey which uses a uid
30  * should be used. This is currently only used for restricted metrics changed operation.
31  */
32 class ConfigKeyWithPackage {
33 public:
ConfigKeyWithPackage(const string & package,int64_t id)34     ConfigKeyWithPackage(const string& package, int64_t id) : mPackage(package), mId(id) {
35     }
36 
GetPackage()37     inline string GetPackage() const {
38         return mPackage;
39     }
GetId()40     inline int64_t GetId() const {
41         return mId;
42     }
43 
44     inline bool operator<(const ConfigKeyWithPackage& that) const {
45         if (mPackage != that.mPackage) {
46             return mPackage < that.mPackage;
47         }
48         return mId < that.mId;
49     };
50 
51     inline bool operator==(const ConfigKeyWithPackage& that) const {
52         return mPackage == that.mPackage && mId == that.mId;
53     };
54 
55 private:
56     string mPackage;
57     int64_t mId;
58 };
59 }  // namespace statsd
60 }  // namespace os
61 }  // namespace android
62