1 /*
2  * Copyright (C) 2020 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 #ifndef ANDROID_OS_WORKSOURCE_H
18 #define ANDROID_OS_WORKSOURCE_H
19 
20 #include <optional>
21 #include <binder/Parcelable.h>
22 #include <utils/RefBase.h>
23 
24 namespace android::os {
25 
26 /**
27  * WorkSource is a structure to describes the source of some work that may be done by someone else.
28  * This file needs to be kept in sync with frameworks/base/core/java/android/os/WorkSource.java
29  */
30 struct WorkSource : public android::Parcelable {
31     WorkSource(
32                std::vector<int32_t> uids = {},
33                std::optional<std::vector<std::optional<String16>>> names = std::nullopt)
mUidsWorkSource34         : mUids(uids),
35           mNames(names) {
36     }
getUidsWorkSource37     std::vector<int32_t> getUids() const { return mUids; }
getNamesWorkSource38     std::optional<std::vector<std::optional<String16>>> getNames() const { return mNames; }
39     bool operator == (const WorkSource &ws) const {
40         return mUids == ws.mUids && mNames == ws.mNames;
41     }
42     status_t readFromParcel(const android::Parcel* parcel) override;
43     status_t writeToParcel(android::Parcel* parcel) const override;
44 
45 private:
46     /** WorkSource UID array */
47     std::vector<int32_t> mUids = {};
48     /** WorkSource Tag array */
49     std::optional<std::vector<std::optional<String16>>> mNames = {};
50 };
51 
52 } // namespace android::os
53 
54 #endif /* ANDROID_OS_WORKSOURCE_H */
55