• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015, Intel Corporation
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Written by William Roberts <william.c.roberts@intel.com>
18  *
19  * This is a parser library for parsing the packages.list file generated
20  * by PackageManager service.
21  *
22  * This simple parser is sensitive to format changes in
23  * frameworks/base/services/core/java/com/android/server/pm/Settings.java
24  * A dependency note has been added to that file to correct
25  * this parser.
26  */
27 
28 #ifndef PACKAGELISTPARSER_H_
29 #define PACKAGELISTPARSER_H_
30 
31 #include <stdbool.h>
32 #include <sys/cdefs.h>
33 #include <sys/types.h>
34 
35 __BEGIN_DECLS
36 
37 /** The file containing the list of installed packages on the system */
38 #define PACKAGES_LIST_FILE  "/data/system/packages.list"
39 
40 typedef struct pkg_info pkg_info;
41 typedef struct gid_list gid_list;
42 
43 struct gid_list {
44     size_t cnt;
45     gid_t *gids;
46 };
47 
48 struct pkg_info {
49     char *name;
50     uid_t uid;
51     bool debuggable;
52     char *data_dir;
53     char *seinfo;
54     gid_list gids;
55     void *private_data;
56 };
57 
58 /**
59  * Callback function to be used by packagelist_parse() routine.
60  * @param info
61  *  The parsed package information
62  * @param userdata
63  *  The supplied userdata pointer to packagelist_parse()
64  * @return
65  *  true to keep processing, false to stop.
66  */
67 typedef bool (*pfn_on_package)(pkg_info *info, void *userdata);
68 
69 /**
70  * Parses the file specified by PACKAGES_LIST_FILE and invokes the callback on
71  * each entry found. Once the callback is invoked, ownership of the pkg_info pointer
72  * is passed to the callback routine, thus they are required to perform any cleanup
73  * desired.
74  * @param callback
75  *  The callback function called on each parsed line of the packages list.
76  * @param userdata
77  *  An optional userdata supplied pointer to pass to the callback function.
78  * @return
79  *  true on success false on failure.
80  */
81 extern bool packagelist_parse(pfn_on_package callback, void *userdata);
82 
83 /**
84  * Frees a pkg_info structure.
85  * @param info
86  *  The struct to free
87  */
88 extern void packagelist_free(pkg_info *info);
89 
90 __END_DECLS
91 
92 #endif /* PACKAGELISTPARSER_H_ */
93