forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
236 lines (208 loc) · 7.22 KB
/
Copy pathApp.java
File metadata and controls
236 lines (208 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package io.sentry.protocol;
import io.sentry.ILogger;
import io.sentry.JsonDeserializer;
import io.sentry.JsonObjectReader;
import io.sentry.JsonObjectWriter;
import io.sentry.JsonSerializable;
import io.sentry.JsonUnknown;
import io.sentry.util.CollectionUtils;
import io.sentry.vendor.gson.stream.JsonToken;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class App implements JsonUnknown, JsonSerializable {
public static final String TYPE = "app";
/** Version-independent application identifier, often a dotted bundle ID. */
private @Nullable String appIdentifier;
/**
* Start time of the app.
*
* <p>Formatted UTC timestamp when the user started the application.
*/
private @Nullable Date appStartTime;
/** Application-specific device identifier. */
private @Nullable String deviceAppHash;
/** String identifying the kind of build. For example, `testflight`. */
private @Nullable String buildType;
/** Application name as it appears on the platform. */
private @Nullable String appName;
/** Application version as it appears on the platform. */
private @Nullable String appVersion;
/** Internal build ID as it appears on the platform. */
private @Nullable String appBuild;
/** Application permissions in the form of "permission_name" : "granted|not_granted" */
private @Nullable Map<String, String> permissions;
public App() {}
App(final @NotNull App app) {
this.appBuild = app.appBuild;
this.appIdentifier = app.appIdentifier;
this.appName = app.appName;
this.appStartTime = app.appStartTime;
this.appVersion = app.appVersion;
this.buildType = app.buildType;
this.deviceAppHash = app.deviceAppHash;
this.permissions = CollectionUtils.newConcurrentHashMap(app.permissions);
this.unknown = CollectionUtils.newConcurrentHashMap(app.unknown);
}
@SuppressWarnings("unused")
private @Nullable Map<String, @NotNull Object> unknown;
public @Nullable String getAppIdentifier() {
return appIdentifier;
}
public void setAppIdentifier(final @Nullable String appIdentifier) {
this.appIdentifier = appIdentifier;
}
@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
public @Nullable Date getAppStartTime() {
final Date appStartTimeRef = appStartTime;
return appStartTimeRef != null ? (Date) appStartTimeRef.clone() : null;
}
public void setAppStartTime(final @Nullable Date appStartTime) {
this.appStartTime = appStartTime;
}
public @Nullable String getDeviceAppHash() {
return deviceAppHash;
}
public void setDeviceAppHash(final @Nullable String deviceAppHash) {
this.deviceAppHash = deviceAppHash;
}
public @Nullable String getBuildType() {
return buildType;
}
public void setBuildType(final @Nullable String buildType) {
this.buildType = buildType;
}
public @Nullable String getAppName() {
return appName;
}
public void setAppName(final @Nullable String appName) {
this.appName = appName;
}
public @Nullable String getAppVersion() {
return appVersion;
}
public void setAppVersion(final @Nullable String appVersion) {
this.appVersion = appVersion;
}
public @Nullable String getAppBuild() {
return appBuild;
}
public void setAppBuild(final @Nullable String appBuild) {
this.appBuild = appBuild;
}
public @Nullable Map<String, String> getPermissions() {
return permissions;
}
public void setPermissions(@Nullable Map<String, String> permissions) {
this.permissions = permissions;
}
// region json
@Nullable
@Override
public Map<String, Object> getUnknown() {
return unknown;
}
@Override
public void setUnknown(@Nullable Map<String, Object> unknown) {
this.unknown = unknown;
}
public static final class JsonKeys {
public static final String APP_IDENTIFIER = "app_identifier";
public static final String APP_START_TIME = "app_start_time";
public static final String DEVICE_APP_HASH = "device_app_hash";
public static final String BUILD_TYPE = "build_type";
public static final String APP_NAME = "app_name";
public static final String APP_VERSION = "app_version";
public static final String APP_BUILD = "app_build";
public static final String APP_PERMISSIONS = "permissions";
}
@Override
public void serialize(@NotNull JsonObjectWriter writer, @NotNull ILogger logger)
throws IOException {
writer.beginObject();
if (appIdentifier != null) {
writer.name(JsonKeys.APP_IDENTIFIER).value(appIdentifier);
}
if (appStartTime != null) {
writer.name(JsonKeys.APP_START_TIME).value(logger, appStartTime);
}
if (deviceAppHash != null) {
writer.name(JsonKeys.DEVICE_APP_HASH).value(deviceAppHash);
}
if (buildType != null) {
writer.name(JsonKeys.BUILD_TYPE).value(buildType);
}
if (appName != null) {
writer.name(JsonKeys.APP_NAME).value(appName);
}
if (appVersion != null) {
writer.name(JsonKeys.APP_VERSION).value(appVersion);
}
if (appBuild != null) {
writer.name(JsonKeys.APP_BUILD).value(appBuild);
}
if (permissions != null && !permissions.isEmpty()) {
writer.name(JsonKeys.APP_PERMISSIONS).value(logger, permissions);
}
if (unknown != null) {
for (String key : unknown.keySet()) {
Object value = unknown.get(key);
writer.name(key).value(logger, value);
}
}
writer.endObject();
}
public static final class Deserializer implements JsonDeserializer<App> {
@SuppressWarnings("unchecked")
@Override
public @NotNull App deserialize(@NotNull JsonObjectReader reader, @NotNull ILogger logger)
throws Exception {
reader.beginObject();
App app = new App();
Map<String, Object> unknown = null;
while (reader.peek() == JsonToken.NAME) {
final String nextName = reader.nextName();
switch (nextName) {
case JsonKeys.APP_IDENTIFIER:
app.appIdentifier = reader.nextStringOrNull();
break;
case JsonKeys.APP_START_TIME:
app.appStartTime = reader.nextDateOrNull(logger);
break;
case JsonKeys.DEVICE_APP_HASH:
app.deviceAppHash = reader.nextStringOrNull();
break;
case JsonKeys.BUILD_TYPE:
app.buildType = reader.nextStringOrNull();
break;
case JsonKeys.APP_NAME:
app.appName = reader.nextStringOrNull();
break;
case JsonKeys.APP_VERSION:
app.appVersion = reader.nextStringOrNull();
break;
case JsonKeys.APP_BUILD:
app.appBuild = reader.nextStringOrNull();
break;
case JsonKeys.APP_PERMISSIONS:
app.permissions =
CollectionUtils.newConcurrentHashMap(
(Map<String, String>) reader.nextObjectOrNull());
break;
default:
if (unknown == null) {
unknown = new ConcurrentHashMap<>();
}
reader.nextUnknown(logger, unknown, nextName);
break;
}
}
app.setUnknown(unknown);
reader.endObject();
return app;
}
}
}