blob: f514f196a2057def28df0bac3940701babea5c3d [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;
Yi Jin42711a02017-10-11 18:20:24 -070043 uint64_t EncodedFieldId() const;
44
Yi Jin99c248f2017-08-25 18:11:58 -070045 const Privacy* lookup(uint32_t fieldId) const;
46};
47
48/**
49 * PrivacySpec defines the request has what level of privacy authorization.
50 * For example, a device without user consent should only be able to upload AUTOMATIC fields.
51 */
52class PrivacySpec {
53public:
54 const uint8_t dest;
55
56 PrivacySpec() : dest(DEST_DEFAULT_VALUE) {}
57 PrivacySpec(uint8_t dest) : dest(dest) {}
58
Yi Jin0f047162017-09-05 13:44:22 -070059 bool operator<(const PrivacySpec& other) const;
60
Yi Jin99c248f2017-08-25 18:11:58 -070061 bool CheckPremission(const Privacy* privacy) const;
62 bool RequireAll() const;
63};
64
Yi Jin0f047162017-09-05 13:44:22 -070065PrivacySpec new_spec_from_args(int dest);
Yi Jin99c248f2017-08-25 18:11:58 -070066PrivacySpec get_default_dropbox_spec();
67
68#endif // PRIVACY_H