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