mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-16 09:21:25 +00:00
Lint warning changes.
This commit is contained in:
parent
d102bd015e
commit
3d3db421d3
@ -6,6 +6,28 @@
|
|||||||
|
|
||||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/>
|
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/>
|
||||||
|
|
||||||
|
<permission android:name="org.thoughtcrime.securesms.ACCESS_SECRETS"
|
||||||
|
android:label="Access to TextSecure Secrets"
|
||||||
|
android:protectionLevel="signature" />
|
||||||
|
|
||||||
|
<uses-permission android:name="org.thoughtcrime.securesms.ACCESS_SECRETS"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.BROADCAST_WAP_PUSH"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_MMS"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_SMS"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<application android:icon="@drawable/icon"
|
<application android:icon="@drawable/icon"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/Theme.Sherlock.Light.DarkActionBar">
|
android:theme="@style/Theme.Sherlock.Light.DarkActionBar">
|
||||||
@ -131,34 +153,12 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<provider android:name=".providers.PartProvider" android:authorities="org.thoughtcrime.provider.securesms" />
|
<provider android:name=".providers.PartProvider"
|
||||||
|
android:authorities="org.thoughtcrime.provider.securesms" />
|
||||||
|
|
||||||
<uses-library android:name="android.test.runner" />
|
<uses-library android:name="android.test.runner" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<permission android:name="org.thoughtcrime.securesms.ACCESS_SECRETS"
|
|
||||||
android:label="Access to TextSecure Secrets"
|
|
||||||
android:protectionLevel="signature" />
|
|
||||||
|
|
||||||
<uses-permission android:name="org.thoughtcrime.securesms.ACCESS_SECRETS"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.BROADCAST_WAP_PUSH"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
|
||||||
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.RECEIVE_MMS"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.WRITE_SMS"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
||||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
||||||
|
|
||||||
|
|
||||||
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
||||||
android:targetPackage="org.thoughtcrime.securesms.tests" android:label="Tests for My App" />
|
android:targetPackage="org.thoughtcrime.securesms.tests" android:label="Tests for My App" />
|
||||||
|
|
||||||
|
@ -1,63 +1,90 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="fill_parent">
|
|
||||||
<TableLayout
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent" >
|
||||||
android:stretchColumns="1">
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="16dip"
|
||||||
|
android:layout_marginRight="16dip"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<TableRow>
|
|
||||||
<TextView
|
<TextView
|
||||||
android:textSize="12sp"
|
android:padding="3dip"
|
||||||
android:text="@string/old_passphrase"
|
android:text="@string/old_passphrase"
|
||||||
android:padding="3dip" />
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<EditText android:id="@+id/old_passphrase"
|
<EditText
|
||||||
android:layout_height="wrap_content"
|
android:id="@+id/old_passphrase"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:password="true"/>
|
android:layout_height="wrap_content"
|
||||||
</TableRow>
|
android:inputType="textPassword"
|
||||||
|
android:layout_marginBottom="5dip" />
|
||||||
|
|
||||||
<TableRow>
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:padding="3dip"
|
||||||
android:text="@string/new_passphrase"
|
android:text="@string/new_passphrase"
|
||||||
android:textSize="12sp"
|
android:layout_width="fill_parent"
|
||||||
android:padding="3dip" />
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<EditText android:id="@+id/new_passphrase"
|
<EditText
|
||||||
android:layout_height="wrap_content"
|
android:id="@+id/new_passphrase"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:password="true"
|
android:layout_height="wrap_content"
|
||||||
/>
|
android:inputType="textPassword"
|
||||||
</TableRow>
|
android:layout_marginBottom="5dip" />
|
||||||
|
|
||||||
<TableRow>
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:padding="3dip"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/repeat_new_passphrase"
|
android:text="@string/repeat_new_passphrase"
|
||||||
android:textSize="12sp"
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
android:padding="3dip" />
|
|
||||||
|
|
||||||
<EditText android:id="@+id/repeat_passphrase"
|
<EditText
|
||||||
android:layout_height="wrap_content"
|
android:id="@+id/repeat_passphrase"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:password="true"
|
android:layout_height="wrap_content"
|
||||||
/>
|
android:inputType="textPassword"
|
||||||
</TableRow>
|
android:layout_marginBottom="5dip" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dip"
|
||||||
|
android:gravity="right"
|
||||||
|
android:orientation="horizontal" >
|
||||||
|
|
||||||
<TableRow>
|
<TableLayout
|
||||||
<Button android:id="@+id/cancel_button"
|
android:layout_width="wrap_content"
|
||||||
android:padding="10dip"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:stretchColumns="*"
|
||||||
android:layout_height="wrap_content"
|
tools:ignore="UselessParent" >
|
||||||
android:text="@string/cancel"/>
|
|
||||||
|
|
||||||
<Button android:id="@+id/ok_button"
|
<TableRow>
|
||||||
android:padding="10dip"
|
|
||||||
android:layout_width="wrap_content"
|
<Button
|
||||||
android:layout_height="wrap_content"
|
android:id="@+id/cancel_button"
|
||||||
android:text="@android:string/ok"/>
|
android:layout_width="wrap_content"
|
||||||
</TableRow>
|
android:layout_height="wrap_content"
|
||||||
</TableLayout>
|
android:layout_marginLeft="16dip"
|
||||||
</ScrollView>
|
android:layout_marginRight="15dip"
|
||||||
|
android:text="@string/cancel" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/ok_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="16dip"
|
||||||
|
android:text="@android:string/ok" />
|
||||||
|
</TableRow>
|
||||||
|
</TableLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="5dip"
|
android:paddingBottom="5dip"
|
||||||
android:background="#fff">
|
android:background="#fff">
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMediumInverse"
|
android:textAppearance="?android:attr/textAppearanceMediumInverse"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<EditText android:id="@+id/passphrase_edit"
|
<EditText android:id="@+id/passphrase_edit"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:password="true"/>
|
android:inputType="textPassword"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
@ -42,7 +42,7 @@
|
|||||||
<EditText
|
<EditText
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:password="true"
|
android:inputType="textPassword"
|
||||||
android:id="@+id/passphrase_edit_repeat"/>
|
android:id="@+id/passphrase_edit_repeat"/>
|
||||||
|
|
||||||
<LinearLayout android:layout_width="fill_parent"
|
<LinearLayout android:layout_width="fill_parent"
|
||||||
|
@ -1,46 +1,58 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:orientation="vertical">
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<TextView android:layout_width="fill_parent"
|
<TextView
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_marginLeft="16dip"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginRight="16dip"
|
android:layout_marginBottom="5dip"
|
||||||
android:layout_marginTop="5dip"
|
android:layout_marginLeft="16dip"
|
||||||
android:layout_marginBottom="5dip"
|
android:layout_marginRight="16dip"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:layout_marginTop="5dip"
|
||||||
android:text="@string/identity_name" />
|
android:text="@string/identity_name"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<EditText android:layout_height="wrap_content"
|
<EditText
|
||||||
android:layout_width="fill_parent"
|
android:id="@+id/identity_name"
|
||||||
android:id="@+id/identity_name"
|
android:layout_width="fill_parent"
|
||||||
android:layout_margin="16dip"/>
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16dip"
|
||||||
|
tools:ignore="TextFields" />
|
||||||
|
|
||||||
<LinearLayout android:layout_width="fill_parent"
|
<LinearLayout
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:orientation="horizontal"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dip"
|
android:layout_marginBottom="16dip"
|
||||||
android:gravity="right">
|
android:gravity="right"
|
||||||
|
android:orientation="horizontal" >
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:stretchColumns="*"
|
||||||
|
tools:ignore="UselessParent" >
|
||||||
|
|
||||||
<TableLayout android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:stretchColumns="*">
|
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<Button android:layout_height="wrap_content"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:text="@string/cancel"
|
|
||||||
android:id="@+id/cancel_button"
|
|
||||||
android:layout_marginRight="15dip"
|
|
||||||
android:layout_marginLeft="16dip"/>
|
|
||||||
|
|
||||||
<Button android:layout_width="wrap_content"
|
<Button
|
||||||
android:layout_height="wrap_content"
|
android:id="@+id/cancel_button"
|
||||||
android:text="@android:string/ok"
|
android:layout_width="wrap_content"
|
||||||
android:id="@+id/ok_button"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginRight="16dip"/>
|
android:layout_marginLeft="16dip"
|
||||||
|
android:layout_marginRight="15dip"
|
||||||
|
android:text="@string/cancel" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/ok_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="16dip"
|
||||||
|
android:text="@android:string/ok" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableLayout>
|
</TableLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -4,7 +4,7 @@
|
|||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent">
|
||||||
<TableLayout
|
<TableLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="wrap_content"
|
||||||
android:shrinkColumns="1">
|
android:shrinkColumns="1">
|
||||||
|
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
android:layout_marginRight="16dip">
|
android:layout_marginRight="16dip">
|
||||||
<TableLayout
|
<TableLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="wrap_content"
|
||||||
android:shrinkColumns="1">
|
android:shrinkColumns="1">
|
||||||
|
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
@ -185,7 +185,7 @@ public class ContactAccessorNewApi extends ContactAccessor {
|
|||||||
return rawContactIds;
|
return rawContactIds;
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
rawContactIds.add(new Long(cursor.getLong(0)));
|
rawContactIds.add(Long.valueOf(cursor.getLong(0)));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null)
|
if (cursor != null)
|
||||||
|
@ -119,7 +119,7 @@ public class CanonicalAddressDatabase {
|
|||||||
|
|
||||||
private long getCanonicalAddressFromCache(String address) {
|
private long getCanonicalAddressFromCache(String address) {
|
||||||
if (addressCache.containsKey(address))
|
if (addressCache.containsKey(address))
|
||||||
return new Long(addressCache.get(address));
|
return Long.valueOf(addressCache.get(address));
|
||||||
|
|
||||||
return -1L;
|
return -1L;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2011 Whisper Systems
|
* Copyright (C) 2011 Whisper Systems
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@ -10,19 +10,12 @@
|
|||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.thoughtcrime.securesms.database;
|
package org.thoughtcrime.securesms.database;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@ -32,15 +25,22 @@ import android.database.sqlite.SQLiteStatement;
|
|||||||
import android.telephony.SmsMessage;
|
import android.telephony.SmsMessage;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database for storage of SMS messages.
|
* Database for storage of SMS messages.
|
||||||
*
|
*
|
||||||
* @author Moxie Marlinspike
|
* @author Moxie Marlinspike
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SmsDatabase extends Database {
|
public class SmsDatabase extends Database {
|
||||||
public static final String TRANSPORT = "transport_type";
|
public static final String TRANSPORT = "transport_type";
|
||||||
|
|
||||||
public static final String TABLE_NAME = "sms";
|
public static final String TABLE_NAME = "sms";
|
||||||
public static final String ID = "_id";
|
public static final String ID = "_id";
|
||||||
public static final String THREAD_ID = "thread_id";
|
public static final String THREAD_ID = "thread_id";
|
||||||
@ -55,65 +55,65 @@ public class SmsDatabase extends Database {
|
|||||||
public static final String SUBJECT = "subject";
|
public static final String SUBJECT = "subject";
|
||||||
public static final String BODY = "body";
|
public static final String BODY = "body";
|
||||||
public static final String SERVICE_CENTER = "service_center";
|
public static final String SERVICE_CENTER = "service_center";
|
||||||
|
|
||||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " integer PRIMARY KEY, " +
|
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " integer PRIMARY KEY, " +
|
||||||
THREAD_ID + " INTEGER, " + ADDRESS + " TEXT, " + PERSON + " INTEGER, " + DATE + " INTEGER, " +
|
THREAD_ID + " INTEGER, " + ADDRESS + " TEXT, " + PERSON + " INTEGER, " + DATE + " INTEGER, " +
|
||||||
PROTOCOL + " INTEGER, " + READ + " INTEGER DEFAULT 0, " + STATUS + " INTEGER DEFAULT -1," +
|
PROTOCOL + " INTEGER, " + READ + " INTEGER DEFAULT 0, " + STATUS + " INTEGER DEFAULT -1," +
|
||||||
TYPE + " INTEGER, " + REPLY_PATH_PRESENT + " INTEGER, " + SUBJECT + " TEXT, " + BODY + " TEXT, " +
|
TYPE + " INTEGER, " + REPLY_PATH_PRESENT + " INTEGER, " + SUBJECT + " TEXT, " + BODY + " TEXT, " +
|
||||||
SERVICE_CENTER + " TEXT);";
|
SERVICE_CENTER + " TEXT);";
|
||||||
|
|
||||||
public SmsDatabase(Context context, SQLiteOpenHelper databaseHelper) {
|
public SmsDatabase(Context context, SQLiteOpenHelper databaseHelper) {
|
||||||
super(context, databaseHelper);
|
super(context, databaseHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateType(long id, long type) {
|
private void updateType(long id, long type) {
|
||||||
Log.w("MessageDatabase", "Updating ID: " + id + " to type: " + type);
|
Log.w("MessageDatabase", "Updating ID: " + id + " to type: " + type);
|
||||||
ContentValues contentValues = new ContentValues();
|
ContentValues contentValues = new ContentValues();
|
||||||
contentValues.put(TYPE, type);
|
contentValues.put(TYPE, type);
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {id+""});
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {id+""});
|
||||||
notifyConversationListeners(getThreadIdForMessage(id));
|
notifyConversationListeners(getThreadIdForMessage(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private long insertMessageReceived(SmsMessage message, String body, long type) {
|
private long insertMessageReceived(SmsMessage message, String body, long type) {
|
||||||
List<Recipient> recipientList = new ArrayList<Recipient>(1);
|
List<Recipient> recipientList = new ArrayList<Recipient>(1);
|
||||||
recipientList.add(new Recipient(null, message.getDisplayOriginatingAddress(), null));
|
recipientList.add(new Recipient(null, message.getDisplayOriginatingAddress(), null));
|
||||||
Recipients recipients = new Recipients(recipientList);
|
Recipients recipients = new Recipients(recipientList);
|
||||||
|
|
||||||
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
|
||||||
|
|
||||||
ContentValues values = new ContentValues(6);
|
ContentValues values = new ContentValues(6);
|
||||||
values.put(ADDRESS, message.getDisplayOriginatingAddress());
|
values.put(ADDRESS, message.getDisplayOriginatingAddress());
|
||||||
values.put(DATE, new Long(System.currentTimeMillis()));
|
values.put(DATE, Long.valueOf(System.currentTimeMillis()));
|
||||||
values.put(PROTOCOL, message.getProtocolIdentifier());
|
values.put(PROTOCOL, message.getProtocolIdentifier());
|
||||||
values.put(READ, Integer.valueOf(0));
|
values.put(READ, Integer.valueOf(0));
|
||||||
|
|
||||||
if (message.getPseudoSubject().length() > 0)
|
if (message.getPseudoSubject().length() > 0)
|
||||||
values.put(SUBJECT, message.getPseudoSubject());
|
values.put(SUBJECT, message.getPseudoSubject());
|
||||||
|
|
||||||
values.put(REPLY_PATH_PRESENT, message.isReplyPathPresent() ? 1 : 0);
|
values.put(REPLY_PATH_PRESENT, message.isReplyPathPresent() ? 1 : 0);
|
||||||
values.put(SERVICE_CENTER, message.getServiceCenterAddress());
|
values.put(SERVICE_CENTER, message.getServiceCenterAddress());
|
||||||
values.put(BODY, body);
|
values.put(BODY, body);
|
||||||
values.put(TYPE, type);
|
values.put(TYPE, type);
|
||||||
values.put(THREAD_ID, threadId);
|
values.put(THREAD_ID, threadId);
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
long messageId = db.insert(TABLE_NAME, null, values);
|
long messageId = db.insert(TABLE_NAME, null, values);
|
||||||
|
|
||||||
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
||||||
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
return messageId;
|
return messageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getThreadIdForMessage(long id) {
|
public long getThreadIdForMessage(long id) {
|
||||||
String sql = "SELECT " + THREAD_ID + " FROM " + TABLE_NAME + " WHERE " + ID + " = ?";
|
String sql = "SELECT " + THREAD_ID + " FROM " + TABLE_NAME + " WHERE " + ID + " = ?";
|
||||||
String[] sqlArgs = new String[] {id+""};
|
String[] sqlArgs = new String[] {id+""};
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
|
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = db.rawQuery(sql, sqlArgs);
|
cursor = db.rawQuery(sql, sqlArgs);
|
||||||
if (cursor != null && cursor.moveToFirst())
|
if (cursor != null && cursor.moveToFirst())
|
||||||
@ -125,14 +125,14 @@ public class SmsDatabase extends Database {
|
|||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMessageCountForThread(long threadId) {
|
public int getMessageCountForThread(long threadId) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = db.query(TABLE_NAME, new String[] {"COUNT(*)"}, THREAD_ID + " = ?", new String[] {threadId+""}, null, null, null);
|
cursor = db.query(TABLE_NAME, new String[] {"COUNT(*)"}, THREAD_ID + " = ?", new String[] {threadId+""}, null, null, null);
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst())
|
if (cursor != null && cursor.moveToFirst())
|
||||||
return cursor.getInt(0);
|
return cursor.getInt(0);
|
||||||
} finally {
|
} finally {
|
||||||
@ -142,42 +142,42 @@ public class SmsDatabase extends Database {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsDecryptFailed(long id) {
|
public void markAsDecryptFailed(long id) {
|
||||||
updateType(id, Types.FAILED_DECRYPT_TYPE);
|
updateType(id, Types.FAILED_DECRYPT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsNoSession(long id) {
|
public void markAsNoSession(long id) {
|
||||||
updateType(id, Types.NO_SESSION_TYPE);
|
updateType(id, Types.NO_SESSION_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsDecrypting(long id) {
|
public void markAsDecrypting(long id) {
|
||||||
updateType(id, Types.DECRYPT_IN_PROGRESS_TYPE);
|
updateType(id, Types.DECRYPT_IN_PROGRESS_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsSent(long id, long type) {
|
public void markAsSent(long id, long type) {
|
||||||
if (type == Types.ENCRYPTING_TYPE)
|
if (type == Types.ENCRYPTING_TYPE)
|
||||||
updateType(id, Types.SECURE_SENT_TYPE);
|
updateType(id, Types.SECURE_SENT_TYPE);
|
||||||
else
|
else
|
||||||
updateType(id, Types.SENT_TYPE);
|
updateType(id, Types.SENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsSentFailed(long id) {
|
public void markAsSentFailed(long id) {
|
||||||
updateType(id, Types.FAILED_TYPE);
|
updateType(id, Types.FAILED_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessagesRead(long threadId) {
|
public void setMessagesRead(long threadId) {
|
||||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||||
ContentValues contentValues = new ContentValues();
|
ContentValues contentValues = new ContentValues();
|
||||||
contentValues.put(READ, 1);
|
contentValues.put(READ, 1);
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
database.update(TABLE_NAME, contentValues, THREAD_ID + " = ? AND " + READ + " = 0", new String[] {threadId+""});
|
database.update(TABLE_NAME, contentValues, THREAD_ID + " = ? AND " + READ + " = 0", new String[] {threadId+""});
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
|
|
||||||
Log.w("SmsDatabase", "setMessagesRead time: " + (end-start));
|
Log.w("SmsDatabase", "setMessagesRead time: " + (end-start));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMessageBodyAndType(long messageId, String body, long type) {
|
public void updateMessageBodyAndType(long messageId, String body, long type) {
|
||||||
ContentValues contentValues = new ContentValues();
|
ContentValues contentValues = new ContentValues();
|
||||||
contentValues.put(BODY, body);
|
contentValues.put(BODY, body);
|
||||||
@ -185,20 +185,20 @@ public class SmsDatabase extends Database {
|
|||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {messageId+""});
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {messageId+""});
|
||||||
|
|
||||||
DatabaseFactory.getThreadDatabase(context).update(getThreadIdForMessage(messageId));
|
DatabaseFactory.getThreadDatabase(context).update(getThreadIdForMessage(messageId));
|
||||||
notifyConversationListeners(getThreadIdForMessage(messageId));
|
notifyConversationListeners(getThreadIdForMessage(messageId));
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long insertSecureMessageReceived(SmsMessage message, String body) {
|
public long insertSecureMessageReceived(SmsMessage message, String body) {
|
||||||
return insertMessageReceived(message, body, Types.DECRYPT_IN_PROGRESS_TYPE);
|
return insertMessageReceived(message, body, Types.DECRYPT_IN_PROGRESS_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long insertMessageReceived(SmsMessage message, String body) {
|
public long insertMessageReceived(SmsMessage message, String body) {
|
||||||
return insertMessageReceived(message, body, Types.INBOX_TYPE);
|
return insertMessageReceived(message, body, Types.INBOX_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long insertMessageSent(String address, long threadId, String body, long date, long type) {
|
public long insertMessageSent(String address, long threadId, String body, long date, long type) {
|
||||||
ContentValues contentValues = new ContentValues(6);
|
ContentValues contentValues = new ContentValues(6);
|
||||||
// contentValues.put(ADDRESS, NumberUtil.filterNumber(address));
|
// contentValues.put(ADDRESS, NumberUtil.filterNumber(address));
|
||||||
@ -208,7 +208,7 @@ public class SmsDatabase extends Database {
|
|||||||
contentValues.put(DATE, date);
|
contentValues.put(DATE, date);
|
||||||
contentValues.put(READ, 1);
|
contentValues.put(READ, 1);
|
||||||
contentValues.put(TYPE, type);
|
contentValues.put(TYPE, type);
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
|
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
|
||||||
|
|
||||||
@ -223,25 +223,25 @@ public class SmsDatabase extends Database {
|
|||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
return db.query(TABLE_NAME, null, outgoingSelection, null, null, null, null);
|
return db.query(TABLE_NAME, null, outgoingSelection, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getDecryptInProgressMessages() {
|
public Cursor getDecryptInProgressMessages() {
|
||||||
String where = TYPE + " = " + Types.DECRYPT_IN_PROGRESS_TYPE;
|
String where = TYPE + " = " + Types.DECRYPT_IN_PROGRESS_TYPE;
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
return db.query(TABLE_NAME, null, where, null, null, null, null);
|
return db.query(TABLE_NAME, null, where, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getEncryptedRogueMessages(Recipient recipient) {
|
public Cursor getEncryptedRogueMessages(Recipient recipient) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
String selection = TYPE + " = " + Types.NO_SESSION_TYPE + " AND PHONE_NUMBERS_EQUAL(" + ADDRESS + ", ?)";
|
String selection = TYPE + " = " + Types.NO_SESSION_TYPE + " AND PHONE_NUMBERS_EQUAL(" + ADDRESS + ", ?)";
|
||||||
String[] args = {recipient.getNumber()};
|
String[] args = {recipient.getNumber()};
|
||||||
return db.query(TABLE_NAME, null, selection, args, null, null, null);
|
return db.query(TABLE_NAME, null, selection, args, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getMessage(long messageId) {
|
public Cursor getMessage(long messageId) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
return db.query(TABLE_NAME, null, ID_WHERE, new String[] {messageId+""}, null, null, null);
|
return db.query(TABLE_NAME, null, ID_WHERE, new String[] {messageId+""}, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteMessage(long messageId) {
|
public void deleteMessage(long messageId) {
|
||||||
Log.w("MessageDatabase", "Deleting: " + messageId);
|
Log.w("MessageDatabase", "Deleting: " + messageId);
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
@ -250,31 +250,31 @@ public class SmsDatabase extends Database {
|
|||||||
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package */void deleteThread(long threadId) {
|
/*package */void deleteThread(long threadId) {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.delete(TABLE_NAME, THREAD_ID + " = ?", new String[] {threadId+""});
|
db.delete(TABLE_NAME, THREAD_ID + " = ?", new String[] {threadId+""});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*package*/ void deleteThreads(Set<Long> threadIds) {
|
/*package*/ void deleteThreads(Set<Long> threadIds) {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
String where = "";
|
String where = "";
|
||||||
|
|
||||||
for (long threadId : threadIds) {
|
for (long threadId : threadIds) {
|
||||||
where += THREAD_ID + " = '" + threadId + "' OR ";
|
where += THREAD_ID + " = '" + threadId + "' OR ";
|
||||||
}
|
}
|
||||||
|
|
||||||
where = where.substring(0, where.length() - 4);
|
where = where.substring(0, where.length() - 4);
|
||||||
|
|
||||||
db.delete(TABLE_NAME, where, null);
|
db.delete(TABLE_NAME, where, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package */ void deleteAllThreads() {
|
/*package */ void deleteAllThreads() {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.delete(TABLE_NAME, null, null);
|
db.delete(TABLE_NAME, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ SQLiteDatabase beginTransaction() {
|
/*package*/ SQLiteDatabase beginTransaction() {
|
||||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
@ -284,23 +284,23 @@ public class SmsDatabase extends Database {
|
|||||||
/*package*/ void endTransaction(SQLiteDatabase database) {
|
/*package*/ void endTransaction(SQLiteDatabase database) {
|
||||||
database.setTransactionSuccessful();
|
database.setTransactionSuccessful();
|
||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ void insertRaw(SQLiteDatabase database, ContentValues contentValues) {
|
/*package*/ void insertRaw(SQLiteDatabase database, ContentValues contentValues) {
|
||||||
database.insert(TABLE_NAME, null, contentValues);
|
database.insert(TABLE_NAME, null, contentValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ SQLiteStatement createInsertStatement(SQLiteDatabase database) {
|
/*package*/ SQLiteStatement createInsertStatement(SQLiteDatabase database) {
|
||||||
return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " + PERSON + ", " + DATE + ", " + PROTOCOL + ", " + READ + ", " + STATUS + ", " + TYPE + ", " + REPLY_PATH_PRESENT + ", " + SUBJECT + ", " + BODY + ", " + SERVICE_CENTER + ", THREAD_ID) " +
|
return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " + PERSON + ", " + DATE + ", " + PROTOCOL + ", " + READ + ", " + STATUS + ", " + TYPE + ", " + REPLY_PATH_PRESENT + ", " + SUBJECT + ", " + BODY + ", " + SERVICE_CENTER + ", THREAD_ID) " +
|
||||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Types {
|
public static class Types {
|
||||||
public static final int INBOX_TYPE = 1;
|
public static final int INBOX_TYPE = 1;
|
||||||
public static final int SENT_TYPE = 2;
|
public static final int SENT_TYPE = 2;
|
||||||
public static final int SENT_PENDING = 4;
|
public static final int SENT_PENDING = 4;
|
||||||
public static final int FAILED_TYPE = 5;
|
public static final int FAILED_TYPE = 5;
|
||||||
|
|
||||||
public static final int ENCRYPTING_TYPE = 42; // Messages are stored local encrypted and need async encryption and delivery.
|
public static final int ENCRYPTING_TYPE = 42; // Messages are stored local encrypted and need async encryption and delivery.
|
||||||
public static final int ENCRYPTED_OUTBOX_TYPE = 43; // Messages are stored local encrypted and need delivery.
|
public static final int ENCRYPTED_OUTBOX_TYPE = 43; // Messages are stored local encrypted and need delivery.
|
||||||
public static final int SECURE_SENT_TYPE = 44; // Messages were sent with async encryption.
|
public static final int SECURE_SENT_TYPE = 44; // Messages were sent with async encryption.
|
||||||
@ -308,23 +308,23 @@ public class SmsDatabase extends Database {
|
|||||||
public static final int FAILED_DECRYPT_TYPE = 46; // Messages were received with async encryption and failed to decrypt.
|
public static final int FAILED_DECRYPT_TYPE = 46; // Messages were received with async encryption and failed to decrypt.
|
||||||
public static final int DECRYPT_IN_PROGRESS_TYPE = 47; // Messages are in the process of being asymmetricaly decrypted.
|
public static final int DECRYPT_IN_PROGRESS_TYPE = 47; // Messages are in the process of being asymmetricaly decrypted.
|
||||||
public static final int NO_SESSION_TYPE = 48; // Messages were received with async encryption but there is no session yet.
|
public static final int NO_SESSION_TYPE = 48; // Messages were received with async encryption but there is no session yet.
|
||||||
|
|
||||||
public static boolean isFailedMessageType(long type) {
|
public static boolean isFailedMessageType(long type) {
|
||||||
return type == FAILED_TYPE;
|
return type == FAILED_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOutgoingMessageType(long type) {
|
public static boolean isOutgoingMessageType(long type) {
|
||||||
return type == SENT_TYPE || type == SENT_PENDING || type == ENCRYPTING_TYPE || type == ENCRYPTED_OUTBOX_TYPE || type == SECURE_SENT_TYPE || type == FAILED_TYPE;
|
return type == SENT_TYPE || type == SENT_PENDING || type == ENCRYPTING_TYPE || type == ENCRYPTED_OUTBOX_TYPE || type == SECURE_SENT_TYPE || type == FAILED_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPendingMessageType(long type) {
|
public static boolean isPendingMessageType(long type) {
|
||||||
return type == SENT_PENDING || type == ENCRYPTING_TYPE || type == ENCRYPTED_OUTBOX_TYPE;
|
return type == SENT_PENDING || type == ENCRYPTING_TYPE || type == ENCRYPTED_OUTBOX_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSecureType(long type) {
|
public static boolean isSecureType(long type) {
|
||||||
return type == SECURE_SENT_TYPE || type == ENCRYPTING_TYPE || type == SECURE_RECEIVED_TYPE;
|
return type == SECURE_SENT_TYPE || type == ENCRYPTING_TYPE || type == SECURE_RECEIVED_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2011 Whisper Systems
|
* Copyright (C) 2011 Whisper Systems
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@ -10,26 +10,26 @@
|
|||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.thoughtcrime.securesms.database;
|
package org.thoughtcrime.securesms.database;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class ThreadDatabase extends Database {
|
public class ThreadDatabase extends Database {
|
||||||
|
|
||||||
private static final String TABLE_NAME = "thread";
|
private static final String TABLE_NAME = "thread";
|
||||||
@ -48,7 +48,7 @@ public class ThreadDatabase extends Database {
|
|||||||
DATE + " INTEGER DEFAULT 0, " + MESSAGE_COUNT + " INTEGER DEFAULT 0, " +
|
DATE + " INTEGER DEFAULT 0, " + MESSAGE_COUNT + " INTEGER DEFAULT 0, " +
|
||||||
RECIPIENT_IDS + " TEXT, " + SNIPPET + " TEXT, " + SNIPPET_CHARSET + " INTEGER DEFAULT 0, " +
|
RECIPIENT_IDS + " TEXT, " + SNIPPET + " TEXT, " + SNIPPET_CHARSET + " INTEGER DEFAULT 0, " +
|
||||||
READ + " INTEGER DEFAULT 1, " + TYPE + " INTEGER DEFAULT 0, " + ERROR + " INTEGER DEFAULT 0, " +
|
READ + " INTEGER DEFAULT 1, " + TYPE + " INTEGER DEFAULT 0, " + ERROR + " INTEGER DEFAULT 0, " +
|
||||||
HAS_ATTACHMENT + " INTEGER DEFAULT 0);";
|
HAS_ATTACHMENT + " INTEGER DEFAULT 0);";
|
||||||
|
|
||||||
public ThreadDatabase(Context context, SQLiteOpenHelper databaseHelper) {
|
public ThreadDatabase(Context context, SQLiteOpenHelper databaseHelper) {
|
||||||
super(context, databaseHelper);
|
super(context, databaseHelper);
|
||||||
@ -62,41 +62,41 @@ public class ThreadDatabase extends Database {
|
|||||||
for (Recipient recipient : recipientList) {
|
for (Recipient recipient : recipientList) {
|
||||||
// String number = NumberUtil.filterNumber(recipient.getNumber());
|
// String number = NumberUtil.filterNumber(recipient.getNumber());
|
||||||
String number = recipient.getNumber();
|
String number = recipient.getNumber();
|
||||||
recipientSet.add(new Long(DatabaseFactory.getAddressDatabase(context).getCanonicalAddress(number)));
|
recipientSet.add(Long.valueOf(DatabaseFactory.getAddressDatabase(context).getCanonicalAddress(number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
long[] recipientArray = new long[recipientSet.size()];
|
long[] recipientArray = new long[recipientSet.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (Long recipientId : recipientSet) {
|
for (Long recipientId : recipientSet) {
|
||||||
recipientArray[i++] = recipientId;
|
recipientArray[i++] = recipientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arrays.sort(recipientArray);
|
Arrays.sort(recipientArray);
|
||||||
|
|
||||||
return recipientArray;
|
return recipientArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRecipientsAsString(long[] recipientIds) {
|
private String getRecipientsAsString(long[] recipientIds) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i=0;i<recipientIds.length;i++) {
|
for (int i=0;i<recipientIds.length;i++) {
|
||||||
if (i != 0) sb.append(' ');
|
if (i != 0) sb.append(' ');
|
||||||
sb.append(recipientIds[i]);
|
sb.append(recipientIds[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long createThreadForRecipients(String recipients, int recipientCount) {
|
private long createThreadForRecipients(String recipients, int recipientCount) {
|
||||||
ContentValues contentValues = new ContentValues(4);
|
ContentValues contentValues = new ContentValues(4);
|
||||||
long date = System.currentTimeMillis();
|
long date = System.currentTimeMillis();
|
||||||
|
|
||||||
contentValues.put(DATE, date - date % 1000);
|
contentValues.put(DATE, date - date % 1000);
|
||||||
contentValues.put(RECIPIENT_IDS, recipients);
|
contentValues.put(RECIPIENT_IDS, recipients);
|
||||||
|
|
||||||
if (recipientCount > 1)
|
if (recipientCount > 1)
|
||||||
contentValues.put(TYPE, 1);
|
contentValues.put(TYPE, 1);
|
||||||
|
|
||||||
contentValues.put(MESSAGE_COUNT, 0);
|
contentValues.put(MESSAGE_COUNT, 0);
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
@ -108,100 +108,100 @@ public class ThreadDatabase extends Database {
|
|||||||
contentValues.put(DATE, date - date % 1000);
|
contentValues.put(DATE, date - date % 1000);
|
||||||
contentValues.put(MESSAGE_COUNT, count);
|
contentValues.put(MESSAGE_COUNT, count);
|
||||||
contentValues.put(SNIPPET, body);
|
contentValues.put(SNIPPET, body);
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] {threadId+""});
|
db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] {threadId+""});
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteThread(long threadId) {
|
private void deleteThread(long threadId) {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.delete(TABLE_NAME, ID_WHERE, new String[] {threadId+""});
|
db.delete(TABLE_NAME, ID_WHERE, new String[] {threadId+""});
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteThreads(Set<Long> threadIds) {
|
private void deleteThreads(Set<Long> threadIds) {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
String where = "";
|
String where = "";
|
||||||
|
|
||||||
for (long threadId : threadIds) {
|
for (long threadId : threadIds) {
|
||||||
where += ID + " = '" + threadId + "' OR ";
|
where += ID + " = '" + threadId + "' OR ";
|
||||||
}
|
}
|
||||||
|
|
||||||
where = where.substring(0, where.length() - 4);
|
where = where.substring(0, where.length() - 4);
|
||||||
|
|
||||||
db.delete(TABLE_NAME, where, null);
|
db.delete(TABLE_NAME, where, null);
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteAllThreads() {
|
private void deleteAllThreads() {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.delete(TABLE_NAME, null, null);
|
db.delete(TABLE_NAME, null, null);
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRead(long threadId) {
|
public void setRead(long threadId) {
|
||||||
ContentValues contentValues = new ContentValues(1);
|
ContentValues contentValues = new ContentValues(1);
|
||||||
contentValues.put(READ, 1);
|
contentValues.put(READ, 1);
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId+""});
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId+""});
|
||||||
|
|
||||||
DatabaseFactory.getSmsDatabase(context).setMessagesRead(threadId);
|
DatabaseFactory.getSmsDatabase(context).setMessagesRead(threadId);
|
||||||
DatabaseFactory.getMmsDatabase(context).setMessagesRead(threadId);
|
DatabaseFactory.getMmsDatabase(context).setMessagesRead(threadId);
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUnread(long threadId) {
|
public void setUnread(long threadId) {
|
||||||
ContentValues contentValues = new ContentValues(1);
|
ContentValues contentValues = new ContentValues(1);
|
||||||
contentValues.put("read", 0);
|
contentValues.put("read", 0);
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId+""});
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId+""});
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getFilteredConversationList(List<String> filter) {
|
public Cursor getFilteredConversationList(List<String> filter) {
|
||||||
if (filter == null || filter.size() == 0)
|
if (filter == null || filter.size() == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
List<Long> recipientIds = DatabaseFactory.getAddressDatabase(context).getCanonicalAddresses(filter);
|
List<Long> recipientIds = DatabaseFactory.getAddressDatabase(context).getCanonicalAddresses(filter);
|
||||||
|
|
||||||
if (recipientIds == null || recipientIds.size() == 0)
|
if (recipientIds == null || recipientIds.size() == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
String selection = RECIPIENT_IDS + " = ?";
|
String selection = RECIPIENT_IDS + " = ?";
|
||||||
String[] selectionArgs = new String[recipientIds.size()];
|
String[] selectionArgs = new String[recipientIds.size()];
|
||||||
|
|
||||||
for (int i=0;i<recipientIds.size()-1;i++)
|
for (int i=0;i<recipientIds.size()-1;i++)
|
||||||
selection += (" OR " + RECIPIENT_IDS + " = ?");
|
selection += (" OR " + RECIPIENT_IDS + " = ?");
|
||||||
|
|
||||||
int i= 0;
|
int i= 0;
|
||||||
for (long id : recipientIds) {
|
for (long id : recipientIds) {
|
||||||
selectionArgs[i++] = id+"";
|
selectionArgs[i++] = id+"";
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
Cursor cursor = db.query(TABLE_NAME, null, selection, selectionArgs, null, null, DATE + " DESC");
|
Cursor cursor = db.query(TABLE_NAME, null, selection, selectionArgs, null, null, DATE + " DESC");
|
||||||
setNotifyConverationListListeners(cursor);
|
setNotifyConverationListListeners(cursor);
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getConversationList() {
|
public Cursor getConversationList() {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, DATE + " DESC");
|
Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, DATE + " DESC");
|
||||||
setNotifyConverationListListeners(cursor);
|
setNotifyConverationListListeners(cursor);
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteConversation(long threadId) {
|
public void deleteConversation(long threadId) {
|
||||||
DatabaseFactory.getSmsDatabase(context).deleteThread(threadId);
|
DatabaseFactory.getSmsDatabase(context).deleteThread(threadId);
|
||||||
DatabaseFactory.getMmsDatabase(context).deleteThread(threadId);
|
DatabaseFactory.getMmsDatabase(context).deleteThread(threadId);
|
||||||
deleteThread(threadId);
|
deleteThread(threadId);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void deleteConversations(Set<Long> selectedConversations) {
|
public void deleteConversations(Set<Long> selectedConversations) {
|
||||||
DatabaseFactory.getSmsDatabase(context).deleteThreads(selectedConversations);
|
DatabaseFactory.getSmsDatabase(context).deleteThreads(selectedConversations);
|
||||||
@ -210,11 +210,11 @@ public class ThreadDatabase extends Database {
|
|||||||
notifyConversationListeners(selectedConversations);
|
notifyConversationListeners(selectedConversations);
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAllConversations() {
|
public void deleteAllConversations() {
|
||||||
DatabaseFactory.getSmsDatabase(context).deleteAllThreads();
|
DatabaseFactory.getSmsDatabase(context).deleteAllThreads();
|
||||||
DatabaseFactory.getMmsDatabase(context).deleteAllThreads();
|
DatabaseFactory.getMmsDatabase(context).deleteAllThreads();
|
||||||
deleteAllThreads();
|
deleteAllThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getThreadIdIfExistsFor(Recipients recipients) {
|
public long getThreadIdIfExistsFor(Recipients recipients) {
|
||||||
@ -224,10 +224,10 @@ public class ThreadDatabase extends Database {
|
|||||||
String where = RECIPIENT_IDS + " = ?";
|
String where = RECIPIENT_IDS + " = ?";
|
||||||
String[] recipientsArg = new String[] {recipientsList};
|
String[] recipientsArg = new String[] {recipientsList};
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
|
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst())
|
if (cursor != null && cursor.moveToFirst())
|
||||||
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
||||||
else
|
else
|
||||||
@ -237,7 +237,7 @@ public class ThreadDatabase extends Database {
|
|||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getThreadIdFor(Recipients recipients) {
|
public long getThreadIdFor(Recipients recipients) {
|
||||||
long[] recipientIds = getRecipientIds(recipients);
|
long[] recipientIds = getRecipientIds(recipients);
|
||||||
String recipientsList = getRecipientsAsString(recipientIds);
|
String recipientsList = getRecipientsAsString(recipientIds);
|
||||||
@ -245,10 +245,10 @@ public class ThreadDatabase extends Database {
|
|||||||
String where = RECIPIENT_IDS + " = ?";
|
String where = RECIPIENT_IDS + " = ?";
|
||||||
String[] recipientsArg = new String[] {recipientsList};
|
String[] recipientsArg = new String[] {recipientsList};
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
|
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst())
|
if (cursor != null && cursor.moveToFirst())
|
||||||
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
||||||
else
|
else
|
||||||
@ -258,24 +258,24 @@ public class ThreadDatabase extends Database {
|
|||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(long threadId) {
|
public void update(long threadId) {
|
||||||
MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context);
|
MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context);
|
||||||
long count = mmsSmsDatabase.getConversationCount(threadId);
|
long count = mmsSmsDatabase.getConversationCount(threadId);
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
deleteThread(threadId);
|
deleteThread(threadId);
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = mmsSmsDatabase.getConversationSnippet(threadId);
|
cursor = mmsSmsDatabase.getConversationSnippet(threadId);
|
||||||
if (cursor != null && cursor.moveToFirst())
|
if (cursor != null && cursor.moveToFirst())
|
||||||
updateThread(threadId, count,
|
updateThread(threadId, count,
|
||||||
cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY)),
|
cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY)),
|
||||||
cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.DATE)));
|
cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.DATE)));
|
||||||
else
|
else
|
||||||
deleteThread(threadId);
|
deleteThread(threadId);
|
||||||
@ -283,7 +283,7 @@ public class ThreadDatabase extends Database {
|
|||||||
if (cursor != null)
|
if (cursor != null)
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2011 Whisper Systems
|
* Copyright (C) 2011 Whisper Systems
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@ -10,48 +10,45 @@
|
|||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.thoughtcrime.securesms.sms;
|
package org.thoughtcrime.securesms.sms;
|
||||||
|
|
||||||
import java.io.IOException;
|
import android.util.Log;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.protocol.Message;
|
|
||||||
import org.thoughtcrime.securesms.protocol.Prefix;
|
|
||||||
import org.thoughtcrime.securesms.protocol.WirePrefix;
|
import org.thoughtcrime.securesms.protocol.WirePrefix;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.thoughtcrime.securesms.util.Base64;
|
||||||
import org.thoughtcrime.securesms.util.Conversions;
|
import org.thoughtcrime.securesms.util.Conversions;
|
||||||
import org.thoughtcrime.securesms.util.Hex;
|
import org.thoughtcrime.securesms.util.Hex;
|
||||||
|
|
||||||
import android.telephony.SmsManager;
|
import java.io.IOException;
|
||||||
import android.util.Log;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class MultipartMessageHandler {
|
public class MultipartMessageHandler {
|
||||||
|
|
||||||
private static final int VERSION_OFFSET = 0;
|
private static final int VERSION_OFFSET = 0;
|
||||||
private static final int MULTIPART_OFFSET = 1;
|
private static final int MULTIPART_OFFSET = 1;
|
||||||
private static final int IDENTIFIER_OFFSET = 2;
|
private static final int IDENTIFIER_OFFSET = 2;
|
||||||
|
|
||||||
private static final int MULTIPART_SUPPORTED_AFTER_VERSION = 1;
|
private static final int MULTIPART_SUPPORTED_AFTER_VERSION = 1;
|
||||||
|
|
||||||
private final HashMap<String, byte[][]> partialMessages = new HashMap<String, byte[][]>();
|
private final HashMap<String, byte[][]> partialMessages = new HashMap<String, byte[][]>();
|
||||||
private final HashMap<String, Integer> idMap = new HashMap<String, Integer>();
|
private final HashMap<String, Integer> idMap = new HashMap<String, Integer>();
|
||||||
|
|
||||||
private String spliceMessage(String prefix, byte[][] messageParts) {
|
private String spliceMessage(String prefix, byte[][] messageParts) {
|
||||||
Log.w("MultipartMessageHandler", "Have complete message fragments, splicing...");
|
Log.w("MultipartMessageHandler", "Have complete message fragments, splicing...");
|
||||||
int totalMessageLength = 0;
|
int totalMessageLength = 0;
|
||||||
|
|
||||||
for (int i=0;i<messageParts.length;i++) {
|
for (int i=0;i<messageParts.length;i++) {
|
||||||
totalMessageLength += messageParts[i].length;
|
totalMessageLength += messageParts[i].length;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] totalMessage = new byte[totalMessageLength];
|
byte[] totalMessage = new byte[totalMessageLength];
|
||||||
int totalMessageOffset = 0;
|
int totalMessageOffset = 0;
|
||||||
|
|
||||||
for (int i=0;i<messageParts.length;i++) {
|
for (int i=0;i<messageParts.length;i++) {
|
||||||
System.arraycopy(messageParts[i], 0, totalMessage, totalMessageOffset, messageParts[i].length);
|
System.arraycopy(messageParts[i], 0, totalMessage, totalMessageOffset, messageParts[i].length);
|
||||||
totalMessageOffset += messageParts[i].length;
|
totalMessageOffset += messageParts[i].length;
|
||||||
@ -59,21 +56,21 @@ public class MultipartMessageHandler {
|
|||||||
|
|
||||||
return prefix + Base64.encodeBytesWithoutPadding(totalMessage);
|
return prefix + Base64.encodeBytesWithoutPadding(totalMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isComplete(byte[][] partialMessages) {
|
private boolean isComplete(byte[][] partialMessages) {
|
||||||
for (int i=0;i<partialMessages.length;i++)
|
for (int i=0;i<partialMessages.length;i++)
|
||||||
if (partialMessages[i] == null) return false;
|
if (partialMessages[i] == null) return false;
|
||||||
|
|
||||||
Log.w("MultipartMessageHandler", "Buffer complete!");
|
Log.w("MultipartMessageHandler", "Buffer complete!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[][] findOrAllocateMultipartBuffer(String sender, int identifier, int count) {
|
private byte[][] findOrAllocateMultipartBuffer(String sender, int identifier, int count) {
|
||||||
String key = sender + identifier;
|
String key = sender + identifier;
|
||||||
|
|
||||||
Log.w("MultipartMessageHandler", "Getting multipart buffer...");
|
Log.w("MultipartMessageHandler", "Getting multipart buffer...");
|
||||||
|
|
||||||
if (partialMessages.containsKey(key)) {
|
if (partialMessages.containsKey(key)) {
|
||||||
Log.w("MultipartMessageHandler", "Returning existing multipart buffer...");
|
Log.w("MultipartMessageHandler", "Returning existing multipart buffer...");
|
||||||
return partialMessages.get(key);
|
return partialMessages.get(key);
|
||||||
@ -89,109 +86,109 @@ public class MultipartMessageHandler {
|
|||||||
byte[] strippedMessage = new byte[decodedMessage.length - (index == 0 ? 2 : 3)];
|
byte[] strippedMessage = new byte[decodedMessage.length - (index == 0 ? 2 : 3)];
|
||||||
int copyDestinationIndex = 0;
|
int copyDestinationIndex = 0;
|
||||||
int copyDestinationLength = strippedMessage.length;
|
int copyDestinationLength = strippedMessage.length;
|
||||||
|
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
strippedMessage[0] = decodedMessage[0];
|
strippedMessage[0] = decodedMessage[0];
|
||||||
copyDestinationIndex++;
|
copyDestinationIndex++;
|
||||||
copyDestinationLength--;
|
copyDestinationLength--;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.arraycopy(decodedMessage, 3, strippedMessage, copyDestinationIndex, copyDestinationLength);
|
System.arraycopy(decodedMessage, 3, strippedMessage, copyDestinationIndex, copyDestinationLength);
|
||||||
return strippedMessage;
|
return strippedMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String processMultipartMessage(String prefix, int index, int count, String sender, int identifier, byte[] decodedMessage) {
|
private String processMultipartMessage(String prefix, int index, int count, String sender, int identifier, byte[] decodedMessage) {
|
||||||
Log.w("MultipartMessageHandler", "Processing multipart message...");
|
Log.w("MultipartMessageHandler", "Processing multipart message...");
|
||||||
decodedMessage = stripMultipartTransportLayer(index, decodedMessage);
|
decodedMessage = stripMultipartTransportLayer(index, decodedMessage);
|
||||||
byte[][] messageParts = findOrAllocateMultipartBuffer(sender, identifier, count);
|
byte[][] messageParts = findOrAllocateMultipartBuffer(sender, identifier, count);
|
||||||
messageParts[index] = decodedMessage;
|
messageParts[index] = decodedMessage;
|
||||||
|
|
||||||
Log.w("MultipartMessageHandler", "Filled buffer at index: " + index);
|
Log.w("MultipartMessageHandler", "Filled buffer at index: " + index);
|
||||||
|
|
||||||
if (!isComplete(messageParts))
|
if (!isComplete(messageParts))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
partialMessages.remove(sender+identifier);
|
partialMessages.remove(sender+identifier);
|
||||||
return spliceMessage(prefix, messageParts);
|
return spliceMessage(prefix, messageParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String processSinglePartMessage(String prefix, byte[] decodedMessage) {
|
private String processSinglePartMessage(String prefix, byte[] decodedMessage) {
|
||||||
Log.w("MultipartMessageHandler", "Processing single part message...");
|
Log.w("MultipartMessageHandler", "Processing single part message...");
|
||||||
decodedMessage[MULTIPART_OFFSET] = decodedMessage[VERSION_OFFSET];
|
decodedMessage[MULTIPART_OFFSET] = decodedMessage[VERSION_OFFSET];
|
||||||
return prefix + Base64.encodeBytesWithoutPadding(decodedMessage, 1, decodedMessage.length-1);
|
return prefix + Base64.encodeBytesWithoutPadding(decodedMessage, 1, decodedMessage.length-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String processPotentialMultipartMessage(String prefix, String sender, String message) {
|
public String processPotentialMultipartMessage(String prefix, String sender, String message) {
|
||||||
try {
|
try {
|
||||||
byte[] decodedMessage = Base64.decodeWithoutPadding(message);
|
byte[] decodedMessage = Base64.decodeWithoutPadding(message);
|
||||||
int currentVersion = Conversions.highBitsToInt(decodedMessage[VERSION_OFFSET]);
|
int currentVersion = Conversions.highBitsToInt(decodedMessage[VERSION_OFFSET]);
|
||||||
|
|
||||||
Log.w("MultipartMessageHandler", "Decoded message with version: " + currentVersion);
|
Log.w("MultipartMessageHandler", "Decoded message with version: " + currentVersion);
|
||||||
Log.w("MultipartMessageHandler", "Decoded message: " + Hex.toString(decodedMessage));
|
Log.w("MultipartMessageHandler", "Decoded message: " + Hex.toString(decodedMessage));
|
||||||
|
|
||||||
if (currentVersion < MULTIPART_SUPPORTED_AFTER_VERSION)
|
if (currentVersion < MULTIPART_SUPPORTED_AFTER_VERSION)
|
||||||
throw new AssertionError("Caller should have checked this.");
|
throw new AssertionError("Caller should have checked this.");
|
||||||
|
|
||||||
int multipartIndex = Conversions.highBitsToInt(decodedMessage[MULTIPART_OFFSET]);
|
int multipartIndex = Conversions.highBitsToInt(decodedMessage[MULTIPART_OFFSET]);
|
||||||
int multipartCount = Conversions.lowBitsToInt(decodedMessage[MULTIPART_OFFSET]);
|
int multipartCount = Conversions.lowBitsToInt(decodedMessage[MULTIPART_OFFSET]);
|
||||||
int identifier = decodedMessage[IDENTIFIER_OFFSET] & 0xFF;
|
int identifier = decodedMessage[IDENTIFIER_OFFSET] & 0xFF;
|
||||||
|
|
||||||
Log.w("MultipartMessageHandler", "Multipart Info: (" + multipartIndex + "/" + multipartCount + ") ID: " + identifier);
|
Log.w("MultipartMessageHandler", "Multipart Info: (" + multipartIndex + "/" + multipartCount + ") ID: " + identifier);
|
||||||
|
|
||||||
if (multipartIndex >= multipartCount)
|
if (multipartIndex >= multipartCount)
|
||||||
return message;
|
return message;
|
||||||
|
|
||||||
if (multipartCount == 1) return processSinglePartMessage(prefix, decodedMessage);
|
if (multipartCount == 1) return processSinglePartMessage(prefix, decodedMessage);
|
||||||
else return processMultipartMessage(prefix, multipartIndex, multipartCount, sender, identifier, decodedMessage);
|
else return processMultipartMessage(prefix, multipartIndex, multipartCount, sender, identifier, decodedMessage);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<String> buildSingleMessage(byte[] decodedMessage, WirePrefix prefix) {
|
private ArrayList<String> buildSingleMessage(byte[] decodedMessage, WirePrefix prefix) {
|
||||||
Log.w("MultipartMessageHandler", "Adding transport info to single-part message...");
|
Log.w("MultipartMessageHandler", "Adding transport info to single-part message...");
|
||||||
|
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
byte[] messageWithMultipartHeader = new byte[decodedMessage.length + 1];
|
byte[] messageWithMultipartHeader = new byte[decodedMessage.length + 1];
|
||||||
System.arraycopy(decodedMessage, 0, messageWithMultipartHeader, 1, decodedMessage.length);
|
System.arraycopy(decodedMessage, 0, messageWithMultipartHeader, 1, decodedMessage.length);
|
||||||
|
|
||||||
messageWithMultipartHeader[0] = decodedMessage[0];
|
messageWithMultipartHeader[0] = decodedMessage[0];
|
||||||
messageWithMultipartHeader[1] = Conversions.intsToByteHighAndLow(0, 1);
|
messageWithMultipartHeader[1] = Conversions.intsToByteHighAndLow(0, 1);
|
||||||
String encodedMessage = Base64.encodeBytesWithoutPadding(messageWithMultipartHeader);
|
String encodedMessage = Base64.encodeBytesWithoutPadding(messageWithMultipartHeader);
|
||||||
|
|
||||||
list.add(prefix.calculatePrefix(encodedMessage) + encodedMessage);
|
list.add(prefix.calculatePrefix(encodedMessage) + encodedMessage);
|
||||||
Log.w("MultipartMessageHandler", "Complete fragment size: " + list.get(list.size()-1).length());
|
Log.w("MultipartMessageHandler", "Complete fragment size: " + list.get(list.size()-1).length());
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte getIdForRecipient(String recipient) {
|
private byte getIdForRecipient(String recipient) {
|
||||||
Integer currentId;
|
Integer currentId;
|
||||||
|
|
||||||
if (idMap.containsKey(recipient)) {
|
if (idMap.containsKey(recipient)) {
|
||||||
currentId = idMap.get(recipient);
|
currentId = idMap.get(recipient);
|
||||||
idMap.remove(recipient);
|
idMap.remove(recipient);
|
||||||
} else {
|
} else {
|
||||||
currentId = new Integer(0);
|
currentId = Integer.valueOf(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte id = currentId.byteValue();
|
byte id = currentId.byteValue();
|
||||||
idMap.put(recipient, new Integer((currentId.intValue() + 1) % 255));
|
idMap.put(recipient, Integer.valueOf((currentId.intValue() + 1) % 255));
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<String> buildMultipartMessage(String recipient, byte[] decodedMessage, WirePrefix prefix) {
|
private ArrayList<String> buildMultipartMessage(String recipient, byte[] decodedMessage, WirePrefix prefix) {
|
||||||
Log.w("MultipartMessageHandler", "Building multipart message...");
|
Log.w("MultipartMessageHandler", "Building multipart message...");
|
||||||
|
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
byte versionByte = decodedMessage[0];
|
byte versionByte = decodedMessage[0];
|
||||||
int messageOffset = 1;
|
int messageOffset = 1;
|
||||||
int segmentIndex = 0;
|
int segmentIndex = 0;
|
||||||
int segmentCount = SmsTransportDetails.getMessageCountForBytes(decodedMessage.length);
|
int segmentCount = SmsTransportDetails.getMessageCountForBytes(decodedMessage.length);
|
||||||
byte id = getIdForRecipient(recipient);
|
byte id = getIdForRecipient(recipient);
|
||||||
|
|
||||||
while (messageOffset < decodedMessage.length-1) {
|
while (messageOffset < decodedMessage.length-1) {
|
||||||
int segmentSize = Math.min(SmsTransportDetails.BASE_MAX_BYTES, decodedMessage.length-messageOffset+3);
|
int segmentSize = Math.min(SmsTransportDetails.BASE_MAX_BYTES, decodedMessage.length-messageOffset+3);
|
||||||
byte[] segment = new byte[segmentSize];
|
byte[] segment = new byte[segmentSize];
|
||||||
@ -200,35 +197,35 @@ public class MultipartMessageHandler {
|
|||||||
segment[2] = id;
|
segment[2] = id;
|
||||||
|
|
||||||
Log.w("MultipartMessageHandler", "Fragment: (" + segmentIndex + "/" + segmentCount +") -- ID: " + id);
|
Log.w("MultipartMessageHandler", "Fragment: (" + segmentIndex + "/" + segmentCount +") -- ID: " + id);
|
||||||
|
|
||||||
System.arraycopy(decodedMessage, messageOffset, segment, 3, segmentSize-3);
|
System.arraycopy(decodedMessage, messageOffset, segment, 3, segmentSize-3);
|
||||||
messageOffset += segmentSize-3;
|
messageOffset += segmentSize-3;
|
||||||
|
|
||||||
String encodedSegment = Base64.encodeBytesWithoutPadding(segment);
|
String encodedSegment = Base64.encodeBytesWithoutPadding(segment);
|
||||||
list.add(prefix.calculatePrefix(encodedSegment) + encodedSegment);
|
list.add(prefix.calculatePrefix(encodedSegment) + encodedSegment);
|
||||||
|
|
||||||
Log.w("MultipartMessageHandler", "Complete fragment size: " + list.get(list.size()-1).length());
|
Log.w("MultipartMessageHandler", "Complete fragment size: " + list.get(list.size()-1).length());
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isManualTransport(String message) {
|
public boolean isManualTransport(String message) {
|
||||||
try {
|
try {
|
||||||
byte[] decodedMessage = Base64.decodeWithoutPadding(message);
|
byte[] decodedMessage = Base64.decodeWithoutPadding(message);
|
||||||
return Conversions.highBitsToInt(decodedMessage[0]) >= MULTIPART_SUPPORTED_AFTER_VERSION;
|
return Conversions.highBitsToInt(decodedMessage[0]) >= MULTIPART_SUPPORTED_AFTER_VERSION;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new AssertionError(ioe);
|
throw new AssertionError(ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> divideMessage(String recipient, String message, WirePrefix prefix) {
|
public ArrayList<String> divideMessage(String recipient, String message, WirePrefix prefix) {
|
||||||
try {
|
try {
|
||||||
byte[] decodedMessage = Base64.decodeWithoutPadding(message);
|
byte[] decodedMessage = Base64.decodeWithoutPadding(message);
|
||||||
|
|
||||||
if (decodedMessage.length <= SmsTransportDetails.SINGLE_MESSAGE_MAX_BYTES)
|
if (decodedMessage.length <= SmsTransportDetails.SINGLE_MESSAGE_MAX_BYTES)
|
||||||
return buildSingleMessage(decodedMessage, prefix);
|
return buildSingleMessage(decodedMessage, prefix);
|
||||||
else
|
else
|
||||||
return buildMultipartMessage(recipient, decodedMessage, prefix);
|
return buildMultipartMessage(recipient, decodedMessage, prefix);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new AssertionError(ioe);
|
throw new AssertionError(ioe);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user