blob: e89cb5400db57006b27fda20a0441cde825b8bbb [file] [log] [blame]
Andreas Gampe438eb752015-10-22 19:51:51 -07001/*
Elliott Hughesd32e7e22019-08-07 22:59:00 -07002 * Copyright (C) 2019 The Android Open Source Project
Andreas Gampe438eb752015-10-22 19:51:51 -07003 *
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 Hughesd32e7e22019-08-07 22:59:00 -07008 * http://www.apache.org/licenses/LICENSE-2.0
Andreas Gampe438eb752015-10-22 19:51:51 -07009 *
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 Gampe438eb752015-10-22 19:51:51 -070015 */
16
Elliott Hughesd32e7e22019-08-07 22:59:00 -070017#pragma once
Andreas Gampe438eb752015-10-22 19:51:51 -070018
19#include <stdbool.h>
Andreas Gampe438eb752015-10-22 19:51:51 -070020#include <sys/types.h>
21
22__BEGIN_DECLS
23
Elliott Hughesd32e7e22019-08-07 22:59:00 -070024typedef struct gid_list {
25 /** Number of gids. */
26 size_t cnt;
Andreas Gampe438eb752015-10-22 19:51:51 -070027
Elliott Hughesd32e7e22019-08-07 22:59:00 -070028 /** Array of gids. */
29 gid_t* gids;
30} gid_list;
Andreas Gampe438eb752015-10-22 19:51:51 -070031
Elliott Hughesd32e7e22019-08-07 22:59:00 -070032typedef struct pkg_info {
33 /** Package name like "com.android.blah". */
34 char* name;
Andreas Gampe438eb752015-10-22 19:51:51 -070035
Elliott Hughesd32e7e22019-08-07 22:59:00 -070036 /** 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 Gampe438eb752015-10-22 19:51:51 -070060
61/**
Elliott Hughesd32e7e22019-08-07 22:59:00 -070062 * 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 Gampe438eb752015-10-22 19:51:51 -070066 */
Elliott Hughesd32e7e22019-08-07 22:59:00 -070067bool packagelist_parse(bool (*callback)(pkg_info* info, void* user_data), void* user_data);
Andreas Gampe438eb752015-10-22 19:51:51 -070068
69/**
Elliott Hughesd32e7e22019-08-07 22:59:00 -070070 * 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 Gampe438eb752015-10-22 19:51:51 -070074 */
Elliott Hughesd32e7e22019-08-07 22:59:00 -070075bool packagelist_parse_file(const char* path, bool (*callback)(pkg_info* info, void* user_data),
76 void* user_data);
Andreas Gampe438eb752015-10-22 19:51:51 -070077
Elliott Hughesd32e7e22019-08-07 22:59:00 -070078/** Frees the given `pkg_info`. */
79void packagelist_free(pkg_info* info);
Andreas Gampe438eb752015-10-22 19:51:51 -070080
81__END_DECLS