don't load signed prekeys on startup
This commit is contained in:
		
							parent
							
								
									f47cf7ae67
								
							
						
					
					
						commit
						cc1402442a
					
				| @ -602,7 +602,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { | ||||
| 
 | ||||
| 					// Validate signedPreKeyRecord + ID | ||||
| 					SignedPreKeyRecord signedPreKeyRecord; | ||||
| 					int numSignedPreKeys = axolotlStore.loadSignedPreKeys().size(); | ||||
| 					int numSignedPreKeys = axolotlStore.getSignedPreKeysCount(); | ||||
| 					try { | ||||
| 						signedPreKeyRecord = axolotlStore.loadSignedPreKey(bundle.getSignedPreKeyId()); | ||||
| 						if (flush | ||||
|  | ||||
| @ -79,9 +79,6 @@ public class SQLiteAxolotlStore implements AxolotlStore { | ||||
| 		this.mXmppConnectionService = service; | ||||
| 		this.localRegistrationId = loadRegistrationId(); | ||||
| 		this.currentPreKeyId = loadCurrentPreKeyId(); | ||||
| 		for (SignedPreKeyRecord record : loadSignedPreKeys()) { | ||||
| 			Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Got Axolotl signed prekey record:" + record.getId()); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public int getCurrentPreKeyId() { | ||||
| @ -415,6 +412,10 @@ public class SQLiteAxolotlStore implements AxolotlStore { | ||||
| 		return mXmppConnectionService.databaseBackend.loadSignedPreKeys(account); | ||||
| 	} | ||||
| 
 | ||||
| 	public int getSignedPreKeysCount() { | ||||
| 		return mXmppConnectionService.databaseBackend.getSignedPreKeysCount(account); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Store a local SignedPreKeyRecord. | ||||
| 	 * | ||||
|  | ||||
| @ -1086,6 +1086,25 @@ public class DatabaseBackend extends SQLiteOpenHelper { | ||||
| 		return prekeys; | ||||
| 	} | ||||
| 
 | ||||
| 	public int getSignedPreKeysCount(Account account) { | ||||
| 		String[] columns = {"count("+SQLiteAxolotlStore.KEY+")"}; | ||||
| 		String[] selectionArgs = {account.getUuid()}; | ||||
| 		SQLiteDatabase db = this.getReadableDatabase(); | ||||
| 		Cursor cursor = db.query(SQLiteAxolotlStore.SIGNED_PREKEY_TABLENAME, | ||||
| 				columns, | ||||
| 				SQLiteAxolotlStore.ACCOUNT + "=?", | ||||
| 				selectionArgs, | ||||
| 				null, null, null); | ||||
| 		final int count; | ||||
| 		if (cursor.moveToFirst()) { | ||||
| 			count = cursor.getInt(0); | ||||
| 		} else { | ||||
| 			count = 0; | ||||
| 		} | ||||
| 		cursor.close(); | ||||
| 		return count; | ||||
| 	} | ||||
| 
 | ||||
| 	public boolean containsSignedPreKey(Account account, int signedPreKeyId) { | ||||
| 		Cursor cursor = getCursorForPreKey(account, signedPreKeyId); | ||||
| 		int count = cursor.getCount(); | ||||
|  | ||||
| @ -991,7 +991,9 @@ public class XmppConnectionService extends Service { | ||||
| 			} | ||||
| 		}; | ||||
| 
 | ||||
| 		Log.d(Config.LOGTAG,"initializing database..."); | ||||
| 		this.databaseBackend = DatabaseBackend.getInstance(getApplicationContext()); | ||||
| 		Log.d(Config.LOGTAG,"restoring accounts..."); | ||||
| 		this.accounts = databaseBackend.getAccounts(); | ||||
| 
 | ||||
| 		if (Config.FREQUENT_RESTARTS_THRESHOLD != 0 | ||||
| @ -1449,6 +1451,8 @@ public class XmppConnectionService extends Service { | ||||
| 			for (Account account : this.accounts) { | ||||
| 				accountLookupTable.put(account.getUuid(), account); | ||||
| 			} | ||||
| 			Log.d(Config.LOGTAG,"restoring conversations..."); | ||||
| 			final long startTimeConversationsRestore = SystemClock.elapsedRealtime(); | ||||
| 			this.conversations.addAll(databaseBackend.getConversations(Conversation.STATUS_AVAILABLE)); | ||||
| 			for(Iterator<Conversation> iterator = conversations.listIterator(); iterator.hasNext();) { | ||||
| 				Conversation conversation = iterator.next(); | ||||
| @ -1460,6 +1464,8 @@ public class XmppConnectionService extends Service { | ||||
| 					iterator.remove(); | ||||
| 				} | ||||
| 			} | ||||
| 			long diffConversationsRestore = SystemClock.elapsedRealtime() - startTimeConversationsRestore; | ||||
| 			Log.d(Config.LOGTAG,"finished restoring conversations in "+diffConversationsRestore+"ms"); | ||||
| 			Runnable runnable = new Runnable() { | ||||
| 				@Override | ||||
| 				public void run() { | ||||
| @ -1469,14 +1475,15 @@ public class XmppConnectionService extends Service { | ||||
| 						Log.d(Config.LOGTAG, "deleting messages that are older than "+AbstractGenerator.getTimestamp(deletionDate)); | ||||
| 						databaseBackend.expireOldMessages(deletionDate); | ||||
| 					} | ||||
| 					Log.d(Config.LOGTAG, "restoring roster"); | ||||
| 					Log.d(Config.LOGTAG,"restoring roster..."); | ||||
| 					for (Account account : accounts) { | ||||
| 						databaseBackend.readRoster(account.getRoster()); | ||||
| 						account.initAccountServices(XmppConnectionService.this); //roster needs to be loaded at this stage | ||||
| 					} | ||||
| 					getBitmapCache().evictAll(); | ||||
| 					loadPhoneContacts(); | ||||
| 					Log.d(Config.LOGTAG, "restoring messages"); | ||||
| 					Log.d(Config.LOGTAG, "restoring messages..."); | ||||
| 					final long startMessageRestore = SystemClock.elapsedRealtime(); | ||||
| 					for (Conversation conversation : conversations) { | ||||
| 						conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE)); | ||||
| 						checkDeletedFiles(conversation); | ||||
| @ -1496,7 +1503,8 @@ public class XmppConnectionService extends Service { | ||||
| 					} | ||||
| 					mNotificationService.finishBacklog(false); | ||||
| 					mRestoredFromDatabase = true; | ||||
| 					Log.d(Config.LOGTAG, "restored all messages"); | ||||
| 					final long diffMessageRestore = SystemClock.elapsedRealtime() - startMessageRestore; | ||||
| 					Log.d(Config.LOGTAG, "finished restoring messages in "+diffMessageRestore+"ms"); | ||||
| 					updateConversationUi(); | ||||
| 				} | ||||
| 			}; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Daniel Gultsch
						Daniel Gultsch