-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
BluetoothData.java
197 lines (156 loc) · 5.52 KB
/
BluetoothData.java
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
package nic.goi.aarogyasetu.models;
import android.os.Build;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import androidx.room.TypeConverters;
import nic.goi.aarogyasetu.utility.CorUtility;
import nic.goi.aarogyasetu.utility.EncryptionUtil;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SignatureException;
import java.security.UnrecoverableEntryException;
import java.security.cert.CertificateException;
import java.util.Calendar;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
@TypeConverters({Converters.class})
@Entity(tableName = "nearby_devices_info_table")
public class BluetoothData {
@ColumnInfo(name = "id")
@SerializedName("id")
@Expose
private int id;
// This is not MAC Address. This is UNIQUE ID Assign to scanned device.
@ColumnInfo(name = "bluetooth_mac_address")
@SerializedName("d")
@Expose
private String bluetoothMacAddress;
// This is the RSSI of the scanned device.
@ColumnInfo(name = "distance")
@SerializedName("dist")
@Expose
private Integer distance;
@ColumnInfo(name = "tx_power")
@SerializedName("tx_power")
@Expose
private String txPower;
@ColumnInfo(name = "tx_power_level")
@SerializedName("tx_power_level")
@Expose
private String txPowerLevel;
@Ignore
private double latitude;
@Ignore
private double longitude;
@ColumnInfo(name = "lat")
@SerializedName("lat")
@Expose
private EncryptedInfo latitudeenc;
@ColumnInfo(name = "long")
@SerializedName("long")
@Expose
private EncryptedInfo longitudeenc;
@PrimaryKey
@ColumnInfo(name = "timestamp")
@SerializedName("ts")
@Expose
private Integer timeStamp;
public BluetoothData(String bluetoothMacAddress, Integer distance, String txPower, String txPowerLevel) {
this.bluetoothMacAddress = bluetoothMacAddress;
this.distance = distance;
this.txPower = txPower;
this.txPowerLevel = txPowerLevel;
timeStamp = CorUtility.Companion.getCurrentEpochTimeInSec();
}
private void setEncLatitute(double latitude) {
EncryptedInfo encryptedInfo = new EncryptedInfo();
try {
encryptedInfo.setData(EncryptionUtil.getInstance().encryptText(String.valueOf(latitude)));
encryptedInfo.setIv(EncryptionUtil.getInstance().getIv());
} catch (UnrecoverableEntryException | NoSuchAlgorithmException | KeyStoreException | NoSuchPaddingException |
InvalidKeyException | InvalidAlgorithmParameterException | IOException | SignatureException | BadPaddingException | IllegalBlockSizeException | CertificateException | NoSuchProviderException e) {
//do nothing
}
this.latitudeenc = encryptedInfo;
}
private void setEncLongitude(double longitude) {
EncryptedInfo encryptedInfo = new EncryptedInfo();
try {
encryptedInfo.setData(EncryptionUtil.getInstance().encryptText(String.valueOf(longitude)));
encryptedInfo.setIv(EncryptionUtil.getInstance().getIv());
} catch (UnrecoverableEntryException | NoSuchAlgorithmException | KeyStoreException | NoSuchPaddingException |
InvalidKeyException | InvalidAlgorithmParameterException | IOException | SignatureException | BadPaddingException | IllegalBlockSizeException | CertificateException | NoSuchProviderException e) {
//do nothing
}
this.longitudeenc = encryptedInfo;
}
public String getBluetoothMacAddress() {
return bluetoothMacAddress;
}
public void setBluetoothMacAddress(String bluetoothMacAddress) {
this.bluetoothMacAddress = bluetoothMacAddress;
}
public Integer getDistance() {
return distance;
}
public void setDistance(Integer distance) {
this.distance = distance;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public EncryptedInfo getLatitudeenc() {
return latitudeenc;
}
public void setLatitudeenc(EncryptedInfo latitudeenc) {
this.latitudeenc = latitudeenc;
}
public EncryptedInfo getLongitudeenc() {
return longitudeenc;
}
public void setLongitudeenc(EncryptedInfo longitudeenc) {
this.longitudeenc = longitudeenc;
}
public Integer getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(Integer timeStamp) {
this.timeStamp = timeStamp;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
setEncLatitute(latitude);
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
setEncLongitude(longitude);
}
public String getTxPower() {
return txPower;
}
public void setTxPower(String txPower) {
this.txPower = txPower;
}
public String getTxPowerLevel() {
return txPowerLevel;
}
public void setTxPowerLevel(String txPowerLevel) {
this.txPowerLevel = txPowerLevel;
}
}