From 27af2af83e5c7c5849a03afa754b83ca8c5c67ce Mon Sep 17 00:00:00 2001 From: Joonas Kerttula Date: Thu, 30 Apr 2026 13:54:46 +0300 Subject: [PATCH] feat: internal usage attribution ID --- android/build.gradle | 1 + android/src/main/AndroidManifest.xml | 12 +++++- .../MapViewControllerReadyListener.java | 21 ++++++++++ .../react/navsdk/NavSdkInitializer.java | 39 +++++++++++++++++++ .../android/react/navsdk/SdkVersion.java | 27 +++++++++++++ ios/react-native-navigation-sdk/NavModule.mm | 2 + .../RNNavSdkAttribution.m | 29 ++++++++++++++ ios/react-native-navigation-sdk/SdkVersion.h | 19 +++++++++ release-please-config.json | 6 ++- 9 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 android/src/main/java/com/google/android/react/navsdk/MapViewControllerReadyListener.java create mode 100644 android/src/main/java/com/google/android/react/navsdk/NavSdkInitializer.java create mode 100644 android/src/main/java/com/google/android/react/navsdk/SdkVersion.java create mode 100644 ios/react-native-navigation-sdk/RNNavSdkAttribution.m create mode 100644 ios/react-native-navigation-sdk/SdkVersion.h diff --git a/android/build.gradle b/android/build.gradle index 1abb278c..4f0fcf83 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -55,6 +55,7 @@ android { dependencies { implementation 'com.facebook.react:react-native:+' + implementation 'androidx.startup:startup-runtime:1.2.0' implementation "androidx.car.app:app:1.4.0" implementation "androidx.car.app:app-projected:1.4.0" implementation 'androidx.constraintlayout:constraintlayout:2.1.4' diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 5c664b46..675b5c15 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -14,12 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. --> - + + + + diff --git a/android/src/main/java/com/google/android/react/navsdk/MapViewControllerReadyListener.java b/android/src/main/java/com/google/android/react/navsdk/MapViewControllerReadyListener.java new file mode 100644 index 00000000..79909893 --- /dev/null +++ b/android/src/main/java/com/google/android/react/navsdk/MapViewControllerReadyListener.java @@ -0,0 +1,21 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.react.navsdk; + +interface MapViewControllerReadyListener { + void onMapViewControllerReady(int viewId); +} diff --git a/android/src/main/java/com/google/android/react/navsdk/NavSdkInitializer.java b/android/src/main/java/com/google/android/react/navsdk/NavSdkInitializer.java new file mode 100644 index 00000000..ae699cdf --- /dev/null +++ b/android/src/main/java/com/google/android/react/navsdk/NavSdkInitializer.java @@ -0,0 +1,39 @@ +/** + * Copyright 2026 Google LLC + * + *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.react.navsdk; + +import android.content.Context; +import androidx.annotation.NonNull; +import androidx.startup.Initializer; +import com.google.android.gms.maps.MapsApiSettings; +import java.util.Collections; +import java.util.List; + +/** Registers the Navigation SDK internal usage attribution ID at application startup. */ +public final class NavSdkInitializer implements Initializer { + + @NonNull + @Override + public Void create(@NonNull Context context) { + MapsApiSettings.addInternalUsageAttributionId( + context.getApplicationContext(), SdkVersion.ATTRIBUTION_ID); + return null; + } + + @NonNull + @Override + public List>> dependencies() { + return Collections.emptyList(); + } +} diff --git a/android/src/main/java/com/google/android/react/navsdk/SdkVersion.java b/android/src/main/java/com/google/android/react/navsdk/SdkVersion.java new file mode 100644 index 00000000..d7a7024c --- /dev/null +++ b/android/src/main/java/com/google/android/react/navsdk/SdkVersion.java @@ -0,0 +1,27 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.react.navsdk; + +/** SDK version constants for internal usage attribution. */ +public final class SdkVersion { + public static final String VERSION = "0.15.1"; // {x-release-please-version} + + public static final String ATTRIBUTION_ID = + "gmp_git_reactnativenavigationsdk_v" + VERSION + "_android"; + + private SdkVersion() {} +} diff --git a/ios/react-native-navigation-sdk/NavModule.mm b/ios/react-native-navigation-sdk/NavModule.mm index 7ce3489f..a13d210e 100644 --- a/ios/react-native-navigation-sdk/NavModule.mm +++ b/ios/react-native-navigation-sdk/NavModule.mm @@ -15,9 +15,11 @@ */ #import "NavModule.h" +#import #import "NavAutoModule.h" #import "NavViewModule.h" #import "ObjectTranslationUtil.h" +#import "SdkVersion.h" using namespace JS::NativeNavModule; diff --git a/ios/react-native-navigation-sdk/RNNavSdkAttribution.m b/ios/react-native-navigation-sdk/RNNavSdkAttribution.m new file mode 100644 index 00000000..8724d11a --- /dev/null +++ b/ios/react-native-navigation-sdk/RNNavSdkAttribution.m @@ -0,0 +1,29 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import +#import "SdkVersion.h" + +@interface RNNavSdkAttribution : NSObject +@end + +@implementation RNNavSdkAttribution + ++ (void)load { + NSString *attributionId = + [NSString stringWithFormat:@"gmp_git_reactnativenavigationsdk_v%@_ios", kRNNavSdkVersion]; + [GMSServices addInternalUsageAttributionID:attributionId]; +} + +@end diff --git a/ios/react-native-navigation-sdk/SdkVersion.h b/ios/react-native-navigation-sdk/SdkVersion.h new file mode 100644 index 00000000..2b9c2166 --- /dev/null +++ b/ios/react-native-navigation-sdk/SdkVersion.h @@ -0,0 +1,19 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +static NSString *const kRNNavSdkVersion = @"0.15.1"; // x-release-please-version diff --git a/release-please-config.json b/release-please-config.json index 4751b22b..6c771557 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -8,7 +8,11 @@ "packages": { ".": { "package-name": "@googlemaps/react-native-navigation-sdk", - "changelog-path": "CHANGELOG.md" + "changelog-path": "CHANGELOG.md", + "extra-files": [ + "android/src/main/java/com/google/android/react/navsdk/SdkVersion.java", + "ios/react-native-navigation-sdk/SdkVersion.h" + ] } } }