blob: 763edb03e4853fa99a6786afd3a68ebb629c568a [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 */
Yi Jinb592e3b2018-02-01 15:17:04 -080016#pragma once
Yi Jin99c248f2017-08-25 18:11:58 -070017
18#ifndef PRIVACY_H
19#define PRIVACY_H
20
Joe Onorato99598ee2019-02-11 15:55:13 +000021#include <android/os/IncidentReportArgs.h>
22
Yi Jin99c248f2017-08-25 18:11:58 -070023#include <stdint.h>
24
Yi Jin6cacbcb2018-03-30 14:04:52 -070025namespace android {
26namespace os {
27namespace incidentd {
28
Joe Onorato99598ee2019-02-11 15:55:13 +000029using namespace android::os;
Yi Jin99c248f2017-08-25 18:11:58 -070030
31/*
Yi Jinbdf58942017-11-14 17:58:19 -080032 * In order to NOT auto-generate large chuck of code by proto compiler in incidentd,
33 * privacy options's data structure are explicitly redefined here and
34 * the values are populated by incident_section_gen tool.
35 *
36 * Each proto field will have a Privacy when it is different from its parent, otherwise
37 * it uses its parent's tag. A message type will have an array of Privacy.
Yi Jin99c248f2017-08-25 18:11:58 -070038 */
39struct Privacy {
Yi Jinbdf58942017-11-14 17:58:19 -080040 // The field number
Yi Jin99c248f2017-08-25 18:11:58 -070041 uint32_t field_id;
Yi Jinbdf58942017-11-14 17:58:19 -080042
43 // The field type, see external/protobuf/src/google/protobuf/descriptor.h
Yi Jin99c248f2017-08-25 18:11:58 -070044 uint8_t type;
Yi Jinbdf58942017-11-14 17:58:19 -080045
46 // If children is null, it is a primitive field,
47 // otherwise it is a message field which could have overridden privacy tags here.
48 // This array is NULL-terminated.
Yi Jin7e0b4e52017-09-12 20:00:25 -070049 Privacy** children;
Yi Jin99c248f2017-08-25 18:11:58 -070050
Joe Onorato99598ee2019-02-11 15:55:13 +000051 // DESTINATION Enum in frameworks/base/core/proto/android/privacy.proto.
52 uint8_t policy;
Joe Onoratoe5472052019-04-24 16:27:33 -070053
Yi Jinbdf58942017-11-14 17:58:19 -080054 // A list of regexp rules for stripping string fields in proto.
55 const char** patterns;
Joe Onoratoe5472052019-04-24 16:27:33 -070056
57 string toString() const;
Yi Jin99c248f2017-08-25 18:11:58 -070058};
59
Yi Jinbdf58942017-11-14 17:58:19 -080060// Encode field id used by ProtoOutputStream.
61uint64_t encode_field_id(const Privacy* p);
62
63// Look up the child with given fieldId, if not found, return NULL.
64const Privacy* lookup(const Privacy* p, uint32_t fieldId);
65
Yi Jin99c248f2017-08-25 18:11:58 -070066/**
67 * PrivacySpec defines the request has what level of privacy authorization.
68 * For example, a device without user consent should only be able to upload AUTOMATIC fields.
Joe Onorato99598ee2019-02-11 15:55:13 +000069 * PRIVACY_POLICY_UNSET are treated as PRIVACY_POLICY_EXPLICIT.
Yi Jin99c248f2017-08-25 18:11:58 -070070 */
71class PrivacySpec {
72public:
Joe Onorato99598ee2019-02-11 15:55:13 +000073 explicit PrivacySpec(uint8_t argPolicy);
Yi Jin99c248f2017-08-25 18:11:58 -070074
Yi Jin0f047162017-09-05 13:44:22 -070075 bool operator<(const PrivacySpec& other) const;
76
Yi Jinbdf58942017-11-14 17:58:19 -080077 // check permission of a policy, if returns true, don't strip the data.
Yi Jinb592e3b2018-02-01 15:17:04 -080078 bool CheckPremission(const Privacy* privacy,
Joe Onorato99598ee2019-02-11 15:55:13 +000079 const uint8_t defaultPrivacyPolicy = PRIVACY_POLICY_UNSET) const;
Yi Jinbdf58942017-11-14 17:58:19 -080080
81 // if returns true, no data need to be stripped.
Yi Jin99c248f2017-08-25 18:11:58 -070082 bool RequireAll() const;
Yi Jin99c248f2017-08-25 18:11:58 -070083
Joe Onorato99598ee2019-02-11 15:55:13 +000084 uint8_t getPolicy() const;
Yi Jinb592e3b2018-02-01 15:17:04 -080085
Yi Jin3ec5cc72018-01-26 13:42:43 -080086private:
Joe Onorato99598ee2019-02-11 15:55:13 +000087 // unimplemented constructors
88 explicit PrivacySpec();
89
90 uint8_t mPolicy;
Yi Jin3ec5cc72018-01-26 13:42:43 -080091};
Yi Jin99c248f2017-08-25 18:11:58 -070092
Joe Onoratoe5472052019-04-24 16:27:33 -070093/**
94 * If a privacy policy is other than the defined values, update it to a real one.
95 */
96uint8_t cleanup_privacy_policy(uint8_t policy);
97
Yi Jin6cacbcb2018-03-30 14:04:52 -070098} // namespace incidentd
99} // namespace os
100} // namespace android
101
Yi Jinb592e3b2018-02-01 15:17:04 -0800102#endif // PRIVACY_H