parse-community / Parse-SDK-Android

The Android SDK for Parse Platform
https://parseplatform.org/
Other
1.88k stars 734 forks source link

ParseInstallation.installationId should be unique for app instances restored from backup #959

Open mman opened 5 years ago

mman commented 5 years ago

When the app using Parse Android SDK is saved to a backup and later restored from that backup on a new device, the ParseInstallation.installationId appears to remain the same, and now we have two devices with two app installations all fighting for the same _Installation entry in the mongo database. Since those two app instances are now running on two different devices, this at least breaks push targeting.

I'm trying to gather more details and figure out how to fix this and to understand how is the installationId generated but please give me a hand if someone knows how to address this.

Thanks, Martin

FridaySG commented 5 years ago

Hey @mman. I believe that when Parse starts it stores a UUID to the disk and then assigns that as the installationID, a major clue is here:

https://github.com/parse-community/Parse-SDK-Android/blob/0cfc67e9a3bcedc714f0041ee60cafb40ed93520/parse/src/main/java/com/parse/InstallationId.java#L37

I think, if the installationID has not been saved to the cloud, it pulls the above one from disk:

https://github.com/parse-community/Parse-SDK-Android/blob/0cfc67e9a3bcedc714f0041ee60cafb40ed93520/parse/src/main/java/com/parse/ParseInstallation.java#L275

So now, a potential solution would be to use a hardware identifier in addition to a randomly generated UUID. For example:

https://stackoverflow.com/a/2785493/5513305

Since the UUID is randomly generated, it changes on each install/uninstall. We would want to maintain that functionality. Perhaps we store the unique hardware identifier on each Installation object and check it against the FCM token? My brain is tired atm but if anybody can help sort out a nice algorithm that'd be great.