From 4a258ee15538aea21ff261c5b5feaa83c8e1d021 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 4 Dec 2018 01:11:03 +0100 Subject: [PATCH] remove dead code --- AndroidManifest.xml | 9 -- .../securesms/DatabaseUpgradeActivity.java | 145 ------------------ .../database/AttachmentDatabase.java | 32 ---- .../securesms/database/Database.java | 10 -- .../securesms/database/EarlyReceiptCache.java | 45 ------ .../securesms/database/MessagingDatabase.java | 12 -- .../securesms/database/ThreadDatabase.java | 32 ---- .../securesms/util/SingleLiveEvent.java | 72 --------- 8 files changed, 357 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java delete mode 100644 src/org/thoughtcrime/securesms/database/EarlyReceiptCache.java delete mode 100644 src/org/thoughtcrime/securesms/util/SingleLiveEvent.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e82e92891..bca7f0fbb 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -144,11 +144,6 @@ - - - - diff --git a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java deleted file mode 100644 index 159f0c440..000000000 --- a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Copyright (C) 2013 Open Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.thoughtcrime.securesms; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.AsyncTask; -import android.os.Bundle; -import android.util.Log; - -import org.thoughtcrime.securesms.notifications.MessageNotifier; -import org.thoughtcrime.securesms.util.Util; -import org.thoughtcrime.securesms.util.VersionTracker; - -import java.util.SortedSet; -import java.util.TreeSet; - -public class DatabaseUpgradeActivity extends BaseActivity { - - public static final int NO_MORE_KEY_EXCHANGE_PREFIX_VERSION = 46; - public static final int MMS_BODY_VERSION = 46; - public static final int TOFU_IDENTITIES_VERSION = 50; - public static final int CURVE25519_VERSION = 63; - public static final int ASYMMETRIC_MASTER_SECRET_FIX_VERSION = 73; - public static final int NO_V1_VERSION = 83; - public static final int SIGNED_PREKEY_VERSION = 83; - public static final int NO_DECRYPT_QUEUE_VERSION = 113; - public static final int PUSH_DECRYPT_SERIAL_ID_VERSION = 131; - public static final int MIGRATE_SESSION_PLAINTEXT = 136; - public static final int CONTACTS_ACCOUNT_VERSION = 136; - public static final int MEDIA_DOWNLOAD_CONTROLS_VERSION = 151; - public static final int REDPHONE_SUPPORT_VERSION = 157; - public static final int NO_MORE_CANONICAL_DB_VERSION = 276; - public static final int PROFILES = 289; - public static final int SCREENSHOTS = 300; - public static final int PERSISTENT_BLOBS = 317; - public static final int INTERNALIZE_CONTACTS = 317; - public static final int SQLCIPHER = 334; - public static final int SQLCIPHER_COMPLETE = 352; - public static final int REMOVE_JOURNAL = 353; - public static final int REMOVE_CACHE = 354; - public static final int FULL_TEXT_SEARCH = 358; - public static final int BAD_IMPORT_CLEANUP = 373; - - private static final SortedSet UPGRADE_VERSIONS = new TreeSet() {{ - add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION); - add(TOFU_IDENTITIES_VERSION); - add(CURVE25519_VERSION); - add(ASYMMETRIC_MASTER_SECRET_FIX_VERSION); - add(NO_V1_VERSION); - add(SIGNED_PREKEY_VERSION); - add(NO_DECRYPT_QUEUE_VERSION); - add(PUSH_DECRYPT_SERIAL_ID_VERSION); - add(MIGRATE_SESSION_PLAINTEXT); - add(MEDIA_DOWNLOAD_CONTROLS_VERSION); - add(REDPHONE_SUPPORT_VERSION); - add(NO_MORE_CANONICAL_DB_VERSION); - add(SCREENSHOTS); - add(INTERNALIZE_CONTACTS); - add(PERSISTENT_BLOBS); - add(SQLCIPHER); - add(SQLCIPHER_COMPLETE); - add(REMOVE_CACHE); - add(FULL_TEXT_SEARCH); - add(BAD_IMPORT_CLEANUP); - }}; - - @Override - public void onCreate(Bundle bundle) { - super.onCreate(bundle); - - if (needsUpgradeTask()) { - Log.w("DatabaseUpgradeActivity", "Upgrading..."); - setContentView(R.layout.database_upgrade_activity); - - } else { - VersionTracker.updateLastSeenVersion(this); - updateNotifications(this); - startActivity((Intent)getIntent().getParcelableExtra("next_intent")); - finish(); - } - } - - private boolean needsUpgradeTask() { - int currentVersionCode = Util.getCurrentApkReleaseVersion(this); - int lastSeenVersion = VersionTracker.getLastSeenVersion(this); - - Log.w("DatabaseUpgradeActivity", "LastSeenVersion: " + lastSeenVersion); - - if (lastSeenVersion >= currentVersionCode) - return false; - - for (int version : UPGRADE_VERSIONS) { - Log.w("DatabaseUpgradeActivity", "Comparing: " + version); - if (lastSeenVersion < version) - return true; - } - - return false; - } - - public static boolean isUpdate(Context context) { - try { - int currentVersionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; - int previousVersionCode = VersionTracker.getLastSeenVersion(context); - - return previousVersionCode < currentVersionCode; - } catch (PackageManager.NameNotFoundException e) { - throw new AssertionError(e); - } - } - - @SuppressLint("StaticFieldLeak") - private void updateNotifications(final Context context) { - new AsyncTask() { - @Override - protected Void doInBackground(Void... params) { - MessageNotifier.updateNotification(context); - return null; - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - public interface DatabaseUpgradeListener { - public void setProgress(int progress, int total); - } - -} diff --git a/src/org/thoughtcrime/securesms/database/AttachmentDatabase.java b/src/org/thoughtcrime/securesms/database/AttachmentDatabase.java index b7f071b43..0750d812e 100644 --- a/src/org/thoughtcrime/securesms/database/AttachmentDatabase.java +++ b/src/org/thoughtcrime/securesms/database/AttachmentDatabase.java @@ -185,38 +185,6 @@ public class AttachmentDatabase extends Database { } } - @SuppressWarnings("ResultOfMethodCallIgnored") - void deleteAttachmentsForMessage(long mmsId) { - SQLiteDatabase database = databaseHelper.getWritableDatabase(); - Cursor cursor = null; - - try { - cursor = database.query(TABLE_NAME, new String[] {DATA, THUMBNAIL}, MMS_ID + " = ?", - new String[] {mmsId+""}, null, null, null); - - while (cursor != null && cursor.moveToNext()) { - deleteAttachmentOnDisk(cursor.getString(0), cursor.getString(1)); - } - } finally { - if (cursor != null) - cursor.close(); - } - - database.delete(TABLE_NAME, MMS_ID + " = ?", new String[] {mmsId + ""}); - notifyAttachmentListeners(); - } - - @SuppressWarnings("ResultOfMethodCallIgnored") - private void deleteAttachmentOnDisk(@Nullable String data, @Nullable String thumbnail) { - if (!TextUtils.isEmpty(data)) { - new File(data).delete(); - } - - if (!TextUtils.isEmpty(thumbnail)) { - new File(thumbnail).delete(); - } - } - @SuppressWarnings("WeakerAccess") @VisibleForTesting protected @Nullable InputStream getDataStream(AttachmentId attachmentId, String dataType, long offset) diff --git a/src/org/thoughtcrime/securesms/database/Database.java b/src/org/thoughtcrime/securesms/database/Database.java index c2979c996..7aa40d6eb 100644 --- a/src/org/thoughtcrime/securesms/database/Database.java +++ b/src/org/thoughtcrime/securesms/database/Database.java @@ -57,16 +57,6 @@ public abstract class Database { cursor.setNotificationUri(context.getContentResolver(), Uri.parse(CONVERSATION_LIST_URI)); } - protected void registerAttachmentListeners(@NonNull ContentObserver observer) { - context.getContentResolver().registerContentObserver(Uri.parse(ATTACHMENT_URI), - true, - observer); - } - - protected void notifyAttachmentListeners() { - context.getContentResolver().notifyChange(Uri.parse(ATTACHMENT_URI), null); - } - public void reset(SQLCipherOpenHelper databaseHelper) { this.databaseHelper = databaseHelper; } diff --git a/src/org/thoughtcrime/securesms/database/EarlyReceiptCache.java b/src/org/thoughtcrime/securesms/database/EarlyReceiptCache.java deleted file mode 100644 index 94d7b7963..000000000 --- a/src/org/thoughtcrime/securesms/database/EarlyReceiptCache.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.thoughtcrime.securesms.database; - -import android.util.Log; - -import org.thoughtcrime.securesms.util.LRUCache; - -import java.util.HashMap; -import java.util.Map; - -public class EarlyReceiptCache { - - private static final String TAG = EarlyReceiptCache.class.getSimpleName(); - - private final LRUCache> cache = new LRUCache<>(100); - - public synchronized void increment(long timestamp, Address origin) { - Log.w(TAG, this+""); - Log.w(TAG, String.format("Early receipt: (%d, %s)", timestamp, origin.serialize())); - - Map receipts = cache.get(timestamp); - - if (receipts == null) { - receipts = new HashMap<>(); - } - - Long count = receipts.get(origin); - - if (count != null) { - receipts.put(origin, ++count); - } else { - receipts.put(origin, 1L); - } - - cache.put(timestamp, receipts); - } - - public synchronized Map remove(long timestamp) { - Map receipts = cache.remove(timestamp); - - Log.w(TAG, this+""); - Log.w(TAG, String.format("Checking early receipts (%d): %d", timestamp, receipts == null ? 0 : receipts.size())); - - return receipts != null ? receipts : new HashMap<>(); - } -} diff --git a/src/org/thoughtcrime/securesms/database/MessagingDatabase.java b/src/org/thoughtcrime/securesms/database/MessagingDatabase.java index 52ef89535..41e523411 100644 --- a/src/org/thoughtcrime/securesms/database/MessagingDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MessagingDatabase.java @@ -12,16 +12,4 @@ public abstract class MessagingDatabase extends Database implements MmsSmsColumn super(context, databaseHelper); } - public static class SyncMessageId { - - private final Address address; - - public SyncMessageId(Address address, long timetamp) { - this.address = address; - } - - public Address getAddress() { - return address; - } - } } diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index e731bfb3e..d92a8e6a9 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -20,7 +20,6 @@ package org.thoughtcrime.securesms.database; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; -import android.database.MergeCursor; import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -39,12 +38,10 @@ import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.recipients.Recipient; -import org.thoughtcrime.securesms.util.DelimiterUtil; import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.guava.Optional; import java.io.Closeable; -import java.util.LinkedList; import java.util.List; public class ThreadDatabase extends Database { @@ -152,35 +149,6 @@ public class ThreadDatabase extends Database { notifyConversationListListeners(); } - public Cursor getFilteredConversationList(@Nullable List
filter) { - if (filter == null || filter.size() == 0) - return null; - - SQLiteDatabase db = databaseHelper.getReadableDatabase(); - List> partitionedAddresses = Util.partition(filter, 900); - List cursors = new LinkedList<>(); - - for (List
addresses : partitionedAddresses) { - String selection = TABLE_NAME + "." + ADDRESS + " = ?"; - String[] selectionArgs = new String[addresses.size()]; - - for (int i=0;i 1 ? new MergeCursor(cursors.toArray(new Cursor[cursors.size()])) : cursors.get(0); - setNotifyConverationListListeners(cursor); - return cursor; - } - public Cursor getDirectShareList() { SQLiteDatabase db = databaseHelper.getReadableDatabase(); String query = createQuery(MESSAGE_COUNT + " != 0", 0); diff --git a/src/org/thoughtcrime/securesms/util/SingleLiveEvent.java b/src/org/thoughtcrime/securesms/util/SingleLiveEvent.java deleted file mode 100644 index 2a58736b0..000000000 --- a/src/org/thoughtcrime/securesms/util/SingleLiveEvent.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.thoughtcrime.securesms.util; - -import android.arch.lifecycle.LifecycleOwner; -import android.arch.lifecycle.MutableLiveData; -import android.arch.lifecycle.Observer; -import android.support.annotation.MainThread; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.util.Log; - -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * A lifecycle-aware observable that sends only new updates after subscription, used for events like - * navigation and Snackbar messages. - *

- * This avoids a common problem with events: on configuration change (like rotation) an update - * can be emitted if the observer is active. This LiveData only calls the observable if there's an - * explicit call to setValue() or call(). - *

- * Note that only one observer is going to be notified of changes. - */ -public class SingleLiveEvent extends MutableLiveData { - - private static final String TAG = SingleLiveEvent.class.getSimpleName(); - - private final AtomicBoolean mPending = new AtomicBoolean(false); - - @MainThread - public void observe(@NonNull LifecycleOwner owner, @NonNull final Observer observer) { - if (hasActiveObservers()) { - Log.w(TAG, "Multiple observers registered but only one will be notified of changes."); - } - - // Observe the internal MutableLiveData - super.observe(owner, t -> { - if (mPending.compareAndSet(true, false)) { - observer.onChanged(t); - } - }); - } - - @MainThread - public void setValue(@Nullable T t) { - mPending.set(true); - super.setValue(t); - } - - /** - * Used for cases where T is Void, to make calls cleaner. - */ - @MainThread - public void call() { - setValue(null); - } -}