• 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     bool profileable_from_shell;
57     long version_code;
58 };
59 
60 /**
61  * Callback function to be used by packagelist_parse() routine.
62  * @param info
63  *  The parsed package information
64  * @param userdata
65  *  The supplied userdata pointer to packagelist_parse()
66  * @return
67  *  true to keep processing, false to stop.
68  */
69 typedef bool (*pfn_on_package)(pkg_info *info, void *userdata);
70 
71 /**
72  * Parses the file specified by PACKAGES_LIST_FILE and invokes the callback on
73  * each entry found. Once the callback is invoked, ownership of the pkg_info pointer
74  * is passed to the callback routine, thus they are required to perform any cleanup
75  * desired.
76  * @param callback
77  *  The callback function called on each parsed line of the packages list.
78  * @param userdata
79  *  An optional userdata supplied pointer to pass to the callback function.
80  * @return
81  *  true on success false on failure.
82  */
83 extern bool packagelist_parse(pfn_on_package callback, void *userdata);
84 
85 /**
86  * Frees a pkg_info structure.
87  * @param info
88  *  The struct to free
89  */
90 extern void packagelist_free(pkg_info *info);
91 
92 __END_DECLS
93 
94 #endif /* PACKAGELISTPARSER_H_ */
95