• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 <stdbool.h>
20 #include <sys/types.h>
21 
22 __BEGIN_DECLS
23 
24 typedef struct gid_list {
25   /** Number of gids. */
26   size_t cnt;
27 
28   /** Array of gids. */
29   gid_t* gids;
30 } gid_list;
31 
32 typedef struct pkg_info {
33   /** Package name like "com.android.blah". */
34   char* name;
35 
36   /** Package uid like 10014. */
37   uid_t uid;
38 
39   /** Package's AndroidManifest.xml debuggable flag. */
40   bool debuggable;
41 
42   /** Package data directory like "/data/user/0/com.android.blah" */
43   char* data_dir;
44 
45   /** Package SELinux info. */
46   char* seinfo;
47 
48   /** Package's list of gids. */
49   gid_list gids;
50 
51   /** Spare pointer for the caller to stash extra data off. */
52   void* private_data;
53 
54   /** Package's AndroidManifest.xml profileable flag. */
55   bool profileable_from_shell;
56 
57   /** Package's AndroidManifest.xml version code. */
58   long version_code;
59 } pkg_info;
60 
61 /**
62  * Parses the system's default package list.
63  * Invokes `callback` once for each package.
64  * The callback owns the `pkg_info*` and should call packagelist_free().
65  * The callback should return `false` to exit early or `true` to continue.
66  */
67 bool packagelist_parse(bool (*callback)(pkg_info* info, void* user_data), void* user_data);
68 
69 /**
70  * Parses the given package list.
71  * Invokes `callback` once for each package.
72  * The callback owns the `pkg_info*` and should call packagelist_free().
73  * The callback should return `false` to exit early or `true` to continue.
74  */
75 bool packagelist_parse_file(const char* path, bool (*callback)(pkg_info* info, void* user_data),
76                             void* user_data);
77 
78 /** Frees the given `pkg_info`. */
79 void packagelist_free(pkg_info* info);
80 
81 __END_DECLS
82