blob: 7f1977e3c8356a41cdebd60b121d0028c08e1b00 [file] [log] [blame]
Yi Jin99c248f2017-08-25 18:11:58 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
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 *
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 */
16
17#ifndef PRIVACY_H
18#define PRIVACY_H
19
20#include <stdint.h>
21
22// This is the default value of DEST enum
23const uint8_t DEST_DEFAULT_VALUE = 1;
24
25/*
26 * In order not to depend on libprotobuf-cpp-full nor libplatformprotos in incidentd,
27 * privacy options's data structure are explicitly redefined in this file.
28 */
29struct Privacy {
30 uint32_t field_id;
31 uint8_t type;
32 // ignore parent's privacy flags if children are set, NULL-terminated
Yi Jin7e0b4e52017-09-12 20:00:25 -070033 Privacy** children;
Yi Jin99c248f2017-08-25 18:11:58 -070034
35 // the following fields are identitical to
36 // frameworks/base/libs/incident/proto/android/privacy.proto
37 uint8_t dest;
38 const char** patterns; // only set when type is string
39
Yi Jin99c248f2017-08-25 18:11:58 -070040 bool IsMessageType() const;
41 bool IsStringType() const;
42 bool HasChildren() const;
43 const Privacy* lookup(uint32_t fieldId) const;
44};
45
46/**
47 * PrivacySpec defines the request has what level of privacy authorization.
48 * For example, a device without user consent should only be able to upload AUTOMATIC fields.
49 */
50class PrivacySpec {
51public:
52 const uint8_t dest;
53
54 PrivacySpec() : dest(DEST_DEFAULT_VALUE) {}
55 PrivacySpec(uint8_t dest) : dest(dest) {}
56
Yi Jin0f047162017-09-05 13:44:22 -070057 bool operator<(const PrivacySpec& other) const;
58
Yi Jin99c248f2017-08-25 18:11:58 -070059 bool CheckPremission(const Privacy* privacy) const;
60 bool RequireAll() const;
61};
62
Yi Jin0f047162017-09-05 13:44:22 -070063PrivacySpec new_spec_from_args(int dest);
Yi Jin99c248f2017-08-25 18:11:58 -070064PrivacySpec get_default_dropbox_spec();
65
66#endif // PRIVACY_H