Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 1 | /* |
| 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 |
| 23 | const 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 | */ |
| 29 | struct Privacy { |
| 30 | uint32_t field_id; |
| 31 | uint8_t type; |
| 32 | // ignore parent's privacy flags if children are set, NULL-terminated |
Yi Jin | 7e0b4e5 | 2017-09-12 20:00:25 -0700 | [diff] [blame] | 33 | Privacy** children; |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 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 | |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 40 | bool IsMessageType() const; |
| 41 | bool IsStringType() const; |
| 42 | bool HasChildren() const; |
Yi Jin | 42711a0 | 2017-10-11 18:20:24 -0700 | [diff] [blame] | 43 | uint64_t EncodedFieldId() const; |
| 44 | |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 45 | 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 | */ |
| 52 | class PrivacySpec { |
| 53 | public: |
| 54 | const uint8_t dest; |
| 55 | |
| 56 | PrivacySpec() : dest(DEST_DEFAULT_VALUE) {} |
| 57 | PrivacySpec(uint8_t dest) : dest(dest) {} |
| 58 | |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 59 | bool operator<(const PrivacySpec& other) const; |
| 60 | |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 61 | bool CheckPremission(const Privacy* privacy) const; |
| 62 | bool RequireAll() const; |
| 63 | }; |
| 64 | |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 65 | PrivacySpec new_spec_from_args(int dest); |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 66 | PrivacySpec get_default_dropbox_spec(); |
| 67 | |
| 68 | #endif // PRIVACY_H |