parent
012093a20d
commit
ea130cece2
Binary file not shown.
@ -0,0 +1,29 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<Objective-C-extensions>
|
||||
<file>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||
</file>
|
||||
<class>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||
</class>
|
||||
<extensions>
|
||||
<pair source="cpp" header="h" fileNamingConvention="NONE" />
|
||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
||||
</extensions>
|
||||
</Objective-C-extensions>
|
||||
</code_scheme>
|
||||
</component>
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
@ -1,3 +0,0 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,308 @@
|
||||
package eu.droogers.smsmatrix;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Log;
|
||||
|
||||
import static eu.droogers.smsmatrix.DatabaseContract.SmsEntry;
|
||||
import static eu.droogers.smsmatrix.DatabaseContract.MmsEntry;
|
||||
|
||||
public class DataManager {
|
||||
|
||||
private static DataManager ourInsance = null;
|
||||
private static final String LOG_TAG = "UntidyLamp.DataManager";
|
||||
public static final String[] ALLColumns = new String[] { "*" };
|
||||
public static final String unread = "locked=0 AND read=0";
|
||||
public static final String mmsTrIdError = "locked=1 AND read=0 AND error_code=1 AND mms_id=0";
|
||||
//final String[] whatColumns = {SmsEntry.COLUMN_ADDRESS};
|
||||
public static final int TYPE_RECIEVED = 2; //2 is recieved (1 is sent)
|
||||
public static final int NOT_READ = 0; //messages has not been read yet
|
||||
public static final int IS_READ = 1; //message has been read
|
||||
public static final int NO_STATUS = -1; //No status yet
|
||||
public static final int NOT_LOCKED = 0; //its not locked
|
||||
public static final int LOCKED = 1; //its locked
|
||||
public static final int ERROR_NO = 0; //no error yet
|
||||
public static final int ERROR_onUnexpectedError = 1;
|
||||
public static final int ERROR_onMatrixError = 2;
|
||||
public static final int ERROR_onNetworkError = 3;
|
||||
|
||||
public static final int MMS_TR_ID_ERROR = 1; // cant find tr_id from onRecieve in mmssms.db
|
||||
|
||||
public static DataManager getInstance() {
|
||||
if(ourInsance == null) {
|
||||
ourInsance = new DataManager();
|
||||
}
|
||||
return ourInsance;
|
||||
}
|
||||
|
||||
public static int dumpSmses(OpenHelper dbHelper) {
|
||||
Log.i(LOG_TAG, "dumpSmses");
|
||||
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
||||
Cursor smsQueryCursor = db.query(DatabaseContract.SmsEntry.TABLE_NAME, ALLColumns, null, null, null, null, null);
|
||||
Log.i(LOG_TAG, "Heres what's in the cursor " + DatabaseUtils.dumpCursorToString(smsQueryCursor) );
|
||||
int smsesCount = smsQueryCursor.getCount();
|
||||
smsQueryCursor.close();
|
||||
Log.i(LOG_TAG, "dumpSmses is done");
|
||||
return smsesCount;
|
||||
}
|
||||
|
||||
|
||||
public static boolean markSmsRead(OpenHelper dbHelper, int smsId) {
|
||||
Log.i(LOG_TAG, "markSmsRead called");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SmsEntry.COLUMN_READ, IS_READ);
|
||||
try {
|
||||
db.update(DatabaseContract.SmsEntry.TABLE_NAME, values, "_id=" + smsId, null );
|
||||
db.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "markSmsRead failed " + e );
|
||||
db.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean lockSms(OpenHelper dbHelper, int smsId) {
|
||||
Log.i(LOG_TAG, "lockSms called");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SmsEntry.COLUMN_LOCKED, LOCKED);
|
||||
try {
|
||||
db.update(DatabaseContract.SmsEntry.TABLE_NAME, values, "_id=" + smsId, null );
|
||||
db.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "lockSms failed " + e );
|
||||
db.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean unlockSms(OpenHelper dbHelper, int smsId) {
|
||||
Log.i(LOG_TAG, "unlockSms called");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SmsEntry.COLUMN_LOCKED, NOT_LOCKED);
|
||||
try {
|
||||
db.update(DatabaseContract.SmsEntry.TABLE_NAME, values, "_id=" + smsId, null );
|
||||
db.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "unlockSms failed " + e );
|
||||
db.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean errorSms(OpenHelper dbHelper, int smsId, int error) {
|
||||
Log.i(LOG_TAG, "errorSms called");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SmsEntry.COLUMN_ERROR_CODE, error);
|
||||
try {
|
||||
db.update(DatabaseContract.SmsEntry.TABLE_NAME, values, "_id=" + smsId, null );
|
||||
db.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "errorSms failed " + e );
|
||||
db.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int dumpMmses(OpenHelper dbHelper) {
|
||||
Log.i(LOG_TAG, "dumpMmses");
|
||||
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
||||
Cursor mmsQueryCursor = db.query(DatabaseContract.MmsEntry.TABLE_NAME, ALLColumns, null, null, null, null, null);
|
||||
Log.i(LOG_TAG, "Heres what's in the cursor " + DatabaseUtils.dumpCursorToString(mmsQueryCursor) );
|
||||
int mmsesCount = mmsQueryCursor.getCount();
|
||||
mmsQueryCursor.close();
|
||||
db.close();
|
||||
Log.i(LOG_TAG, "dumpMmses is done");
|
||||
return mmsesCount;
|
||||
}
|
||||
|
||||
|
||||
public static boolean markMmsRead(OpenHelper dbHelper, int mmsId) {
|
||||
Log.i(LOG_TAG, "markMmsRead called");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MmsEntry.COLUMN_READ, IS_READ);
|
||||
try {
|
||||
db.update(DatabaseContract.MmsEntry.TABLE_NAME, values, "_id=" + mmsId, null );
|
||||
db.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "markMmsRead failed " + e );
|
||||
db.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean lockMms(OpenHelper dbHelper, int mmsId) {
|
||||
Log.i(LOG_TAG, "lockMms called");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MmsEntry.COLUMN_LOCKED, LOCKED);
|
||||
try {
|
||||
db.update(DatabaseContract.MmsEntry.TABLE_NAME, values, "_id=" + mmsId, null );
|
||||
db.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "lockMms failed " + e );
|
||||
db.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean unlockMms(OpenHelper dbHelper, int mmsId) {
|
||||
Log.i(LOG_TAG, "unlockMms called");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MmsEntry.COLUMN_LOCKED, NOT_LOCKED);
|
||||
try {
|
||||
db.update(DatabaseContract.MmsEntry.TABLE_NAME, values, "_id=" + mmsId, null );
|
||||
db.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "unlockMms failed " + e );
|
||||
db.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean errorMms(OpenHelper dbHelper, int mmsId, int error) {
|
||||
Log.i(LOG_TAG, "errorMms called");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MmsEntry.COLUMN_ERROR_CODE, error);
|
||||
try {
|
||||
db.update(DatabaseContract.MmsEntry.TABLE_NAME, values, "_id=" + mmsId, null );
|
||||
db.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "errorMms failed " + e );
|
||||
db.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static int countSmses(OpenHelper dbHelper) {
|
||||
Log.i(LOG_TAG, "countSmses");
|
||||
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
||||
Cursor countSmsesCursor = db.query(DatabaseContract.SmsEntry.TABLE_NAME, ALLColumns, null, null, null, null, null);
|
||||
int smsesCount = countSmsesCursor.getCount();
|
||||
countSmsesCursor.close();
|
||||
db.close();
|
||||
Log.i(LOG_TAG, "countSmses is done");
|
||||
return smsesCount;
|
||||
}
|
||||
|
||||
public static int countMmses(OpenHelper dbHelper) {
|
||||
Log.i(LOG_TAG, "countMmses");
|
||||
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
||||
Cursor countMmsesCursor = db.query(DatabaseContract.MmsEntry.TABLE_NAME, ALLColumns, null, null, null, null, null);
|
||||
int mmsesCount = countMmsesCursor.getCount();
|
||||
countMmsesCursor.close();
|
||||
db.close();
|
||||
Log.i(LOG_TAG, "countMmses is done");
|
||||
return mmsesCount;
|
||||
}
|
||||
|
||||
public static long importSms(OpenHelper dbHelper, String address, long date, long dateSent, int read, int type, int status, String body, int locked, int errorCode) {
|
||||
Log.i(LOG_TAG, "importSms");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_ADDRESS, address);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_DATE, date);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_DATE_SENT, dateSent);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_READ, read);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_STATUS, status);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_TYPE, type);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_BODY, body);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_LOCKED, locked);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_ERROR_CODE, errorCode);
|
||||
try {
|
||||
long smsImportRowId = db.insert(DatabaseContract.SmsEntry.TABLE_NAME, null, values);
|
||||
Log.i(LOG_TAG, "smsImportRowId " + smsImportRowId );
|
||||
db.close();
|
||||
return smsImportRowId;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "importSms failed " + e );
|
||||
db.close();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateLongSmsBody (OpenHelper dbHelper, long id, String body ){
|
||||
|
||||
Log.i(LOG_TAG, "updateLongSmsBody");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_BODY, body);
|
||||
|
||||
try {
|
||||
Log.i(LOG_TAG, " try updateLongSmsBody _id=" + id );
|
||||
db.update(DatabaseContract.SmsEntry.TABLE_NAME, values, "_id=" + id, null );
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "updateLongSmsBody failed " + e );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
|
||||
|
||||
public static long importMms(OpenHelper dbHelper, String tr_id, String address, long date, long dateSent, int read, int type, int mmsId, int status, String body, int locked, int errorCode) {
|
||||
Log.i(LOG_TAG, "importMms");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_TR_ID, tr_id);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_ADDRESS, address);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_DATE, date);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_DATE_SENT, dateSent);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_READ, read);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_STATUS, status);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_TYPE, type);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_MMS_ID, mmsId);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_BODY, body);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_LOCKED, locked);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_ERROR_CODE, errorCode);
|
||||
try {
|
||||
long mmsImportRowId = db.insert(DatabaseContract.MmsEntry.TABLE_NAME, null, values);
|
||||
Log.i(LOG_TAG, "smsImportRowId " + mmsImportRowId );
|
||||
db.close();
|
||||
return mmsImportRowId;
|
||||
} catch (Exception e) {
|
||||
db.close();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateFailedMms (OpenHelper dbHelper, int id, int mmsId, String body, int locked, int errorCode ){
|
||||
Log.i(LOG_TAG, "updateFailedMms");
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_MMS_ID, mmsId);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_BODY, body);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_LOCKED, locked);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_ERROR_CODE, errorCode);
|
||||
|
||||
try {
|
||||
Log.i(LOG_TAG, " try updateFailedMms _id=" + id );
|
||||
db.update(DatabaseContract.MmsEntry.TABLE_NAME, values, "_id=" + id, null );
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "updateFailedMms _id="+ id + " failed: " + e );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
|
||||
public static boolean deleteAll (OpenHelper dbHelper) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package eu.droogers.smsmatrix;
|
||||
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
public final class DatabaseContract {
|
||||
private DatabaseContract () {}
|
||||
|
||||
public static final class SmsEntry implements BaseColumns {
|
||||
public static final String TABLE_NAME = "sms";
|
||||
public static final String COLUMN_ADDRESS = "address";
|
||||
public static final String COLUMN_DATE = "date";
|
||||
public static final String COLUMN_DATE_SENT = "date_sent";
|
||||
public static final String COLUMN_READ = "read";
|
||||
public static final String COLUMN_STATUS = "status";
|
||||
public static final String COLUMN_TYPE = "type";
|
||||
public static final String COLUMN_BODY = "body";
|
||||
public static final String COLUMN_LOCKED = "locked";
|
||||
public static final String COLUMN_ERROR_CODE = "error_code";
|
||||
|
||||
public static final String SQL_CREATE_TABLE =
|
||||
"CREATE TABLE " + TABLE_NAME + " (" +
|
||||
_ID + " INTEGER PRIMARY KEY, " +
|
||||
COLUMN_ADDRESS + " TEXT NOT NULL, " +
|
||||
COLUMN_DATE + " INTEGER NOT NULL, " +
|
||||
COLUMN_DATE_SENT + " INTEGER NOT NULL, " +
|
||||
COLUMN_READ + " INTEGER NOT NULL, " +
|
||||
COLUMN_STATUS + " INTEGER NOT NULL, " +
|
||||
COLUMN_TYPE + " INTEGER NOT NULL, " +
|
||||
COLUMN_BODY + " TEXT NOT NULL, " +
|
||||
COLUMN_LOCKED + " INTEGER, " +
|
||||
COLUMN_ERROR_CODE + " INTEGER )";
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static final class MmsEntry implements BaseColumns {
|
||||
public static final String TABLE_NAME = "mms";
|
||||
public static final String COLUMN_TR_ID = "tr_id";
|
||||
public static final String COLUMN_ADDRESS = "address";
|
||||
public static final String COLUMN_DATE = "date";
|
||||
public static final String COLUMN_DATE_SENT = "date_sent";
|
||||
public static final String COLUMN_READ = "read";
|
||||
public static final String COLUMN_STATUS = "status";
|
||||
public static final String COLUMN_TYPE = "type";
|
||||
public static final String COLUMN_MMS_ID = "mms_id";
|
||||
public static final String COLUMN_BODY = "body";
|
||||
public static final String COLUMN_LOCKED = "locked";
|
||||
public static final String COLUMN_ERROR_CODE = "error_code";
|
||||
|
||||
public static final String SQL_CREATE_TABLE =
|
||||
"CREATE TABLE " + TABLE_NAME + " (" +
|
||||
_ID + " INTEGER PRIMARY KEY, " +
|
||||
COLUMN_TR_ID + " TEXT NOT NULL, " +
|
||||
COLUMN_ADDRESS + " TEXT NOT NULL, " +
|
||||
COLUMN_DATE + " INTEGER NOT NULL, " +
|
||||
COLUMN_DATE_SENT + " INTEGER NOT NULL, " +
|
||||
COLUMN_READ + " INTEGER NOT NULL, " +
|
||||
COLUMN_STATUS + " INTEGER NOT NULL, " +
|
||||
COLUMN_TYPE + " INTEGER NOT NULL, " +
|
||||
COLUMN_MMS_ID + " INTEGER NOT NULL, " +
|
||||
COLUMN_BODY + " TEXT, " +
|
||||
COLUMN_LOCKED + " INTEGER, " +
|
||||
COLUMN_ERROR_CODE + " INTEGER )";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package eu.droogers.smsmatrix;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.provider.ContactsContract;
|
||||
|
||||
|
||||
public class DatabaseDataWorker {
|
||||
private SQLiteDatabase mDb;
|
||||
public DatabaseDataWorker(SQLiteDatabase db) {
|
||||
mDb = db;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void insertSms(int address, int date, int dateSent, int read, int type, int status, String body, int locked, int errorCode) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_ADDRESS, address);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_DATE, date);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_DATE_SENT, dateSent);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_READ, read);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_STATUS, status);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_TYPE, type);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_BODY, body);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_LOCKED, locked);
|
||||
values.put(DatabaseContract.SmsEntry.COLUMN_ERROR_CODE, errorCode);
|
||||
|
||||
long newRowId = mDb.insert(DatabaseContract.SmsEntry.TABLE_NAME, null, values);
|
||||
}
|
||||
|
||||
private void insertMms(String tr_id, int address, int date, int dateSent, int read, int type, int mmsId, int status, String body, int locked, int errorCode) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_TR_ID, tr_id);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_ADDRESS, address);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_DATE, date);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_DATE_SENT, dateSent);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_READ, read);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_STATUS, status);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_TYPE, type);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_MMS_ID, mmsId);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_BODY, body);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_LOCKED, locked);
|
||||
values.put(DatabaseContract.MmsEntry.COLUMN_ERROR_CODE, errorCode);
|
||||
|
||||
long newRowId = mDb.insert(DatabaseContract.MmsEntry.TABLE_NAME, null, values);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,302 +0,0 @@
|
||||
package eu.droogers.smsmatrix;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.provider.Telephony;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class MMSMonitor {
|
||||
private MatrixService mainActivity;
|
||||
private ContentResolver contentResolver = null;
|
||||
private Context mainContext;
|
||||
private Handler mmshandler = null;
|
||||
private ContentObserver mmsObserver = null;
|
||||
public boolean monitorStatus = false;
|
||||
private int mmsCount = 0;
|
||||
private static final String TAG = "MMSMonitor";
|
||||
|
||||
public MMSMonitor(final MatrixService mainActivity, final Context mainContext) {
|
||||
this.mainActivity = mainActivity;
|
||||
contentResolver = mainActivity.getContentResolver();
|
||||
this.mainContext = mainContext;
|
||||
mmshandler = new MMSHandler();
|
||||
mmsObserver = new MMSObserver(mmshandler);
|
||||
Log.i(TAG, "***** Start MMS Monitor *****");
|
||||
}
|
||||
|
||||
|
||||
public void startMMSMonitoring() {
|
||||
try {
|
||||
monitorStatus = false;
|
||||
if (!monitorStatus) {
|
||||
contentResolver.registerContentObserver(
|
||||
Uri.parse("content://mms"),
|
||||
true,
|
||||
mmsObserver
|
||||
);
|
||||
|
||||
// Save the count of MMS messages on start-up.
|
||||
Uri uriMMSURI = Uri.parse("content://mms-sms");
|
||||
Cursor mmsCur = mainActivity.getContentResolver().query(
|
||||
uriMMSURI,
|
||||
null,
|
||||
Telephony.Mms.MESSAGE_BOX + " = " + Telephony.Mms.MESSAGE_BOX_INBOX,
|
||||
null,
|
||||
Telephony.Mms._ID
|
||||
);
|
||||
if (mmsCur != null && mmsCur.getCount() > 0) {
|
||||
mmsCount = mmsCur.getCount();
|
||||
Log.d(TAG, "Init MMSCount = " + mmsCount);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void stopMMSMonitoring() {
|
||||
try {
|
||||
monitorStatus = false;
|
||||
if (!monitorStatus){
|
||||
contentResolver.unregisterContentObserver(mmsObserver);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MMSHandler extends Handler {
|
||||
public void handleMessage(final Message msg) {
|
||||
//Log.i(TAG, "Handler");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MMSObserver extends ContentObserver {
|
||||
private Handler mms_handle = null;
|
||||
public MMSObserver(final Handler mmshandle) {
|
||||
super(mmshandle);
|
||||
mms_handle = mmshandle;
|
||||
}
|
||||
|
||||
public void onChange(final boolean bSelfChange) {
|
||||
super.onChange(bSelfChange);
|
||||
Log.i(TAG, "Onchange");
|
||||
|
||||
try {
|
||||
monitorStatus = true;
|
||||
|
||||
// Send message to Activity.
|
||||
Message msg = new Message();
|
||||
mms_handle.sendMessage(msg);
|
||||
|
||||
// Get the MMS count.
|
||||
Uri uriMMSURI = Uri.parse("content://mms/");
|
||||
Cursor mmsCur = mainActivity.getContentResolver().query(
|
||||
uriMMSURI,
|
||||
null,
|
||||
Telephony.Mms.MESSAGE_BOX + " = " + Telephony.Mms.MESSAGE_BOX_INBOX,
|
||||
null,
|
||||
Telephony.Mms._ID
|
||||
);
|
||||
|
||||
int currMMSCount = 0;
|
||||
if (mmsCur != null && mmsCur.getCount() > 0) {
|
||||
currMMSCount = mmsCur.getCount();
|
||||
}
|
||||
|
||||
// Proceed if there is a new message.
|
||||
if (currMMSCount > mmsCount) {
|
||||
mmsCount = currMMSCount;
|
||||
mmsCur.moveToLast();
|
||||
|
||||
// Get the message id and subject.
|
||||
String subject = mmsCur.getString(mmsCur.getColumnIndex(Telephony.Mms.SUBJECT));
|
||||
int id = Integer.parseInt(mmsCur.getString(mmsCur.getColumnIndex(Telephony.Mms._ID)));
|
||||
Log.d(TAG, "_id = " + id);
|
||||
Log.d(TAG, "Subject = " + subject);
|
||||
|
||||
byte[] mediaData = null;
|
||||
String message = "";
|
||||
String address = "";
|
||||
String fileName = "";
|
||||
String fileType = "";
|
||||
String messageType = "";
|
||||
|
||||
// Get parts.
|
||||
Uri uriMMSPart = Uri.parse("content://mms/part");
|
||||
Cursor curPart = mainActivity.getContentResolver().query(
|
||||
uriMMSPart,
|
||||
null,
|
||||
Telephony.Mms.Part.MSG_ID + " = " + id,
|
||||
null,
|
||||
Telephony.Mms.Part._ID
|
||||
);
|
||||
Log.d(TAG, "Parts records length = " + curPart.getCount());
|
||||
curPart.moveToLast();
|
||||
do {
|
||||
String contentType = curPart.getString(curPart.getColumnIndex(Telephony.Mms.Part.CONTENT_TYPE));
|
||||
String partId = curPart.getString(curPart.getColumnIndex(Telephony.Mms.Part._ID));
|
||||
fileName = curPart.getString(curPart.getColumnIndex(Telephony.Mms.Part.NAME));
|
||||
Log.d(TAG, "partId = " + partId);
|
||||
Log.d(TAG, "Part mime type = " + contentType);
|
||||
|
||||
if (contentType.equalsIgnoreCase("text/plain"))
|
||||
{
|
||||
// Get the message.
|
||||
|
||||
Log.i(TAG,"==== Get the message start ====");
|
||||
messageType = Matrix.MESSAGE_TYPE_TEXT;
|
||||
byte[] messageData = readMMSPart(partId);
|
||||
if (messageData != null && messageData.length > 0) {
|
||||
message = new String(messageData);
|
||||
}
|
||||
|
||||
if (message.isEmpty()) {
|
||||
Cursor curPart1 = mainActivity.getContentResolver().query(
|
||||
uriMMSPart,
|
||||
null,
|
||||
Telephony.Mms.Part.MSG_ID + " = " + id + " and "+ Telephony.Mms.Part._ID + " = " + partId,
|
||||
null,
|
||||
Telephony.Mms.Part._ID
|
||||
);
|
||||
for (int i = 0; i < curPart1.getColumnCount(); i++)
|
||||
{
|
||||
Log.d(TAG,"Column Name : " + curPart1.getColumnName(i));
|
||||
}
|
||||
curPart1.moveToLast();
|
||||
message = curPart1.getString(13);
|
||||
}
|
||||
Log.d(TAG,"Txt Message = " + message);
|
||||
} else if (isImageType(contentType) || isVideoType(contentType)) {
|
||||
// Get the media.
|
||||
|
||||
if (isImageType(contentType)) {
|
||||
messageType = Matrix.MESSAGE_TYPE_IMAGE;
|
||||
} else if (isVideoType(contentType)) {
|
||||
messageType = Matrix.MESSAGE_TYPE_VIDEO;
|
||||
}
|
||||
Log.i(TAG, "==== Get the media start ====");
|
||||
fileType = contentType;
|
||||
mediaData = readMMSPart(partId);
|
||||
Log.i(TAG, "Media data length == " + mediaData.length);
|
||||
}
|
||||
} while (curPart.moveToPrevious());
|
||||
|
||||
|
||||
|
||||
// Get the sender's address.
|
||||
Uri uriMMSAddr = Uri.parse("content://mms/" + id + "/addr");
|
||||
Cursor addrCur = mainActivity.getContentResolver().query(
|
||||
uriMMSAddr,
|
||||
null,
|
||||
Telephony.Mms.Addr.TYPE + " = 137", // PduHeaders.FROM
|
||||
null,
|
||||
Telephony.Mms.Addr._ID
|
||||
);
|
||||
if (addrCur != null) {
|
||||
addrCur.moveToLast();
|
||||
do{
|
||||
Log.d(TAG, "addrCur records length = " + addrCur.getCount());
|
||||
if (addrCur.getCount() > 0) {
|
||||
address = addrCur.getString(addrCur.getColumnIndex(Telephony.Mms.Addr.ADDRESS));
|
||||
}
|
||||
Log.d(TAG, "address = " + address);
|
||||
|
||||
if (!message.isEmpty()) {
|
||||
Utilities.sendMatrix(mainActivity, message, address, messageType);
|
||||
}
|
||||
if (mediaData != null) {
|
||||
Utilities.sendMatrix(
|
||||
mainActivity,
|
||||
mediaData,
|
||||
address,
|
||||
messageType,
|
||||
fileName,
|
||||
fileType
|
||||
);
|
||||
}
|
||||
} while (addrCur.moveToPrevious());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private byte[] readMMSPart(String partId) {
|
||||
byte[] partData = null;
|
||||
Uri partURI = Uri.parse("content://mms/part/" + partId);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
InputStream is = null;
|
||||
|
||||
try {
|
||||
|
||||
Log.i(TAG,"Entered into readMMSPart try.");
|
||||
ContentResolver mContentResolver = mainActivity.getContentResolver();
|
||||
is = mContentResolver.openInputStream(partURI);
|
||||
|
||||
byte[] buffer = new byte[256];
|
||||
int len = is.read(buffer);
|
||||
while (len >= 0) {
|
||||
baos.write(buffer, 0, len);
|
||||
len = is.read(buffer);
|
||||
}
|
||||
partData = baos.toByteArray();
|
||||
//Log.i(TAG, "Text Msg :: " + new String(partData));
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Exception == Failed to load part data");
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Exception :: Failed to close stream");
|
||||
}
|
||||
}
|
||||
}
|
||||
return partData;
|
||||
}
|
||||
|
||||
|
||||
private boolean isImageType(String mime) {
|
||||
boolean result = false;
|
||||
if (mime.equalsIgnoreCase("image/jpg")
|
||||
|| mime.equalsIgnoreCase("image/jpeg")
|
||||
|| mime.equalsIgnoreCase("image/png")
|
||||
|| mime.equalsIgnoreCase("image/gif")
|
||||
|| mime.equalsIgnoreCase("image/bmp")) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private boolean isVideoType(String mime) {
|
||||
boolean result = false;
|
||||
if (mime.equalsIgnoreCase("video/3gpp")
|
||||
|| mime.equalsIgnoreCase("video/3gpp2")
|
||||
|| mime.equalsIgnoreCase("video/avi")
|
||||
|| mime.equalsIgnoreCase("video/mp4")
|
||||
|| mime.equalsIgnoreCase("video/mpeg")
|
||||
|| mime.equalsIgnoreCase("video/webm")) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package eu.droogers.smsmatrix;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
public class OpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
public static final String DATABASE_NAME = "SmsMatrix.db";
|
||||
public static final int DATABASE_VERSION = 1;
|
||||
public OpenHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(DatabaseContract.SmsEntry.SQL_CREATE_TABLE);
|
||||
db.execSQL(DatabaseContract.MmsEntry.SQL_CREATE_TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package eu.droogers.smsmatrix;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class Utilities {
|
||||
public static void sendMatrix(Context context, String body, String phone, String type) {
|
||||
Intent intent = new Intent(context, MatrixService.class);
|
||||
intent.putExtra("SendSms_phone", phone);
|
||||
intent.putExtra("SendSms_body", body);
|
||||
intent.putExtra("SendSms_type", type);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
public static void sendMatrix(Context context, byte[] body, String phone, String type, String fileName, String contentType) {
|
||||
Intent intent = new Intent(context, MatrixService.class);
|
||||
intent.putExtra("SendSms_phone", phone);
|
||||
intent.putExtra("SendSms_body", body);
|
||||
intent.putExtra("SendSms_type", type);
|
||||
intent.putExtra("SendSms_fileName", fileName);
|
||||
intent.putExtra("SendSms_contentType", contentType);
|
||||
context.startService(intent);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue