1 /*
2  * Copyright 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 <stddef.h>
20 #include <stdint.h>
21 
22 // Opaque structure holding information extracted from an APK manifest.
23 struct ApkManifestInfo;
24 
25 extern "C" {
26 
27 // Parse a binary XML encoded APK manifest and extract relevant information.
28 // The caller must free the returned pointer using freeManifestInfo.  Returns
29 // null if any error occurs. Does not retain any pointer to the manifest
30 // provided.
31 const ApkManifestInfo* extractManifestInfo(const void* manifest, size_t size);
32 
33 // Frees an ApkManifestInfo allocated by extractManifestInfo; this invalidates
34 // the pointer and it must not be used again.
35 void freeManifestInfo(const ApkManifestInfo* info);
36 
37 // Given a valid ApkManifestInfo pointer, return the package name of the APK, as
38 // a nul-terminated UTF-8 string. The pointer remains valid until the
39 // ApkManifestInfo is freed.
40 const char* getPackageName(const ApkManifestInfo* info);
41 
42 // Given a valid ApkManifestInfo pointer, return the version code of the APK.
43 uint64_t getVersionCode(const ApkManifestInfo* info);
44 }
45