1 /*
2  * Copyright (C) 2024 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 <aidl/google/sdv/packagemanagerproxy/BnPackageManagerProxy.h>
20 #include <aidl/google/sdv/packagemanagerproxy/IPackageManagerProxy.h>
21 #include <android-base/result.h>
22 #include <android/content/pm/IPackageManagerNative.h>
23 
24 #include <string>
25 #include <vector>
26 
27 namespace google {
28 namespace sdv {
29 namespace packagemanagerproxy {
30 
31 /**
32  * This class implements the IPackageManagerProxy AIDL interface.
33  *
34  * Once binder is setup for the process, create an instance of this class
35  * and call init() on the object. This will wait for the IPackageManagerNative
36  * service, then reigster itself with service manager as a provider of the
37  * IPackageManagerProxy interface.
38  */
39 class PackageManagerProxy : public aidl::google::sdv::packagemanagerproxy::BnPackageManagerProxy {
40 public:
41     android::base::Result<void> init();
42 
43     // Implements IPackageManagerProxy.aidl interfaces.
44     ndk::ScopedAStatus getNamesForUids(const std::vector<int32_t>& uids,
45                                        std::vector<std::string>* _aidl_return) override;
46     ndk::ScopedAStatus getPackageUid(const std::string& packageName, int64_t flags, int32_t userId,
47                                      int32_t* _aidl_return) override;
48     ndk::ScopedAStatus getVersionCodeForPackage(const std::string& packageName,
49                                                 int64_t* _aidl_return) override;
50 
51 private:
52     android::sp<android::content::pm::IPackageManagerNative> mPackageManagerNativeService;
53 };
54 
55 }  // namespace packagemanagerproxy
56 }  // namespace sdv
57 }  // namespace google
58