[Mateusz Herych] How can Android Backup break your app

[Mateusz Herych] How can Android Backup break your app

Presentation from GDG DevFest Ukraine 2015 - the biggest Google related event in the country. October 23-24, Lviv. Learn more at http://devfest.gdg.org.ua/

3a6de6bc902de7f75c0e753b3202ed52?s=128

Google Developers Group Lviv

October 24, 2015
Tweet

Transcript

  1. Auto Backup

  2. Auto Backup Quick story on how it can break your

    app
  3. +MateuszHerych GDG Kraków Android GDE Engineer @ Base

  4. Basic facts

  5. Automatic backups are enabled for all apps installed on devices

    running Marshmallow. No additional app code is required.
  6. Automatic backups are enabled for all apps by default.

  7. What does it mean?

  8. Android now backups Databases

  9. Android now backups Databases SharedPreferences

  10. Android now backups Databases SharedPreferences Basically everything in your /data

    (-cache -nobackupfiles)
  11. Android won’t backup Context.getCacheDir

  12. Android won’t backup Context.getCacheDir Context.getNoBackupFilesDir

  13. Once in 24h

  14. WIFI, overnight/idle, charging

  15. Backup is restored during the installation

  16. targetSdkVersion 23

  17. EASY!

  18. Q & A

  19. None
  20. None
  21. Titanium Backup

  22. Backup is not a new concept on Android.

  23. And you can face exact same problems.

  24. None
  25. None
  26. Or just follow good practices and use common sense.

  27. Practice #1

  28. Practice #1 Don’t backup data that’s synchronized with your backend

    anyway.
  29. Tables.CONTACTS first_name TEXT, last_name TEXT, modified INTEGER NOT NULL DEFAULT

    0
  30. Tables.CONTACTS INSERT INTO contacts VALUES (‘Jan’, ‘Kowalski’, 1)

  31. Tables.CONTACTS INSERT INTO contacts VALUES (‘Jan’, ‘Kowalski’, 1) … and

    then Android decides to backup your data.
  32. ????

  33. Every device that receives a backup will post an update

    to the server.
  34. = Duplicates

  35. None
  36. If your database is a “syncable database”

  37. Consider removing it from the backup list.

  38. AndroidManifest.xml <application android:fullBackupContent=” @xml/scheme” … />

  39. res/xml/scheme.xml <?xml version="1.0" encoding="utf-8"?> <full-backup-content> <exclude domain="database" path="my. db"/> </full-backup-content>

  40. res/xml/scheme.xml <?xml version="1.0" encoding="utf-8"?> <full-backup-content> <include domain="database" path="my. db"/> </full-backup-content>

  41. res/xml/scheme.xml <?xml version="1.0" encoding="utf-8"?> <full-backup-content> <exclude domain="database" path="my. db"/> </full-backup-content>

  42. Domain database, sharedpref, file, external, root

  43. DON’T HARDCODE ABSOLUTE PATHS!

  44. Practice #2

  45. Practice #2 Take care of data migrations.

  46. Data migrations mean

  47. Data migrations mean Database schema migrations

  48. Data migrations mean Database schema migrations SharedPreferences

  49. Data migrations mean Database schema migrations SharedPreferences Any serialized data

    (binary, json, etc)
  50. Beware, you may receive data from the older version.*

  51. Practice #3

  52. Practice #3 GCM anyone?

  53. Keep your GCM registration_id out of your backup.

  54. It may break GCM on that device.

  55. It may break GCM on another device, too.

  56. Same for other, per- device unique tokens/keys.

  57. Same for other, per- device unique tokens/keys. PS: Check if

    InstanceId fits your needs
  58. How?

  59. How? Separate SharedPreferences

  60. How? Separate SharedPreferences Separate database

  61. Practice #4

  62. Practice #4 Consider legal issues.

  63. Practice #4 Quick story on how it can break your

    app
  64. Practice #4 Quick story on how it can put you

    in jail
  65. Practice #4 Quick story on how it can put you

    in jail
  66. Technically speaking...

  67. Android Backup sends your users’ data to Google

  68. Android Backup sends your users’ data to another company

  69. Ask yourself - do you backup user’s confidential data?

  70. Then if (and only if) you REALLY think it’s necessary

  71. Encrypt it.

  72. Backup is cool

  73. Recovery is cool

  74. Use it wisely.

  75. Leaving its settings as defaults isn’t wise.*

  76. *For most apps.

  77. Ah, one more thing.

  78. 25 MB

  79. After which your backup doesn’t work anymore.

  80. So decide what exactly to backup and have a strategy

  81. NO STRATEGY =

  82. NO STRATEGY = OPTING OUT

  83. Even worse

  84. It makes your user think there’s some backup

  85. But suddenly there is not

  86. Thanks!

  87. Q & A

  88. Q & A Really. https://developer.android.com/preview/backup/index.html https://commonsware.com/blog/2015/06/04/random- musings-m-developer-preview-bad-part-two.html