| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 29 |
|
| 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 |
|
| 43 |
|
| 44 |
public IncidentReportArgs() { |
| 45 |
mPrivacyPolicy = IncidentManager.PRIVACY_POLICY_AUTO; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 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 |
|
| 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 |
|
| 146 |
|
| 147 |
public void setAll(boolean all) { |
| 148 |
mAll = all; |
| 149 |
if (all) { |
| 150 |
mSections.clear(); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 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 |
|
| 171 |
|
| 172 |
|
| 173 |
public void addSection(int section) { |
| 174 |
if (!mAll && section > 1) { |
| 175 |
mSections.add(section); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
public boolean isAll() { |
| 183 |
return mAll; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 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 |
|