• 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   /**
37    * Package uid like 10014.
38    * Note that apexes and SDK libraries may have a bogus 0xffffffff value.
39    */
40   uid_t uid;
41 
42   /** Package's AndroidManifest.xml debuggable flag. */
43   bool debuggable;
44 
45   /** Package data directory like "/data/user/0/com.android.blah" */
46   char* data_dir;
47 
48   /** Package SELinux info. */
49   char* seinfo;
50 
51   /** Package's list of gids. */
52   gid_list gids;
53 
54   /** Spare pointer for the caller to stash extra data off. */
55   void* private_data;
56 
57   /** Package's AndroidManifest.xml profileable flag. */
58   bool profileable_from_shell;
59 
60   /** Package's AndroidManifest.xml version code. */
61   long version_code;
62 } pkg_info;
63 
64 /**
65  * Parses the system's default package list.
66  * Invokes `callback` once for each package.
67  * The callback owns the `pkg_info*` and should call packagelist_free().
68  * The callback should return `false` to exit early or `true` to continue.
69  */
70 bool packagelist_parse(bool (*callback)(pkg_info* info, void* user_data), void* user_data);
71 
72 /**
73  * Parses the given package list.
74  * Invokes `callback` once for each package.
75  * The callback owns the `pkg_info*` and should call packagelist_free().
76  * The callback should return `false` to exit early or `true` to continue.
77  */
78 bool packagelist_parse_file(const char* path, bool (*callback)(pkg_info* info, void* user_data),
79                             void* user_data);
80 
81 /** Frees the given `pkg_info`. */
82 void packagelist_free(pkg_info* info);
83 
84 __END_DECLS
85