blob: 9e15ff43be06d5cb5facb52aba4d95fee6d0a6f4 [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
Yi Jinbdf58942017-11-14 17:58:19 -080022// This is the default value of DEST enum, sync with privacy.proto
23const uint8_t DEST_UNSET = 255; // DEST_UNSET is not exposed to libincident
24const uint8_t DEST_DEFAULT_VALUE = DEST_UNSET;
Yi Jin99c248f2017-08-25 18:11:58 -070025
26/*
Yi Jinbdf58942017-11-14 17:58:19 -080027 * 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 Jin99c248f2017-08-25 18:11:58 -070033 */
34struct Privacy {
Yi Jinbdf58942017-11-14 17:58:19 -080035 // The field number
Yi Jin99c248f2017-08-25 18:11:58 -070036 uint32_t field_id;
Yi Jinbdf58942017-11-14 17:58:19 -080037
38 // The field type, see external/protobuf/src/google/protobuf/descriptor.h
Yi Jin99c248f2017-08-25 18:11:58 -070039 uint8_t type;
Yi Jinbdf58942017-11-14 17:58:19 -080040
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 Jin7e0b4e52017-09-12 20:00:25 -070044 Privacy** children;
Yi Jin99c248f2017-08-25 18:11:58 -070045
Yi Jinbdf58942017-11-14 17:58:19 -080046 // DESTINATION Enum in frameworks/base/libs/incident/proto/android/privacy.proto.
Yi Jin99c248f2017-08-25 18:11:58 -070047 uint8_t dest;
Yi Jinbdf58942017-11-14 17:58:19 -080048 // A list of regexp rules for stripping string fields in proto.
49 const char** patterns;
Yi Jin99c248f2017-08-25 18:11:58 -070050};
51
Yi Jinbdf58942017-11-14 17:58:19 -080052// Encode field id used by ProtoOutputStream.
53uint64_t encode_field_id(const Privacy* p);
54
55// Look up the child with given fieldId, if not found, return NULL.
56const Privacy* lookup(const Privacy* p, uint32_t fieldId);
57
Yi Jin99c248f2017-08-25 18:11:58 -070058/**
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 Jinbdf58942017-11-14 17:58:19 -080061 * DEST_UNSET are treated as DEST_EXPLICIT.
Yi Jin99c248f2017-08-25 18:11:58 -070062 */
63class PrivacySpec {
64public:
65 const uint8_t dest;
66
67 PrivacySpec() : dest(DEST_DEFAULT_VALUE) {}
68 PrivacySpec(uint8_t dest) : dest(dest) {}
69
Yi Jin0f047162017-09-05 13:44:22 -070070 bool operator<(const PrivacySpec& other) const;
71
Yi Jinbdf58942017-11-14 17:58:19 -080072 // check permission of a policy, if returns true, don't strip the data.
73 bool CheckPremission(const Privacy* privacy, const uint8_t defaultDest = DEST_DEFAULT_VALUE) const;
74
75 // if returns true, no data need to be stripped.
Yi Jin99c248f2017-08-25 18:11:58 -070076 bool RequireAll() const;
77};
78
Yi Jin0f047162017-09-05 13:44:22 -070079PrivacySpec new_spec_from_args(int dest);
Yi Jin99c248f2017-08-25 18:11:58 -070080PrivacySpec get_default_dropbox_spec();
81
82#endif // PRIVACY_H