Skip to content

Commit 9792316

Browse files
authored
UPDATE react-native-hms-dtm 5.2.0-300 (#103)
* UPDATE react-native-hms-dtm 5.2.0-300
1 parent 9547624 commit 9792316

12 files changed

Lines changed: 149 additions & 13520 deletions

File tree

react-native-hms-dtm/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<p align="center">
77
<a href="https://www.npmjs.com/package/@hmscore/react-native-hms-dtm"><img src="https://img.shields.io/npm/dm/@hmscore/react-native-hms-dtm?color=%23007EC6&style=for-the-badge" alt="downloads"></a>
88
<a href="https://www.npmjs.com/package/@hmscore/react-native-hms-dtm"><img src="https://img.shields.io/npm/v/@hmscore/react-native-hms-dtm?color=%23ed2a1c&style=for-the-badge" alt="NPM version"></a>
9-
<a href="/LICENCE"><img src="https://img.shields.io/npm/l/@hmscore/react-native-hms-dtm.svg?color=%3bcc62&style=for-the-badge" alt="Licence"></a>
9+
<a href="./LICENCE"><img src="https://img.shields.io/npm/l/@hmscore/react-native-hms-dtm.svg?color=%3bcc62&style=for-the-badge" alt="Licence"></a>
1010
</p>
1111

1212
----
@@ -15,7 +15,7 @@ HUAWEI Dynamic Tag Manager (DTM) is a dynamic tag management system. With DTM, i
1515

1616
The React Native Plugin enables communication between HUAWEI DTM SDK and React Native platform. HUAWEI DTM offers you a range of preset DTM models so you can gain a deeper insight in.
1717

18-
[> Learn More](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/about-the-service-0000001055654101)
18+
[> Learn More](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/about-the-service-0000001055654101?ha_source=hms1)
1919

2020
## Installation
2121

@@ -25,21 +25,22 @@ $ npm i @hmscore/react-native-hms-dtm
2525

2626
## Documentation
2727

28-
- [Quick Start](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/integrating-sdk-0000001077774624)
29-
- [Reference](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References-V1/overview-0000001057153998-V1)
28+
- [Quick Start](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/integrating-sdk-0000001077774624?ha_source=hms1)
29+
- [Reference](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References-V1/overview-0000001057153998-V1?ha_source=hms1)
3030

3131
### Additional Topics
32-
- [Operations on the Server](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/operation-server-overview-0000001077378810)
33-
- [Development Guide](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/dev-guide-overiview-0000001096471561)
32+
33+
- [Operations on the Server](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/operation-server-overview-0000001077378810?ha_source=hms1)
34+
- [Development Guide](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/dev-guide-overiview-0000001096471561?ha_source=hms1)
3435

3536
## Questions or Issues
3637

3738
If you have questions about how to use HMS samples, try the following options:
3839
- [Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services) is the best place for any programming questions. Be sure to tag your question with
3940
**huawei-mobile-services**.
4041
- [Github](https://github.com/HMS-Core/hms-react-native-plugin) is the official repository for these plugins, You can open an issue or submit your ideas.
41-
- [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101187876626530001) HMS Core Module is great for general questions, or seeking recommendations and opinions.
42-
- [Huawei Developer Docs](https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin) is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.
42+
- [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101187876626530001&ha_source=hms1) HMS Core Module is great for general questions, or seeking recommendations and opinions.
43+
- [Huawei Developer Docs](https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1) is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.
4344

4445
If you run into a bug in our samples, please submit an issue to the [GitHub repository](https://github.com/HMS-Core/hms-react-native-plugin).
4546

react-native-hms-dtm/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ dependencies {
4949
implementation fileTree(include: ['*.jar'], dir: 'libs')
5050
implementation 'com.facebook.react:react-native:+'
5151

52-
implementation 'com.huawei.hms:hianalytics:5.1.0.300'
53-
implementation 'com.huawei.hms:dtm-api:5.1.0.300'
52+
implementation 'com.huawei.hms:hianalytics:5.2.0.300'
53+
implementation 'com.huawei.hms:dtm-api:5.2.0.300'
5454

5555
def supportLibVersion = safeExtGet('supportLibVersion', '27.1.1')
5656
def supportLibMajorVersion = supportLibVersion.split('\\.')[0] as int

react-native-hms-dtm/android/src/main/java/com/huawei/hms/rn/dtm/logger/HMSLogger.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.huawei.hms.rn.dtm.logger;
1717

18+
import static android.os.Build.DEVICE;
19+
1820
import android.content.Context;
1921
import android.content.pm.PackageManager;
2022
import android.net.ConnectivityManager;
@@ -30,13 +32,14 @@
3032
import java.util.HashMap;
3133
import java.util.Map;
3234

33-
import static android.os.Build.DEVICE;
34-
3535
public final class HMSLogger {
3636
private static final String TAG = "HMSLogger";
3737

38-
private static final String VERSION = "5.1.0.300";
39-
private static final String SERVICE = "ReactNativeDTM";
38+
private static final String KIT = "ReactNativeDTM";
39+
private static final String PLATFORM = "ReactNative";
40+
private static final String VERSION = "5.2.0.300";
41+
42+
private static final String SERVICE = "Cross-Platform";
4043

4144
private static final String SUCCESS = "0";
4245
private static final String UNKNOWN = "UNKNOWN";
@@ -46,7 +49,6 @@ public final class HMSLogger {
4649
private static final String PERIODIC_EVENT_ID = "60001";
4750

4851
private static final String NETWORK_TYPE_WIFI = "WIFI";
49-
5052
private static volatile HMSLogger instance;
5153

5254
private final WeakReference<Context> weakContext;
@@ -75,8 +77,8 @@ private HMSLogger(final Context context) {
7577
hiAnalyticsUtils = HiAnalyticsUtils.getInstance();
7678
connectivityManager = objectCast(context.getSystemService(Context.CONNECTIVITY_SERVICE),
7779
ConnectivityManager.class);
78-
hiAnalyticsUtils.enableLog();
7980

81+
hiAnalyticsUtils.enableLog();
8082
HMSBIInitializer.getInstance(context).initBI();
8183
setupEventMap(singleEventMap);
8284
setupEventMap(periodicEventMap);
@@ -105,7 +107,7 @@ public static synchronized HMSLogger getInstance(final Context context) {
105107
*
106108
* @return Actual context reference
107109
*/
108-
private Context getContext() {
110+
private synchronized Context getContext() {
109111
return weakContext.get();
110112
}
111113

@@ -202,7 +204,7 @@ private synchronized void sendEvent(final String eventId, final String methodNam
202204
*
203205
* @return app_id value or NOT_AVAILABLE if not found
204206
*/
205-
private String getAppId() {
207+
private synchronized String getAppId() {
206208
try {
207209
return AGConnectServicesConfig.fromContext(getContext()).getString("client/app_id");
208210
} catch (final NullPointerException e) {
@@ -217,7 +219,7 @@ private String getAppId() {
217219
* @param packageName Package name of the app
218220
* @return App version name in String type
219221
*/
220-
private String getAppVersionName(final String packageName) {
222+
private synchronized String getAppVersionName(final String packageName) {
221223
try {
222224
return getContext().getPackageManager().getPackageInfo(packageName, 0).versionName;
223225
} catch (final PackageManager.NameNotFoundException e) {
@@ -231,7 +233,7 @@ private String getAppVersionName(final String packageName) {
231233
*
232234
* @return Human readable network type; such as WIFI, 4G
233235
*/
234-
private String getNetworkType() {
236+
private synchronized String getNetworkType() {
235237
if (connectivityManager != null) {
236238
final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
237239
if (networkInfo != null && networkInfo.isConnected()) {
@@ -257,7 +259,9 @@ private String getNetworkType() {
257259
*
258260
* @param map HashMap to put default values
259261
*/
260-
private void setupEventMap(final Map<String, Object> map) {
262+
private synchronized void setupEventMap(final Map<String, Object> map) {
263+
map.put("kit", KIT);
264+
map.put("platform", PLATFORM);
261265
map.put("version", VERSION);
262266
map.put("service", SERVICE);
263267
map.put("appid", getAppId());
@@ -273,7 +277,7 @@ private void setupEventMap(final Map<String, Object> map) {
273277
* @param resultCode Code of the method's result. "0" for success, others for error
274278
* @param currentTime Current timestamp in millisecond
275279
*/
276-
private void putToSingleEventMap(final String methodName, final String resultCode, final long currentTime) {
280+
private synchronized void putToSingleEventMap(final String methodName, final String resultCode, final long currentTime) {
277281
final long startTime = getOrDefault(startTimeMap, methodName, currentTime);
278282
final int costTime = (int) (currentTime - startTime);
279283
singleEventMap.put("apiName", methodName);
@@ -290,7 +294,8 @@ private void putToSingleEventMap(final String methodName, final String resultCod
290294
* @param resultCode Code of the method's result. "0" for success, others for error
291295
* @param currentTime Current timestamp in millisecond
292296
*/
293-
private void putToPeriodicEventMap(final String methodName, final String resultCode, final long currentTime) {
297+
private synchronized void putToPeriodicEventMap(final String methodName, final String resultCode,
298+
final long currentTime) {
294299
increaseResultCodeCount(methodName, resultCode);
295300
increaseMapValue(methodName, allCountMap);
296301

@@ -326,9 +331,8 @@ private void putToPeriodicEventMap(final String methodName, final String resultC
326331
*
327332
* @return HashMap of human readable network type names
328333
*/
329-
private Map<Integer, String> createNetworkTypeMap() {
334+
private synchronized Map<Integer, String> createNetworkTypeMap() {
330335
final Map<Integer, String> map = new HashMap<>();
331-
332336
map.put(0, UNKNOWN);
333337
map.put(1, "2G");
334338
map.put(2, "2G");
@@ -360,7 +364,7 @@ private Map<Integer, String> createNetworkTypeMap() {
360364
* @param methodName Name of the calling method
361365
* @param resultCode Code of the method's result. "0" for success, others for error
362366
*/
363-
private void increaseResultCodeCount(final String methodName, final String resultCode) {
367+
private synchronized void increaseResultCodeCount(final String methodName, final String resultCode) {
364368
final Map<String, Long> map = getOrDefault(resultCodeCountMap, methodName, new HashMap<>());
365369

366370
increaseMapValue(resultCode, map);
@@ -373,7 +377,7 @@ private void increaseResultCodeCount(final String methodName, final String resul
373377
* @param key Key for map lookup
374378
* @param map The Map that contains the key and its corresponding value
375379
*/
376-
private void increaseMapValue(final String key, final Map<String, Long> map) {
380+
private synchronized void increaseMapValue(final String key, final Map<String, Long> map) {
377381
map.put(key, getOrDefault(map, key, 0L) + 1);
378382
}
379383

@@ -387,7 +391,7 @@ private void increaseMapValue(final String key, final Map<String, Long> map) {
387391
* @param <V> Generic type of the value
388392
* @return Corresponding value or default value
389393
*/
390-
private <K, V> V getOrDefault(final Map<K, V> map, final K key, final V defaultValue) {
394+
private synchronized <K, V> V getOrDefault(final Map<K, V> map, final K key, final V defaultValue) {
391395
return map.containsKey(key) ? map.get(key) : defaultValue;
392396
}
393397

@@ -400,7 +404,7 @@ private <K, V> V getOrDefault(final Map<K, V> map, final K key, final V defaultV
400404
* @param <K> Generic type of the key
401405
* @param <V> Generic type of the value
402406
*/
403-
private <K, V> void putIfAbsent(final Map<K, V> map, final K key, final V value) {
407+
private synchronized <K, V> void putIfAbsent(final Map<K, V> map, final K key, final V value) {
404408
if (!map.containsKey(key)) {
405409
map.put(key, value);
406410
}
@@ -415,7 +419,7 @@ private <K, V> void putIfAbsent(final Map<K, V> map, final K key, final V value)
415419
* @param <D> Destination type
416420
* @return Object that casted to D type
417421
*/
418-
private <S, D> D objectCast(final S source, final Class<D> clazz) {
422+
private synchronized <S, D> D objectCast(final S source, final Class<D> clazz) {
419423
return clazz.cast(source);
420424
}
421425
}

react-native-hms-dtm/example/App.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
Text,
2222
View,
2323
ScrollView,
24-
Image,
2524
DeviceEventEmitter
2625
} from 'react-native';
2726

@@ -163,13 +162,8 @@ export default class App extends React.Component {
163162

164163
<View style={styles.header}>
165164
<Text style={styles.headerTitle}>HMS DTM Plugin</Text>
166-
<Image
167-
resizeMode="contain"
168-
style={styles.headerLogo}
169-
source={require('./assets/images/huawei_icon.jpg')} />
170165
</View>
171166

172-
173167
<ScrollView
174168
ref={(scrollView) => { this._scrollView = scrollView; }}
175169
onScroll={this.handleScroll}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# React-Native HMS DTM - Demo
2+
3+
---
4+
5+
## Contents
6+
7+
- [Introduction](#1-introduction)
8+
- [Installation](#2-installation)
9+
- [Configuration](#3-configuration)
10+
- [Licensing and Terms](#4-licensing-and-terms)
11+
12+
---
13+
14+
## 1. Introduction
15+
16+
This demo project is an example to demonstrate the features of the **Huawei React-Native DTM Kit** Plugin.
17+
18+
---
19+
20+
## 2. Installation
21+
22+
Before you get started, you must register as a HUAWEI developer and complete identity verification on the [HUAWEI Developer](https://developer.huawei.com/consumer/en/?ha_source=hms1) website. For details, please refer to [Register a HUAWEI ID](https://developer.huawei.com/consumer/en/doc/10104?ha_source=hms1).
23+
24+
### Creating a Project in AppGallery Connect
25+
Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:
26+
27+
**Step 1.** Set an unique **Application ID** on the app level build gradle file located on **example/android/app/build.gradle**. You should also change the **package names** for the manifest files in the **/example/android/app/src/** directory to match with the Application ID.
28+
```gradle
29+
<!-- Other configurations ... -->
30+
defaultConfig {
31+
// Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). You may need to change the package name on AndroidManifest.xml and MainActivity.java respectively.
32+
// The Application ID here should match with the Package Name on the AppGalleryConnect
33+
applicationId "<Enter_Your_Package_Here>"
34+
<!-- Other configurations ... -->
35+
}
36+
```
37+
38+
**Step 2.** Sign in to [AppGallery Connect](https://developer.huawei.com/consumer/en/service/josp/agc/index.html?ha_source=hms1) and select **My projects**.
39+
40+
**Step 3.** Select your project from the project list or create a new one by clicking the **Add Project** button.
41+
42+
**Step 4.** Go to **Project Setting** > **General information**, and click **Add app**.
43+
If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click **Add app**.
44+
45+
**Step 5.** On the **Add app** page, enter the **Application ID** you've defined before as the **Package Name** here, then fill the necessary fields and click **OK**.
46+
47+
**Step 6:** Copy the **agconnect-service.json** file to the **android/app** directory of your React Native project.
48+
49+
### Configuring the Signing Certificate Fingerprint
50+
51+
A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core (APK) through the HMS SDK. Before using the HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in the **AppGallery Connect**. You can refer to 3rd and 4th steps of [Generating a Signing Certificate](https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html?ha_source=hms1#2) codelab tutorial for the certificate generation. Perform the following steps after you have generated the certificate.
52+
53+
**Step 1:** Sign in to [AppGallery Connect](https://developer.huawei.com/consumer/en/service/josp/agc/index.html?ha_source=hms1) and select your project from **My Projects**. Then go to **Project Setting** > **General information**. In the **App information** field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained **SHA-256 certificate fingerprint**.
54+
55+
**Step 2:** After completing the configuration, click **OK** to save the changes. (Check mark icon)
56+
57+
**Step 3:** Enter the properties of the key you generated to the **build.gradle** file located on **example/android/app/build.gradle**.
58+
```
59+
signingConfigs {
60+
config {
61+
storeFile file('<keystore_file>')
62+
keyAlias '<key_alias>'
63+
keyPassword '<key_password>'
64+
storePassword '<keystore_password>'
65+
v1SigningEnabled true
66+
v2SigningEnabled true
67+
}
68+
}
69+
```
70+
**Step 4:** Check whether the **agconnect-services.json** file and signature file are placed in **android/app** directory of the React Native project.
71+
72+
### Build & Run the project
73+
74+
- In *example* folder, run command as follows.
75+
76+
```
77+
npm run i
78+
```
79+
80+
- Run the app by executing following command.
81+
82+
```bash
83+
react-native run-android
84+
```
85+
86+
---
87+
88+
## 3. Configuration
89+
90+
No.
91+
92+
---
93+
94+
## 4. Licensing and Terms
95+
96+
Huawei React-Native HMS DTM - Demo is licensed under [Apache 2.0 license](LICENCE)
Binary file not shown.

react-native-hms-dtm/example/app.json

Lines changed: 0 additions & 4 deletions
This file was deleted.
-35.3 KB
Binary file not shown.

react-native-hms-dtm/example/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616

1717
import { AppRegistry } from 'react-native';
1818
import App from './App';
19-
import { name as appName } from './app.json';
2019

21-
AppRegistry.registerComponent(appName, () => App);
20+
AppRegistry.registerComponent("RNHMSDTM Demo", () => App);

0 commit comments

Comments
 (0)