49 {
50 if (instance == null)
51 {
52 synchronized (AppDatabase.class)
53 {
54 if (instance == null)
55 {
56 byte[] key = getOrCreateDbKey(context);
57 migrateUnencryptedIfNeeded(context, key);
58
59 instance = Room.databaseBuilder(context.getApplicationContext(),
60 AppDatabase.class, DB_NAME)
61 .openHelperFactory(new SupportOpenHelperFactory(key))
62 .addMigrations(MIGRATION_10_11)
63 .addMigrations(MIGRATION_11_12)
64 .addMigrations(MIGRATION_12_13)
65 .addMigrations(MIGRATION_13_14)
66 .addMigrations(MIGRATION_14_15)
67 .addMigrations(MIGRATION_15_16)
68 .build();
69 }
70 }
71 }
72 return instance;
73 }