Skip to content

Shared Hardware Id

Mihály Hunyady edited this page Apr 13, 2021 · 7 revisions

Shared Hardware Id

Note

The development of this feature is in progress, please do not use it in production releases!

Shared Hardware Id is enabled from SDK version 2.12

What is shared hardware id?

From 2.12.0 Emarsys SDK provides a solution to share the hardware identifier between your applications, that has Emarsys SDK integrated.

How does it work?

The SDK uses a ContentProvider to share encrypted hardware id between the applications in a secure way. For this to work a shared secret is needed in every application what needs this shared hardware id.

  • If no secret is added to the Emarsys Config:
    • and there is a stored hardware id already, the SDK works as before and uses the stored hardware id and doesn't provide it to other applications
    • but there is no hardware id stored, the SDK generates a new one and stores it
  • If there is a secret added to the Emarsys Config:
    • and there is a stored hardware id, the SDK uses that and makes it available through a ContentProvider and provides it in an encrypted form, to authorised applications
    • the SDK asks for a hardware id from the other applications configured in sharedPackageNames, and uses the one it found, or
    • if no hardware id found, the SDK generates one and makes it available through a ContentProvider and provides it in an encrypted form, to authorised applications

With the behaviour above the SDK works fine and compatible with every previous versions. The existing hardware id of an app will not be changed, if the secret is added later.

Required steps at integration

The following modifications must be done in all of your applications.

1. Set your other application' packages in the Config

Call EmarsysConfig.Builder.sharedPackageNames(sharedPackageNames: List) before the setup, where the sharedPackageNames is the list of the package names of your other applications.

2. Set your applications' secrets in the Config

Set your secret in the Config of your applications with the EmarsysConfig.Builder.sharedSecret(sharedSecret: String) method. This secret can be any String, and it's mandatory to be the same in all your applications.

3. Add provider and queries tag in your AndroidManifest.xml

In your manifest file add the provider tag inside your application tag, and the queries tag inside the manifest tag. The content of these are listed below.

provider
<provider
android:name="com.emarsys.provider.SharedHardwareIdentificationContentProvider"
android:authorities="${applicationId}"
android:enabled="true"
android:exported="true"
android:grantUriPermissions="true" />

In the <package android:name="APPLICATION_PACKAGE"> the APPLICATION_PACKAGE is your other application's package name.

queries
<queries>
    <package android:name="APPLICATION_PACKAGE" />
</queries>
Java
public class SampleApplication extends Application {

@Override
public void onCreate() {
super.onCreate();
    EmarsysConfig config = new EmarsysConfig.Builder()
    .application(this)
    .mobileEngageApplicationCode(<applicationCode:String?>)
    .contactFieldId(<contactFieldId: Integer>)
    .predictMerchantId(<predictMerchantId:String?>)
    .inAppEventHandler(getInAppEventHandler())
    .notificationEventHandler(getNotificationEventHandler())
    .sharedPackageNames(<sharedPackageNames: List<String>>)
    .sharedSecret(<sharedSecret: String>)
    .build();

    Emarsys.setup(config);
    }
}
Kotlin
class SampleApplication: Application() {

    override fun onCreate() {
    super.onCreate()
    val config = EmarsysConfig.Builder()
    .application(this)
    .mobileEngageApplicationCode(<applicationCode: String?>)
    .contactFieldId(<contactFieldId: Integer>)
    .predictMerchantId(<predictMerchantId:String?>)
    .inAppEventHandler(getInAppEventHandler())
    .notificationEventHandler(getNotificationEventHandler())
    .sharedPackageNames(<sharedPackageNames: List<String>>)
    .sharedSecret(<sharedSecret: String>)
    .build()

    Emarsys.setup(config)
    }
}