Debian Codegraph @

core/java/android/os/IncidentReportArgs.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2005 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 package android.os;
18
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.util.IntArray;
24
25 import java.util.ArrayList;
26
27 /**
28 * The arguments for an incident report.
29 * {@hide}
30 */
31 @SystemApi
32 public final class IncidentReportArgs implements Parcelable {
33
34 private final IntArray mSections = new IntArray();
35 private final ArrayList<byte[]> mHeaders = new ArrayList<byte[]>();
36 private boolean mAll;
37 private int mPrivacyPolicy;
38 private String mReceiverPkg;
39 private String mReceiverCls;
40
41 /**
42 * Construct an incident report args with no fields.
43 */
44 public IncidentReportArgs() {
45 mPrivacyPolicy = IncidentManager.PRIVACY_POLICY_AUTO;
46 }
47
48 /**
49 * Construct an incdent report args from the given parcel.
50 */
51 public IncidentReportArgs(Parcel in) {
52 readFromParcel(in);
53 }
54
55 @Override
56 public int describeContents() {
57 return 0;
58 }
59
60 @Override
61 public void writeToParcel(Parcel out, int flags) {
62 out.writeInt(mAll ? 1 : 0);
63
64 int N = mSections.size();
65 out.writeInt(N);
66 for (int i=0; i<N; i++) {
67 out.writeInt(mSections.get(i));
68 }
69
70 N = mHeaders.size();
71 out.writeInt(N);
72 for (int i=0; i<N; i++) {
73 out.writeByteArray(mHeaders.get(i));
74 }
75
76 out.writeInt(mPrivacyPolicy);
77
78 out.writeString(mReceiverPkg);
79
80 out.writeString(mReceiverCls);
81 }
82
83 public void readFromParcel(Parcel in) {
84 mAll = in.readInt() != 0;
85
86 mSections.clear();
87 int N = in.readInt();
88 for (int i=0; i<N; i++) {
89 mSections.add(in.readInt());
90 }
91
92 mHeaders.clear();
93 N = in.readInt();
94 for (int i=0; i<N; i++) {
95 mHeaders.add(in.createByteArray());
96 }
97
98 mPrivacyPolicy = in.readInt();
99
100 mReceiverPkg = in.readString();
101
102 mReceiverCls = in.readString();
103 }
104
105 public static final @android.annotation.NonNull Parcelable.Creator<IncidentReportArgs> CREATOR
106 = new Parcelable.Creator<IncidentReportArgs>() {
107 public IncidentReportArgs createFromParcel(Parcel in) {
108 return new IncidentReportArgs(in);
109 }
110
111 public IncidentReportArgs[] newArray(int size) {
112 return new IncidentReportArgs[size];
113 }
114 };
115
116 /**
117 * Print this report as a string.
118 */
119 @NonNull
120 @Override
121 public String toString() {
122 final StringBuilder sb = new StringBuilder("Incident(");
123 if (mAll) {
124 sb.append("all");
125 } else {
126 final int N = mSections.size();
127 if (N > 0) {
128 sb.append(mSections.get(0));
129 }
130 for (int i=1; i<N; i++) {
131 sb.append(" ");
132 sb.append(mSections.get(i));
133 }
134 }
135 sb.append(", ");
136 sb.append(mHeaders.size());
137 sb.append(" headers), ");
138 sb.append("privacy: ").append(mPrivacyPolicy);
139 sb.append("receiver pkg: ").append(mReceiverPkg);
140 sb.append("receiver cls: ").append(mReceiverCls);
141 return sb.toString();
142 }
143
144 /**
145 * Set this incident report to include all fields.
146 */
147 public void setAll(boolean all) {
148 mAll = all;
149 if (all) {
150 mSections.clear();
151 }
152 }
153
154 /**
155 * Set this incident report privacy policy spec.
156 */
157 public void setPrivacyPolicy(int privacyPolicy) {
158 switch (privacyPolicy) {
159 case IncidentManager.PRIVACY_POLICY_LOCAL:
160 case IncidentManager.PRIVACY_POLICY_EXPLICIT:
161 case IncidentManager.PRIVACY_POLICY_AUTO:
162 mPrivacyPolicy = privacyPolicy;
163 break;
164 default:
165 mPrivacyPolicy = IncidentManager.PRIVACY_POLICY_AUTO;
166 }
167 }
168
169 /**
170 * Add this section to the incident report. Skip if the input is smaller than 2 since section
171 * id are only valid for positive integer as Protobuf field id. Here 1 is reserved for Header.
172 */
173 public void addSection(int section) {
174 if (!mAll && section > 1) {
175 mSections.add(section);
176 }
177 }
178
179 /**
180 * Returns whether the incident report will include all fields.
181 */
182 public boolean isAll() {
183 return mAll;
184 }
185
186 /**
187 * Returns whether this section will be included in the incident report.
188 */
189 public boolean containsSection(int section) {
190 return mAll || mSections.indexOf(section) >= 0;
191 }
192
193 public int sectionCount() {
194 return mSections.size();
195 }
196
197 public void addHeader(byte[] header) {
198 mHeaders.add(header);
199 }
200 }
201