blob: c56ba9b8e3fe96aa1631c47f3479113db58a2100 [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
33 const Privacy** children;
34
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
40 Privacy(uint32_t field_id, uint8_t type, uint8_t dest); // generic constructor
41 Privacy(uint32_t field_id, const Privacy** children); // used for message type
42 Privacy(uint32_t field_id, uint8_t dest, const char** patterns); // used for string type
43
44 bool IsMessageType() const;
45 bool IsStringType() const;
46 bool HasChildren() const;
47 const Privacy* lookup(uint32_t fieldId) const;
48};
49
50/**
51 * PrivacySpec defines the request has what level of privacy authorization.
52 * For example, a device without user consent should only be able to upload AUTOMATIC fields.
53 */
54class PrivacySpec {
55public:
56 const uint8_t dest;
57
58 PrivacySpec() : dest(DEST_DEFAULT_VALUE) {}
59 PrivacySpec(uint8_t dest) : dest(dest) {}
60
Yi Jin0f047162017-09-05 13:44:22 -070061 bool operator<(const PrivacySpec& other) const;
62
Yi Jin99c248f2017-08-25 18:11:58 -070063 bool CheckPremission(const Privacy* privacy) const;
64 bool RequireAll() const;
65};
66
Yi Jin0f047162017-09-05 13:44:22 -070067PrivacySpec new_spec_from_args(int dest);
Yi Jin99c248f2017-08-25 18:11:58 -070068PrivacySpec get_default_dropbox_spec();
69
70#endif // PRIVACY_H