Skip to content

Commit fc67365

Browse files
authored
feat(analytics): Legacy data migration of Pinpoint Endpoint ID (#2489)
Co-authored-by: dnys1, Jordan-Nelson Automatically migrate legacy pinpoint endpoint id from Amplify Android and iOS native storage.
1 parent 5713ceb commit fc67365

34 files changed

+651
-99
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled.
5+
6+
version:
7+
revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
8+
channel: stable
9+
10+
project_type: plugin
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
17+
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
18+
- platform: android
19+
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
20+
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
21+
- platform: ios
22+
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
23+
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
24+
- platform: linux
25+
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
26+
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
27+
- platform: macos
28+
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
29+
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
30+
- platform: web
31+
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
32+
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
33+
- platform: windows
34+
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
35+
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.PHONY: pigeons
2+
pigeons:
3+
flutter pub run pigeon --input pigeons/pigeon_config_android.dart
4+
flutter format --fix lib/src/legacy_native_data_provider/pigeon_legacy_data_provider.android.g.dart
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include: package:amplify_lints/library.yaml
22

3-
analyzer:
3+
analyzer:
44
errors:
5-
implementation_imports: error #TODO(equartey): Remove when lint is enforced project-wide
5+
implementation_imports: error #TODO(equartey): Remove when lint is enforced project-wide
6+
exclude:
7+
- "**/*.g.dart"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
group 'com.amazonaws.amplify.amplify_analytics_pinpoint.amplify_analytics_pinpoint'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
ext.kotlin_version = '1.6.10'
6+
repositories {
7+
google()
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
classpath 'com.android.tools.build:gradle:7.1.3'
13+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14+
}
15+
}
16+
17+
rootProject.allprojects {
18+
repositories {
19+
google()
20+
mavenCentral()
21+
}
22+
}
23+
24+
apply plugin: 'com.android.library'
25+
apply plugin: 'kotlin-android'
26+
27+
android {
28+
compileSdkVersion 33
29+
30+
compileOptions {
31+
sourceCompatibility JavaVersion.VERSION_1_8
32+
targetCompatibility JavaVersion.VERSION_1_8
33+
}
34+
35+
kotlinOptions {
36+
jvmTarget = '1.8'
37+
}
38+
39+
sourceSets {
40+
main.java.srcDirs += 'src/main/kotlin'
41+
}
42+
43+
defaultConfig {
44+
minSdkVersion 23
45+
}
46+
}
47+
48+
dependencies {
49+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
50+
}
51+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'amplify_analytics_pinpoint'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.amazonaws.amplify.amplify_analytics_pinpoint.amplify_analytics_pinpoint">
3+
</manifest>

packages/analytics/amplify_analytics_pinpoint/android/src/main/java/com/amazonaws/amplify/amplify_analytics_pinpoint/amplify_analytics_pinpoint/Messages.java

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package com.amazonaws.amplify.amplify_analytics_pinpoint.amplify_analytics_pinpoint
5+
6+
import android.content.Context
7+
import android.content.SharedPreferences
8+
import androidx.annotation.NonNull
9+
import io.flutter.embedding.engine.plugins.FlutterPlugin
10+
11+
class AmplifyAnalyticsPinpointPlugin: FlutterPlugin, Messages.PigeonLegacyDataProvider {
12+
13+
private var context: Context? = null
14+
private var sharedPrefs: SharedPreferences? = null
15+
16+
companion object {
17+
private const val PINPOINT_SHARED_PREFS_SUFFIX = "515d6767-01b7-49e5-8273-c8d11b0f331d"
18+
private const val UNIQUE_ID_KEY = "UniqueId";
19+
}
20+
21+
override fun onAttachedToEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
22+
context = binding.applicationContext
23+
Messages.PigeonLegacyDataProvider.setup(binding.binaryMessenger, this)
24+
}
25+
26+
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
27+
Messages.PigeonLegacyDataProvider.setup(binding.binaryMessenger, null)
28+
context = null
29+
}
30+
31+
override fun getEndpointId(pinpointAppId: String, result: Messages.Result<String?>){
32+
if (context == null) {
33+
result.error(Exception("Application context is null"))
34+
return
35+
}
36+
sharedPrefs = sharedPrefs ?: context!!.getSharedPreferences(
37+
"${pinpointAppId}$PINPOINT_SHARED_PREFS_SUFFIX",
38+
Context.MODE_PRIVATE
39+
)
40+
result.success(sharedPrefs!!.getString(UNIQUE_ID_KEY, null))
41+
}
42+
43+
}

packages/analytics/amplify_analytics_pinpoint/example/integration_test/auto_session_tracking_test.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License").
4-
// You may not use this file except in compliance with the License.
5-
// A copy of the License is located at
6-
//
7-
// http://aws.amazon.com/apache2.0
8-
//
9-
// or in the "license" file accompanying this file. This file is distributed
10-
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
// express or implied. See the License for the specific language governing
12-
// permissions and limitations under the License.
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
import 'dart:async';
155

0 commit comments

Comments
 (0)