Skip to content

Commit

Permalink
feat(analytics): Legacy data migration of Pinpoint Endpoint ID (#2489)
Browse files Browse the repository at this point in the history
Co-authored-by: dnys1, Jordan-Nelson

Automatically migrate legacy pinpoint endpoint id from Amplify Android and iOS native storage.
  • Loading branch information
fjnoyp committed Jan 11, 2023
1 parent 5713ceb commit fc67365
Show file tree
Hide file tree
Showing 34 changed files with 651 additions and 99 deletions.
45 changes: 45 additions & 0 deletions packages/analytics/amplify_analytics_pinpoint/.metadata
@@ -0,0 +1,45 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.

version:
revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
channel: stable

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
- platform: android
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
- platform: ios
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
- platform: linux
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
- platform: macos
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
- platform: web
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
- platform: windows
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
4 changes: 4 additions & 0 deletions packages/analytics/amplify_analytics_pinpoint/Makefile
@@ -0,0 +1,4 @@
.PHONY: pigeons
pigeons:
flutter pub run pigeon --input pigeons/pigeon_config_android.dart
flutter format --fix lib/src/legacy_native_data_provider/pigeon_legacy_data_provider.android.g.dart
@@ -1,5 +1,7 @@
include: package:amplify_lints/library.yaml

analyzer:
analyzer:
errors:
implementation_imports: error #TODO(equartey): Remove when lint is enforced project-wide
implementation_imports: error #TODO(equartey): Remove when lint is enforced project-wide
exclude:
- "**/*.g.dart"
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
51 changes: 51 additions & 0 deletions packages/analytics/amplify_analytics_pinpoint/android/build.gradle
@@ -0,0 +1,51 @@
group 'com.amazonaws.amplify.amplify_analytics_pinpoint.amplify_analytics_pinpoint'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
minSdkVersion 23
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

@@ -0,0 +1 @@
rootProject.name = 'amplify_analytics_pinpoint'
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazonaws.amplify.amplify_analytics_pinpoint.amplify_analytics_pinpoint">
</manifest>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,43 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.amazonaws.amplify.amplify_analytics_pinpoint.amplify_analytics_pinpoint

import android.content.Context
import android.content.SharedPreferences
import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin

class AmplifyAnalyticsPinpointPlugin: FlutterPlugin, Messages.PigeonLegacyDataProvider {

private var context: Context? = null
private var sharedPrefs: SharedPreferences? = null

companion object {
private const val PINPOINT_SHARED_PREFS_SUFFIX = "515d6767-01b7-49e5-8273-c8d11b0f331d"
private const val UNIQUE_ID_KEY = "UniqueId";
}

override fun onAttachedToEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
context = binding.applicationContext
Messages.PigeonLegacyDataProvider.setup(binding.binaryMessenger, this)
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
Messages.PigeonLegacyDataProvider.setup(binding.binaryMessenger, null)
context = null
}

override fun getEndpointId(pinpointAppId: String, result: Messages.Result<String?>){
if (context == null) {
result.error(Exception("Application context is null"))
return
}
sharedPrefs = sharedPrefs ?: context!!.getSharedPreferences(
"${pinpointAppId}$PINPOINT_SHARED_PREFS_SUFFIX",
Context.MODE_PRIVATE
)
result.success(sharedPrefs!!.getString(UNIQUE_ID_KEY, null))
}

}
@@ -1,15 +1,5 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file 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.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';

Expand Down
@@ -1,15 +1,5 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file 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.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';

Expand Down
@@ -1,15 +1,5 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file 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.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';

Expand Down
@@ -1,16 +1,5 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// 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.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';

Expand Down
@@ -1,15 +1,5 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file 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.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';

Expand Down
@@ -1,16 +1,5 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// 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.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_analytics_pinpoint_dart/src/sdk/pinpoint.dart'
show EndpointResponse;
Expand Down
Expand Up @@ -6,10 +6,7 @@ library amplify_analytics_pinpoint;

/// Overridable Flutter injected dependencies
export 'package:amplify_analytics_pinpoint_dart/amplify_analytics_pinpoint_dart.dart'
show
AppLifecycleProvider,
CachedEventsPathProvider,
DeviceContextInfoProvider;
show AppLifecycleProvider;

/// Category Implementation
export 'src/analytics_plugin_impl.dart';

0 comments on commit fc67365

Please sign in to comment.