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 | |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 22 | // This is the default value of DEST enum, sync with privacy.proto |
| 23 | const uint8_t DEST_UNSET = 255; // DEST_UNSET is not exposed to libincident |
| 24 | const uint8_t DEST_DEFAULT_VALUE = DEST_UNSET; |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 25 | |
| 26 | /* |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 27 | * In order to NOT auto-generate large chuck of code by proto compiler in incidentd, |
| 28 | * privacy options's data structure are explicitly redefined here and |
| 29 | * the values are populated by incident_section_gen tool. |
| 30 | * |
| 31 | * Each proto field will have a Privacy when it is different from its parent, otherwise |
| 32 | * it uses its parent's tag. A message type will have an array of Privacy. |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 33 | */ |
| 34 | struct Privacy { |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 35 | // The field number |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 36 | uint32_t field_id; |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 37 | |
| 38 | // The field type, see external/protobuf/src/google/protobuf/descriptor.h |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 39 | uint8_t type; |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 40 | |
| 41 | // If children is null, it is a primitive field, |
| 42 | // otherwise it is a message field which could have overridden privacy tags here. |
| 43 | // This array is NULL-terminated. |
Yi Jin | 7e0b4e5 | 2017-09-12 20:00:25 -0700 | [diff] [blame] | 44 | Privacy** children; |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 45 | |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 46 | // DESTINATION Enum in frameworks/base/libs/incident/proto/android/privacy.proto. |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 47 | uint8_t dest; |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 48 | // A list of regexp rules for stripping string fields in proto. |
| 49 | const char** patterns; |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 52 | // Encode field id used by ProtoOutputStream. |
| 53 | uint64_t encode_field_id(const Privacy* p); |
| 54 | |
| 55 | // Look up the child with given fieldId, if not found, return NULL. |
| 56 | const Privacy* lookup(const Privacy* p, uint32_t fieldId); |
| 57 | |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 58 | /** |
| 59 | * PrivacySpec defines the request has what level of privacy authorization. |
| 60 | * For example, a device without user consent should only be able to upload AUTOMATIC fields. |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 61 | * DEST_UNSET are treated as DEST_EXPLICIT. |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 62 | */ |
| 63 | class PrivacySpec { |
| 64 | public: |
| 65 | const uint8_t dest; |
| 66 | |
| 67 | PrivacySpec() : dest(DEST_DEFAULT_VALUE) {} |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 68 | bool operator<(const PrivacySpec& other) const; |
| 69 | |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 70 | // check permission of a policy, if returns true, don't strip the data. |
| 71 | bool CheckPremission(const Privacy* privacy, const uint8_t defaultDest = DEST_DEFAULT_VALUE) const; |
| 72 | |
| 73 | // if returns true, no data need to be stripped. |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 74 | bool RequireAll() const; |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 75 | |
Yi Jin | 3ec5cc7 | 2018-01-26 13:42:43 -0800 | [diff] [blame^] | 76 | // Constructs spec using static methods below. |
| 77 | static PrivacySpec new_spec(int dest); |
| 78 | static PrivacySpec get_default_dropbox_spec(); |
| 79 | private: |
| 80 | PrivacySpec(uint8_t dest) : dest(dest) {} |
| 81 | }; |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 82 | |
| 83 | #endif // PRIVACY_H |