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