2013-11-10 04:15:29 -08:00
|
|
|
/**
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
2014-11-21 12:53:40 -08:00
|
|
|
import android.database.Cursor;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
2013-11-10 04:15:29 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2015-07-06 17:36:49 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore;
|
|
|
|
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
|
2017-03-28 12:05:30 -07:00
|
|
|
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2015-08-24 15:24:31 -07:00
|
|
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.MmsDatabase.Reader;
|
2014-11-21 12:53:40 -08:00
|
|
|
import org.thoughtcrime.securesms.database.PushDatabase;
|
2015-08-24 15:24:31 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
2014-10-21 10:39:25 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
2015-07-14 14:35:28 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob;
|
2014-11-21 12:53:40 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushDecryptJob;
|
2015-09-30 16:19:50 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
2014-02-25 20:57:18 -08:00
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
2014-07-23 15:40:45 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2013-05-07 16:31:11 -07:00
|
|
|
import org.thoughtcrime.securesms.util.VersionTracker;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2014-04-22 14:33:29 -07:00
|
|
|
import java.io.File;
|
2015-08-24 15:24:31 -07:00
|
|
|
import java.util.List;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import java.util.SortedSet;
|
|
|
|
import java.util.TreeSet;
|
|
|
|
|
2015-02-08 13:53:12 -08:00
|
|
|
public class DatabaseUpgradeActivity extends BaseActivity {
|
2015-08-24 15:24:31 -07:00
|
|
|
private static final String TAG = DatabaseUpgradeActivity.class.getSimpleName();
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2014-07-18 20:29:00 -07:00
|
|
|
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;
|
2014-04-22 14:33:29 -07:00
|
|
|
public static final int NO_V1_VERSION = 83;
|
2014-10-21 10:39:25 -07:00
|
|
|
public static final int SIGNED_PREKEY_VERSION = 83;
|
2015-04-21 13:04:00 -07:00
|
|
|
public static final int NO_DECRYPT_QUEUE_VERSION = 113;
|
2015-06-25 11:17:42 -07:00
|
|
|
public static final int PUSH_DECRYPT_SERIAL_ID_VERSION = 131;
|
2015-07-16 11:17:04 -07:00
|
|
|
public static final int MIGRATE_SESSION_PLAINTEXT = 136;
|
|
|
|
public static final int CONTACTS_ACCOUNT_VERSION = 136;
|
2015-09-10 16:48:10 -10:00
|
|
|
public static final int MEDIA_DOWNLOAD_CONTROLS_VERSION = 151;
|
2015-09-30 16:19:50 -07:00
|
|
|
public static final int REDPHONE_SUPPORT_VERSION = 157;
|
2017-07-26 09:59:15 -07:00
|
|
|
public static final int NO_MORE_CANONICAL_DB_VERSION = 276;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
|
|
|
private static final SortedSet<Integer> UPGRADE_VERSIONS = new TreeSet<Integer>() {{
|
|
|
|
add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION);
|
2013-05-23 16:36:24 -07:00
|
|
|
add(TOFU_IDENTITIES_VERSION);
|
2013-11-10 04:15:29 -08:00
|
|
|
add(CURVE25519_VERSION);
|
2014-07-18 20:29:00 -07:00
|
|
|
add(ASYMMETRIC_MASTER_SECRET_FIX_VERSION);
|
2014-10-21 10:39:25 -07:00
|
|
|
add(NO_V1_VERSION);
|
|
|
|
add(SIGNED_PREKEY_VERSION);
|
2014-11-03 15:16:04 -08:00
|
|
|
add(NO_DECRYPT_QUEUE_VERSION);
|
2015-06-25 11:17:42 -07:00
|
|
|
add(PUSH_DECRYPT_SERIAL_ID_VERSION);
|
2015-07-06 17:36:49 -07:00
|
|
|
add(MIGRATE_SESSION_PLAINTEXT);
|
2015-08-24 15:24:31 -07:00
|
|
|
add(MEDIA_DOWNLOAD_CONTROLS_VERSION);
|
2015-09-30 16:19:50 -07:00
|
|
|
add(REDPHONE_SUPPORT_VERSION);
|
2017-07-26 09:59:15 -07:00
|
|
|
add(NO_MORE_CANONICAL_DB_VERSION);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
}};
|
|
|
|
|
|
|
|
private MasterSecret masterSecret;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle bundle) {
|
|
|
|
super.onCreate(bundle);
|
2013-11-10 04:15:29 -08:00
|
|
|
this.masterSecret = getIntent().getParcelableExtra("master_secret");
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2013-11-10 04:15:29 -08:00
|
|
|
if (needsUpgradeTask()) {
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
Log.w("DatabaseUpgradeActivity", "Upgrading...");
|
|
|
|
setContentView(R.layout.database_upgrade_activity);
|
|
|
|
|
|
|
|
ProgressBar indeterminateProgress = (ProgressBar)findViewById(R.id.indeterminate_progress);
|
|
|
|
ProgressBar determinateProgress = (ProgressBar)findViewById(R.id.determinate_progress);
|
|
|
|
|
2013-05-07 16:31:11 -07:00
|
|
|
new DatabaseUpgradeTask(indeterminateProgress, determinateProgress)
|
|
|
|
.execute(VersionTracker.getLastSeenVersion(this));
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
} else {
|
2013-05-07 16:31:11 -07:00
|
|
|
VersionTracker.updateLastSeenVersion(this);
|
2015-08-12 10:44:27 -07:00
|
|
|
updateNotifications(this, masterSecret);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
startActivity((Intent)getIntent().getParcelableExtra("next_intent"));
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-10 04:15:29 -08:00
|
|
|
private boolean needsUpgradeTask() {
|
2014-07-23 15:40:45 -07:00
|
|
|
int currentVersionCode = Util.getCurrentApkReleaseVersion(this);
|
|
|
|
int lastSeenVersion = VersionTracker.getLastSeenVersion(this);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2014-07-23 15:40:45 -07:00
|
|
|
Log.w("DatabaseUpgradeActivity", "LastSeenVersion: " + lastSeenVersion);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2014-07-23 15:40:45 -07:00
|
|
|
if (lastSeenVersion >= currentVersionCode)
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
return false;
|
2014-07-23 15:40:45 -07:00
|
|
|
|
|
|
|
for (int version : UPGRADE_VERSIONS) {
|
|
|
|
Log.w("DatabaseUpgradeActivity", "Comparing: " + version);
|
|
|
|
if (lastSeenVersion < version)
|
|
|
|
return true;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
2014-07-23 15:40:45 -07:00
|
|
|
|
|
|
|
return false;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isUpdate(Context context) {
|
|
|
|
try {
|
2013-05-07 16:31:11 -07:00
|
|
|
int currentVersionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
|
|
|
|
int previousVersionCode = VersionTracker.getLastSeenVersion(context);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
|
|
|
return previousVersionCode < currentVersionCode;
|
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 10:44:27 -07:00
|
|
|
private void updateNotifications(final Context context, final MasterSecret masterSecret) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
public interface DatabaseUpgradeListener {
|
|
|
|
public void setProgress(int progress, int total);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class DatabaseUpgradeTask extends AsyncTask<Integer, Double, Void>
|
|
|
|
implements DatabaseUpgradeListener
|
|
|
|
{
|
|
|
|
|
|
|
|
private final ProgressBar indeterminateProgress;
|
|
|
|
private final ProgressBar determinateProgress;
|
|
|
|
|
|
|
|
public DatabaseUpgradeTask(ProgressBar indeterminateProgress, ProgressBar determinateProgress) {
|
|
|
|
this.indeterminateProgress = indeterminateProgress;
|
|
|
|
this.determinateProgress = determinateProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Integer... params) {
|
2013-11-10 04:15:29 -08:00
|
|
|
Context context = DatabaseUpgradeActivity.this.getApplicationContext();
|
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
Log.w("DatabaseUpgradeActivity", "Running background upgrade..");
|
|
|
|
DatabaseFactory.getInstance(DatabaseUpgradeActivity.this)
|
2013-11-10 04:15:29 -08:00
|
|
|
.onApplicationLevelUpgrade(context, masterSecret, params[0], this);
|
|
|
|
|
|
|
|
if (params[0] < CURVE25519_VERSION) {
|
2015-07-06 17:36:49 -07:00
|
|
|
IdentityKeyUtil.migrateIdentityKeys(context, masterSecret);
|
2013-11-10 04:15:29 -08:00
|
|
|
}
|
|
|
|
|
2014-04-22 14:33:29 -07:00
|
|
|
if (params[0] < NO_V1_VERSION) {
|
|
|
|
File v1sessions = new File(context.getFilesDir(), "sessions");
|
|
|
|
|
|
|
|
if (v1sessions.exists() && v1sessions.isDirectory()) {
|
|
|
|
File[] contents = v1sessions.listFiles();
|
|
|
|
|
|
|
|
if (contents != null) {
|
|
|
|
for (File session : contents) {
|
|
|
|
session.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v1sessions.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 10:39:25 -07:00
|
|
|
if (params[0] < SIGNED_PREKEY_VERSION) {
|
|
|
|
ApplicationContext.getInstance(getApplicationContext())
|
|
|
|
.getJobManager()
|
2015-07-06 17:36:49 -07:00
|
|
|
.add(new CreateSignedPreKeyJob(context));
|
2014-10-21 10:39:25 -07:00
|
|
|
}
|
|
|
|
|
2014-11-03 15:16:04 -08:00
|
|
|
if (params[0] < NO_DECRYPT_QUEUE_VERSION) {
|
2015-07-06 17:36:49 -07:00
|
|
|
scheduleMessagesInPushDatabase(context);
|
|
|
|
}
|
2014-11-21 12:53:40 -08:00
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
if (params[0] < PUSH_DECRYPT_SERIAL_ID_VERSION) {
|
|
|
|
scheduleMessagesInPushDatabase(context);
|
|
|
|
}
|
2014-11-21 12:53:40 -08:00
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
if (params[0] < MIGRATE_SESSION_PLAINTEXT) {
|
|
|
|
new TextSecureSessionStore(context, masterSecret).migrateSessions();
|
|
|
|
new TextSecurePreKeyStore(context, masterSecret).migrateRecords();
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
IdentityKeyUtil.migrateIdentityKeys(context, masterSecret);
|
|
|
|
scheduleMessagesInPushDatabase(context);;
|
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-07-14 14:35:28 -07:00
|
|
|
if (params[0] < CONTACTS_ACCOUNT_VERSION) {
|
|
|
|
ApplicationContext.getInstance(getApplicationContext())
|
|
|
|
.getJobManager()
|
|
|
|
.add(new DirectoryRefreshJob(getApplicationContext()));
|
|
|
|
}
|
|
|
|
|
2015-08-24 15:24:31 -07:00
|
|
|
if (params[0] < MEDIA_DOWNLOAD_CONTROLS_VERSION) {
|
|
|
|
schedulePendingIncomingParts(context);
|
|
|
|
}
|
|
|
|
|
2015-09-30 16:19:50 -07:00
|
|
|
if (params[0] < REDPHONE_SUPPORT_VERSION) {
|
|
|
|
ApplicationContext.getInstance(getApplicationContext())
|
|
|
|
.getJobManager()
|
|
|
|
.add(new RefreshAttributesJob(getApplicationContext()));
|
2015-10-02 07:55:59 -07:00
|
|
|
ApplicationContext.getInstance(getApplicationContext())
|
|
|
|
.getJobManager()
|
|
|
|
.add(new DirectoryRefreshJob(getApplicationContext()));
|
2015-09-30 16:19:50 -07:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
return null;
|
|
|
|
}
|
2014-11-21 12:53:40 -08:00
|
|
|
|
2015-08-24 15:24:31 -07:00
|
|
|
private void schedulePendingIncomingParts(Context context) {
|
2015-10-12 18:25:05 -07:00
|
|
|
final AttachmentDatabase attachmentDb = DatabaseFactory.getAttachmentDatabase(context);
|
|
|
|
final MmsDatabase mmsDb = DatabaseFactory.getMmsDatabase(context);
|
2017-03-28 12:05:30 -07:00
|
|
|
final List<DatabaseAttachment> pendingAttachments = DatabaseFactory.getAttachmentDatabase(context).getPendingAttachments(masterSecret);
|
2015-08-24 15:24:31 -07:00
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
Log.w(TAG, pendingAttachments.size() + " pending parts.");
|
|
|
|
for (DatabaseAttachment attachment : pendingAttachments) {
|
|
|
|
final Reader reader = mmsDb.readerFor(masterSecret, mmsDb.getMessage(attachment.getMmsId()));
|
2015-08-24 15:24:31 -07:00
|
|
|
final MessageRecord record = reader.getNext();
|
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
if (attachment.hasData()) {
|
|
|
|
Log.w(TAG, "corrected a pending media part " + attachment.getAttachmentId() + "that already had data.");
|
|
|
|
attachmentDb.setTransferState(attachment.getMmsId(), attachment.getAttachmentId(), AttachmentDatabase.TRANSFER_PROGRESS_DONE);
|
2015-09-04 10:56:59 -07:00
|
|
|
} else if (record != null && !record.isOutgoing() && record.isPush()) {
|
2015-10-12 18:25:05 -07:00
|
|
|
Log.w(TAG, "queuing new attachment download job for incoming push part " + attachment.getAttachmentId() + ".");
|
2015-08-24 15:24:31 -07:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2017-07-21 15:59:27 -07:00
|
|
|
.add(new AttachmentDownloadJob(context, attachment.getMmsId(), attachment.getAttachmentId(), false));
|
2015-08-24 15:24:31 -07:00
|
|
|
}
|
|
|
|
reader.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void scheduleMessagesInPushDatabase(Context context) {
|
|
|
|
PushDatabase pushDatabase = DatabaseFactory.getPushDatabase(context);
|
|
|
|
Cursor pushReader = null;
|
2014-11-21 12:53:40 -08:00
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
try {
|
|
|
|
pushReader = pushDatabase.getPending();
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
while (pushReader != null && pushReader.moveToNext()) {
|
|
|
|
ApplicationContext.getInstance(getApplicationContext())
|
|
|
|
.getJobManager()
|
|
|
|
.add(new PushDecryptJob(getApplicationContext(),
|
2017-07-26 09:59:15 -07:00
|
|
|
pushReader.getLong(pushReader.getColumnIndexOrThrow(PushDatabase.ID))));
|
2015-06-25 11:17:42 -07:00
|
|
|
}
|
2015-07-06 17:36:49 -07:00
|
|
|
} finally {
|
|
|
|
if (pushReader != null)
|
|
|
|
pushReader.close();
|
2015-06-25 11:17:42 -07:00
|
|
|
}
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onProgressUpdate(Double... update) {
|
|
|
|
indeterminateProgress.setVisibility(View.GONE);
|
|
|
|
determinateProgress.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
double scaler = update[0];
|
|
|
|
determinateProgress.setProgress((int)Math.floor(determinateProgress.getMax() * scaler));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
2013-05-07 16:31:11 -07:00
|
|
|
VersionTracker.updateLastSeenVersion(DatabaseUpgradeActivity.this);
|
2015-08-12 10:44:27 -07:00
|
|
|
updateNotifications(DatabaseUpgradeActivity.this, masterSecret);
|
2014-02-25 20:57:18 -08:00
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
startActivity((Intent)getIntent().getParcelableExtra("next_intent"));
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setProgress(int progress, int total) {
|
|
|
|
publishProgress(((double)progress / (double)total));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|