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; |
| 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 | */ |
| 50 | class PrivacySpec { |
| 51 | public: |
| 52 | const uint8_t dest; |
| 53 | |
| 54 | PrivacySpec() : dest(DEST_DEFAULT_VALUE) {} |
| 55 | PrivacySpec(uint8_t dest) : dest(dest) {} |
| 56 | |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 57 | bool operator<(const PrivacySpec& other) const; |
| 58 | |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 59 | bool CheckPremission(const Privacy* privacy) const; |
| 60 | bool RequireAll() const; |
| 61 | }; |
| 62 | |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 63 | PrivacySpec new_spec_from_args(int dest); |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 64 | PrivacySpec get_default_dropbox_spec(); |
| 65 | |
| 66 | #endif // PRIVACY_H |