Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 23+ - Exclude GCM Registration ID from backup

Tags:

I have an app which uses Azure to send Push notifications. Azure in turn, uses GCM to send to Android devices.

I'm noticing that I have a warning in my AndroidManifest.xml stating

On SDK version 23 and up, your app data will be automatically backed up, and restored on app install. Your GCM regid will not work across restores, so you must ensure that it is excluded from the back-up set. Use the attribute android:fullBackupContent to specify an @xml resource which configures which files to backup.

I have following the instructions here https://developer.android.com/training/backup/autosyncapi.html?hl=in#configuring

however I am stumped as to how to exclude the GCM regID from the backup? Here is my current setup.

Manifest

<application         android:allowBackup="true"         android:fullBackupContent="@xml/backup_scheme"         ........ 

res/xml/backup_scheme.xml

<?xml version="1.0" encoding="utf-8"?> <full-backup-content>     <exclude domain="sharedpref" path=""/> </full-backup-content> 

What do I put as path? Am I supposed to have a physical file somewhere I exclude?

UPDATE

So I think I figured it out. In my RegistrationIntentService.java file, I store the users registrationID in the shared preferences under the string "registrationID". So I'm assuming I use the following...

<exclude domain="sharedpref" path="registrationID"/> 

right?

like image 569
Phil Avatar asked Aug 22 '16 20:08

Phil


2 Answers

After further study from @Simon answer, I think we would still need to replace the file name specified in the Path when the backup descriptor xml file is auto-generated from the quickfix in Android Studio. I check the shared_prefs directory in one of my app which has implemented the Firebase Cloud Messaging and found the following GCM settings preferences files:

enter image description here

So the backup_descriptor.xml would be:

<?xml version="1.0" encoding="utf-8"?> <full-backup-content>     <!-- Exclude the shared preferences file that contains the GCM registrationId -->     <exclude         domain="sharedpref"         path="com.google.android.gms.appid.xml"/>     <exclude         domain="sharedpref"         path="com.google.android.gms.measurement.prefs.xml"/> </full-backup-content> 
like image 165
CodePlay Avatar answered Oct 13 '22 01:10

CodePlay


I faced same issue and I was going to follow accepting answer, but turns out it seems it is not what should be done.

What I did is that I set the fullBackupContentProperty in my manifest before creating the backup_scheme.xml file. So of course, Android Studio complained with a warning but provided me a quickfix to automatically generate that file.

Applying the quickfix generated the following file:

<?xml version="1.0" encoding="utf-8"?> <full-backup-content>     <!-- Remove the following "exclude" elements to make them a part of the auto backup -->     <exclude         domain="database"         path="attendee.db" />     <exclude         domain="database"         path="whova_messages.db" />     <exclude         domain="database"         path="photo.db" />     <exclude         domain="database"         path="agenda.db" />     <exclude         domain="database"         path="ebb.db" />     <exclude         domain="database"         path="vertical.db" />     <exclude         domain="database"         path="whova.db" />     <!-- Exclude the shared preferences file that contains the GCM registrationId -->     <exclude         domain="sharedpref"         path="WhovaMessagePrefFile.xml" />     <exclude         domain="sharedpref"         path="APP_RATER.xml" />     <exclude         domain="sharedpref"         path="WhovaPrefFile.xml" /> </full-backup-content> 

Note the <!-- Exclude the shared preferences file that contains the GCM registrationId -->

So my guess is that you have to exclude the entire Shared Preference file containing the GCM ID, and not just the key.

Too bad the documentation does not make it super clear and also too bad we have to exclude and entire file from the backup.

like image 20
Simon Ninon Avatar answered Oct 12 '22 23:10

Simon Ninon