Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 1 | /* |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 2 | * Copyright (C) 2019 The Android Open Source Project |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 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 | * |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 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. |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 17 | #pragma once |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 18 | |
| 19 | #include <stdbool.h> |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 20 | #include <sys/types.h> |
| 21 | |
| 22 | __BEGIN_DECLS |
| 23 | |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 24 | typedef struct gid_list { |
| 25 | /** Number of gids. */ |
| 26 | size_t cnt; |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 27 | |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 28 | /** Array of gids. */ |
| 29 | gid_t* gids; |
| 30 | } gid_list; |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 31 | |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 32 | typedef struct pkg_info { |
| 33 | /** Package name like "com.android.blah". */ |
| 34 | char* name; |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 35 | |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 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; |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 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. |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 66 | */ |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 67 | bool packagelist_parse(bool (*callback)(pkg_info* info, void* user_data), void* user_data); |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 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. |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 74 | */ |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 75 | bool packagelist_parse_file(const char* path, bool (*callback)(pkg_info* info, void* user_data), |
| 76 | void* user_data); |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 77 | |
Elliott Hughes | d32e7e2 | 2019-08-07 22:59:00 -0700 | [diff] [blame] | 78 | /** Frees the given `pkg_info`. */ |
| 79 | void packagelist_free(pkg_info* info); |
Andreas Gampe | 438eb75 | 2015-10-22 19:51:51 -0700 | [diff] [blame] | 80 | |
| 81 | __END_DECLS |