summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java
blob: 132b62008690069d11368efadcfe58b1780f5554 (plain)
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
package com.mapbox.mapboxsdk.module.telemetry;

import android.content.Context;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.mapbox.android.telemetry.Event;
import com.mapbox.android.telemetry.TelemetryUtils;

class MapLoadEvent extends Event implements Parcelable {
  private static final String MAP_LOAD = "map.load";
  private static final String OPERATING_SYSTEM = "Android - " + Build.VERSION.RELEASE;

  @SerializedName("event")
  private final String event;
  @SerializedName("created")
  private String created;
  @SerializedName("userId")
  private String userId;
  @SerializedName("model")
  private String model = null;
  @SerializedName("operatingSystem")
  private String operatingSystem = null;
  @SerializedName("resolution")
  private Float resolution = null;
  @SerializedName("accessibilityFontScale")
  private Float accessibilityFontScale = null;
  @SerializedName("orientation")
  private String orientation = null;
  @SerializedName("batteryLevel")
  private Integer batteryLevel;
  @SerializedName("pluggedIn")
  private Boolean pluggedIn;
  @SerializedName("carrier")
  private String carrier = null;
  @SerializedName("cellularNetworkType")
  private String cellularNetworkType;
  @SerializedName("wifi")
  private Boolean wifi = null;
  @SerializedName("sdkIdentifier")
  private String sdkIdentifier = null;
  @SerializedName("sdkVersion")
  private String sdkVersion = null;

  MapLoadEvent(String userId) {
    this.event = MAP_LOAD;
    this.model = Build.MODEL;
    this.operatingSystem = OPERATING_SYSTEM;
    this.created = TelemetryUtils.obtainCurrentDate();
    this.userId = userId;
    this.batteryLevel = 0;
    this.pluggedIn = false;
    this.cellularNetworkType = "";
  }

  MapLoadEvent setDeviceInfo(Context context) {
    this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
    this.pluggedIn = TelemetryUtils.isPluggedIn(context);
    this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
    return this;
  }

  void setResolution(float resolution) {
    this.resolution = resolution;
  }

  void setAccessibilityFontScale(float accessibilityFontScale) {
    this.accessibilityFontScale = accessibilityFontScale;
  }

  void setOrientation(String orientation) {
    this.orientation = orientation;
  }

  void setCarrier(String carrier) {
    this.carrier = carrier;
  }

  void setWifi(boolean wifi) {
    this.wifi = wifi;
  }

  void setSdkIdentifier(String sdkIdentifier) {
    this.sdkIdentifier = sdkIdentifier;
  }

  void setSdkVersion(String sdkVersion) {
    this.sdkVersion = sdkVersion;
  }

  private MapLoadEvent(Parcel in) {
    event = in.readString();
    created = in.readString();
    userId = in.readString();
    model = in.readString();
    operatingSystem = in.readString();
    resolution = in.readByte() == 0x00 ? null : in.readFloat();
    accessibilityFontScale = in.readByte() == 0x00 ? null : in.readFloat();
    orientation = in.readString();
    batteryLevel = in.readInt();
    pluggedIn = in.readByte() != 0x00;
    carrier = in.readString();
    cellularNetworkType = in.readString();
    byte wifiVal = in.readByte();
    wifi = wifiVal == 0x02 ? null : wifiVal != 0x00;
    sdkIdentifier = in.readString();
    sdkVersion = in.readString();
  }

  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(event);
    dest.writeString(created);
    dest.writeString(userId);
    dest.writeString(model);
    dest.writeString(operatingSystem);
    if (resolution == null) {
      dest.writeByte((byte) (0x00));
    } else {
      dest.writeByte((byte) (0x01));
      dest.writeFloat(resolution);
    }
    if (accessibilityFontScale == null) {
      dest.writeByte((byte) (0x00));
    } else {
      dest.writeByte((byte) (0x01));
      dest.writeFloat(accessibilityFontScale);
    }
    dest.writeString(orientation);
    dest.writeInt(batteryLevel);
    dest.writeByte((byte) (pluggedIn ? 0x01 : 0x00));
    dest.writeString(carrier);
    dest.writeString(cellularNetworkType);
    if (wifi == null) {
      dest.writeByte((byte) (0x02));
    } else {
      dest.writeByte((byte) (wifi ? 0x01 : 0x00));
    }
    dest.writeString(sdkIdentifier);
    dest.writeString(sdkVersion);
  }

  @SuppressWarnings("unused")
  public static final Creator<MapLoadEvent> CREATOR = new Creator<MapLoadEvent>() {
    @Override
    public MapLoadEvent createFromParcel(Parcel in) {
      return new MapLoadEvent(in);
    }

    @Override
    public MapLoadEvent[] newArray(int size) {
      return new MapLoadEvent[size];
    }
  };
}