@amplitude/analytics-react-native 1.3.5 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/java/com/amplitude/reactnative/AmplitudeReactNativeModule.kt +1 -1
- package/android/src/main/java/com/amplitude/reactnative/AndroidContextProvider.kt +10 -126
- package/lib/commonjs/version.js +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/version.ts +1 -1
- package/android/src/main/java/com/amplitude/reactnative/Utils.kt +0 -34
|
@@ -31,7 +31,7 @@ class AmplitudeReactNativeModule(private val reactContext: ReactApplicationConte
|
|
|
31
31
|
private fun getApplicationContext(options: ReadableMap, promise: Promise) {
|
|
32
32
|
val trackAdid = if (options.hasKey("adid")) options.getBoolean("adid") else false
|
|
33
33
|
if (androidContextProvider == null) {
|
|
34
|
-
androidContextProvider = AndroidContextProvider(reactContext.applicationContext,
|
|
34
|
+
androidContextProvider = AndroidContextProvider(reactContext.applicationContext, trackAdid)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
promise.resolve(WritableNativeMap().apply {
|
|
@@ -4,27 +4,18 @@ import android.content.Context
|
|
|
4
4
|
import android.content.pm.PackageInfo
|
|
5
5
|
import android.content.pm.PackageManager
|
|
6
6
|
import android.content.res.Resources
|
|
7
|
-
import android.location.Geocoder
|
|
8
|
-
import android.location.Location
|
|
9
|
-
import android.location.LocationManager
|
|
10
7
|
import android.os.Build
|
|
11
8
|
import android.provider.Settings.Secure
|
|
12
9
|
import android.telephony.TelephonyManager
|
|
13
|
-
import java.io.IOException
|
|
14
10
|
import java.lang.Exception
|
|
15
|
-
import java.lang.IllegalArgumentException
|
|
16
|
-
import java.lang.IllegalStateException
|
|
17
|
-
import java.lang.NullPointerException
|
|
18
11
|
import java.lang.reflect.InvocationTargetException
|
|
19
12
|
import java.util.Locale
|
|
20
13
|
import java.util.UUID
|
|
21
|
-
import kotlin.collections.ArrayList
|
|
22
14
|
|
|
23
|
-
class AndroidContextProvider(private val context: Context,
|
|
24
|
-
var isLocationListening = true
|
|
15
|
+
class AndroidContextProvider(private val context: Context, shouldTrackAdid: Boolean) {
|
|
25
16
|
var shouldTrackAdid = true
|
|
26
17
|
private var cachedInfo: CachedInfo? = null
|
|
27
|
-
|
|
18
|
+
get() {
|
|
28
19
|
if (field == null) {
|
|
29
20
|
field = CachedInfo()
|
|
30
21
|
}
|
|
@@ -110,61 +101,14 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
|
|
|
110
101
|
private fun fetchCountry(): String? {
|
|
111
102
|
// This should not be called on the main thread.
|
|
112
103
|
|
|
113
|
-
|
|
114
|
-
// we try to grab the country from the network, and finally the locale
|
|
115
|
-
var country = countryFromLocation
|
|
116
|
-
if (!country.isNullOrEmpty()) {
|
|
117
|
-
return country
|
|
118
|
-
}
|
|
119
|
-
country = countryFromNetwork
|
|
104
|
+
var country = countryFromNetwork
|
|
120
105
|
return if (!country.isNullOrEmpty()) {
|
|
121
106
|
country
|
|
122
107
|
} else countryFromLocale
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Failed to reverse geocode location
|
|
126
|
-
private val countryFromLocation: String?
|
|
127
|
-
private get() {
|
|
128
|
-
if (!isLocationListening) {
|
|
129
|
-
return null
|
|
130
|
-
}
|
|
131
|
-
val recent = mostRecentLocation
|
|
132
|
-
if (recent != null) {
|
|
133
|
-
try {
|
|
134
|
-
if (Geocoder.isPresent()) {
|
|
135
|
-
val geocoder = geocoder
|
|
136
|
-
val addresses = geocoder.getFromLocation(
|
|
137
|
-
recent.latitude,
|
|
138
|
-
recent.longitude, 1
|
|
139
|
-
)
|
|
140
|
-
if (addresses != null) {
|
|
141
|
-
for (address in addresses) {
|
|
142
|
-
if (address != null) {
|
|
143
|
-
return address.countryCode
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
} catch (e: IOException) {
|
|
149
|
-
// Failed to reverse geocode location
|
|
150
|
-
} catch (e: NullPointerException) {
|
|
151
|
-
// Failed to reverse geocode location
|
|
152
|
-
} catch (e: NoSuchMethodError) {
|
|
153
|
-
// failed to fetch geocoder
|
|
154
|
-
} catch (e: IllegalArgumentException) {
|
|
155
|
-
// Bad lat / lon values can cause Geocoder to throw IllegalArgumentExceptions
|
|
156
|
-
} catch (e: IllegalStateException) {
|
|
157
|
-
// sometimes the location manager is unavailable
|
|
158
|
-
} catch (e: SecurityException) {
|
|
159
|
-
// Customized Android System without Google Play Service Installed
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return null
|
|
163
|
-
}
|
|
108
|
+
}
|
|
164
109
|
|
|
165
|
-
// Failed to get country from network
|
|
166
110
|
private val countryFromNetwork: String?
|
|
167
|
-
|
|
111
|
+
get() {
|
|
168
112
|
try {
|
|
169
113
|
val manager = context
|
|
170
114
|
.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
|
@@ -181,7 +125,7 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
|
|
|
181
125
|
}
|
|
182
126
|
|
|
183
127
|
private val locale: Locale
|
|
184
|
-
|
|
128
|
+
get() {
|
|
185
129
|
val configuration = Resources.getSystem().configuration
|
|
186
130
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
187
131
|
val localeList = configuration.locales
|
|
@@ -196,7 +140,7 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
|
|
|
196
140
|
}
|
|
197
141
|
|
|
198
142
|
private val countryFromLocale: String
|
|
199
|
-
|
|
143
|
+
get() = locale.country
|
|
200
144
|
|
|
201
145
|
private fun fetchLanguage(): String {
|
|
202
146
|
return locale.language
|
|
@@ -243,14 +187,14 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
|
|
|
243
187
|
}
|
|
244
188
|
|
|
245
189
|
private val fetchAndCacheAmazonAdvertisingId: String?
|
|
246
|
-
|
|
190
|
+
get() {
|
|
247
191
|
val cr = context.contentResolver
|
|
248
192
|
limitAdTrackingEnabled = Secure.getInt(cr, SETTING_LIMIT_AD_TRACKING, 0) == 1
|
|
249
193
|
advertisingId = Secure.getString(cr, SETTING_ADVERTISING_ID)
|
|
250
194
|
return advertisingId
|
|
251
195
|
}
|
|
252
196
|
private val fetchAndCacheGoogleAdvertisingId: String?
|
|
253
|
-
|
|
197
|
+
get() {
|
|
254
198
|
try {
|
|
255
199
|
val AdvertisingIdClient = Class
|
|
256
200
|
.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient")
|
|
@@ -348,66 +292,7 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
|
|
|
348
292
|
val advertisingId: String?
|
|
349
293
|
get() = cachedInfo!!.advertisingId
|
|
350
294
|
val appSetId: String
|
|
351
|
-
get() = cachedInfo!!.appSetId
|
|
352
|
-
// Don't crash if the device does not have location services.
|
|
353
|
-
|
|
354
|
-
// It's possible that the location service is running out of process
|
|
355
|
-
// and the remote getProviders call fails. Handle null provider lists.
|
|
356
|
-
val mostRecentLocation: Location?
|
|
357
|
-
get() {
|
|
358
|
-
if (!isLocationListening) {
|
|
359
|
-
return null
|
|
360
|
-
}
|
|
361
|
-
if (!Utils.checkLocationPermissionAllowed(context)) {
|
|
362
|
-
return null
|
|
363
|
-
}
|
|
364
|
-
val locationManager = context
|
|
365
|
-
.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
|
366
|
-
?: return null
|
|
367
|
-
|
|
368
|
-
// Don't crash if the device does not have location services.
|
|
369
|
-
|
|
370
|
-
// It's possible that the location service is running out of process
|
|
371
|
-
// and the remote getProviders call fails. Handle null provider lists.
|
|
372
|
-
var providers: List<String?>? = null
|
|
373
|
-
try {
|
|
374
|
-
providers = locationManager.getProviders(true)
|
|
375
|
-
} catch (e: SecurityException) {
|
|
376
|
-
// failed to get providers list
|
|
377
|
-
} catch (e: Exception) {
|
|
378
|
-
// other causes
|
|
379
|
-
}
|
|
380
|
-
if (providers == null) {
|
|
381
|
-
return null
|
|
382
|
-
}
|
|
383
|
-
val locations: MutableList<Location> = ArrayList()
|
|
384
|
-
for (provider in providers) {
|
|
385
|
-
var location: Location? = null
|
|
386
|
-
try {
|
|
387
|
-
location = locationManager.getLastKnownLocation(provider!!)
|
|
388
|
-
} catch (e: SecurityException) {
|
|
389
|
-
LogcatLogger.logger.warn("Failed to get most recent location")
|
|
390
|
-
} catch (e: Exception) {
|
|
391
|
-
LogcatLogger.logger.warn("Failed to get most recent location")
|
|
392
|
-
}
|
|
393
|
-
if (location != null) {
|
|
394
|
-
locations.add(location)
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
var maximumTimestamp: Long = -1
|
|
398
|
-
var bestLocation: Location? = null
|
|
399
|
-
for (location in locations) {
|
|
400
|
-
if (location.time > maximumTimestamp) {
|
|
401
|
-
maximumTimestamp = location.time
|
|
402
|
-
bestLocation = location
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return bestLocation
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// @VisibleForTesting
|
|
409
|
-
protected val geocoder: Geocoder
|
|
410
|
-
protected get() = Geocoder(context, Locale.ENGLISH)
|
|
295
|
+
get() = cachedInfo!!.appSetId
|
|
411
296
|
|
|
412
297
|
companion object {
|
|
413
298
|
const val OS_NAME = "android"
|
|
@@ -420,7 +305,6 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
|
|
|
420
305
|
}
|
|
421
306
|
|
|
422
307
|
init {
|
|
423
|
-
isLocationListening = locationListening
|
|
424
308
|
this.shouldTrackAdid = shouldTrackAdid
|
|
425
309
|
}
|
|
426
310
|
}
|
package/lib/commonjs/version.js
CHANGED
package/lib/module/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '1.3.
|
|
1
|
+
export const VERSION = '1.3.6';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.3.
|
|
1
|
+
export declare const VERSION = "1.3.6";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-react-native",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Official React Native SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analytics",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
]
|
|
91
91
|
]
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "83cf780dec45f8e8dfcc7310c70ffb4ffe67788e"
|
|
94
94
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '1.3.
|
|
1
|
+
export const VERSION = '1.3.6';
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
package com.amplitude.reactnative
|
|
2
|
-
|
|
3
|
-
import android.Manifest
|
|
4
|
-
import android.app.Activity
|
|
5
|
-
import android.content.Context
|
|
6
|
-
import android.content.pm.PackageManager
|
|
7
|
-
import android.os.Build
|
|
8
|
-
|
|
9
|
-
object Utils {
|
|
10
|
-
|
|
11
|
-
fun checkLocationPermissionAllowed(context: Context?): Boolean {
|
|
12
|
-
return checkPermissionAllowed(context, Manifest.permission.ACCESS_COARSE_LOCATION) ||
|
|
13
|
-
checkPermissionAllowed(context, Manifest.permission.ACCESS_FINE_LOCATION)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
fun checkPermissionAllowed(context: Context?, permission: String?): Boolean {
|
|
17
|
-
// ANDROID 6.0 AND UP!
|
|
18
|
-
return if (Build.VERSION.SDK_INT >= 23) {
|
|
19
|
-
var hasPermission = false
|
|
20
|
-
try {
|
|
21
|
-
// Invoke checkSelfPermission method from Android 6 (API 23 and UP)
|
|
22
|
-
val methodCheckPermission =
|
|
23
|
-
Activity::class.java.getMethod("checkSelfPermission", String::class.java)
|
|
24
|
-
val resultObj = methodCheckPermission.invoke(context, permission)
|
|
25
|
-
val result = resultObj.toString().toInt()
|
|
26
|
-
hasPermission = result == PackageManager.PERMISSION_GRANTED
|
|
27
|
-
} catch (ex: Exception) {
|
|
28
|
-
}
|
|
29
|
-
hasPermission
|
|
30
|
-
} else {
|
|
31
|
-
true
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|