From 7f2214772a506fd416c6f28385ac4c86e87c8bef Mon Sep 17 00:00:00 2001 From: xLaMbChOpSx Date: Sat, 7 Jun 2014 19:06:49 +1000 Subject: [PATCH] Silent Sms Detection (Class 0), Database Restore, Progress Bar Sms Receiver will monitor for Class 0 messages and provide an alert when received, details are tracked to a database table and displayed in a notification fragment. Restore database tables using exported CSV files this will also be added into the Db Adapter shortly to allow data to persist across database updates. Database retore added to the RequestTask class so it can be executed in the background. Progress bar added to provide more feedback about background operations. --- app/src/main/AndroidManifest.xml | 113 ++++++------- .../java/com/SecUpwN/AIMSICD/AIMSICD.java | 104 +++++++++--- .../AIMSICD/adapters/AIMSICDDbAdapter.java | 149 ++++++++++++++++-- .../AIMSICD/adapters/SilentSmsCardData.java | 46 ++++++ .../adapters/SilentSmsCardInflater.java | 67 ++++++++ .../AIMSICD/fragments/DbViewerFragment.java | 21 +++ .../AIMSICD/fragments/SilentSmsFragment.java | 67 ++++++++ .../SecUpwN/AIMSICD/receiver/SmsReceiver.java | 51 ++++++ .../SamsungMulticlientRilExecutor.java | 1 + .../SecUpwN/AIMSICD/utils/RequestTask.java | 32 +++- .../main/res/drawable/progress_bar_states.xml | 43 +++++ app/src/main/res/layout/silent_sms_items.xml | 53 +++++++ app/src/main/res/layout/sms_fragment.xml | 33 ++++ app/src/main/res/layout/top.xml | 17 +- app/src/main/res/menu/main_menu.xml | 8 +- app/src/main/res/values/strings.xml | 8 +- 16 files changed, 710 insertions(+), 103 deletions(-) create mode 100644 app/src/main/java/com/SecUpwN/AIMSICD/adapters/SilentSmsCardData.java create mode 100644 app/src/main/java/com/SecUpwN/AIMSICD/adapters/SilentSmsCardInflater.java create mode 100644 app/src/main/java/com/SecUpwN/AIMSICD/fragments/SilentSmsFragment.java create mode 100644 app/src/main/java/com/SecUpwN/AIMSICD/receiver/SmsReceiver.java create mode 100644 app/src/main/res/drawable/progress_bar_states.xml create mode 100644 app/src/main/res/layout/silent_sms_items.xml create mode 100644 app/src/main/res/layout/sms_fragment.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9af8c432b..4d95ff389 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,81 +1,88 @@ + package="com.SecUpwN.AIMSICD" + android:versionCode="18" + android:versionName="0.1.18"> + android:glEsVersion="0x00020000" + android:required="true"/> - - - - - - - - - - + + + + + + + + + + + - + android:allowBackup="false" + android:icon="@drawable/sense_alarm" + android:label="@string/app_name" + android:theme="@style/AppTheme"> + + android:name="com.google.android.gms.version" + android:value="@integer/google_play_services_version"/> + android:name=".AIMSICD" + android:exported="true" + android:label="@string/app_name_short" + android:screenOrientation="portrait"> - - - + + + - - + + + android:name=".service.AimsicdService" + android:enabled="true" + android:exported="false"> - + - + + + + + - + + + + android:name=".activities.MapViewer" + android:exported="true" + android:label="@string/map_view" + android:parentActivityName=".AIMSICD"> + android:name="android.support.PARENT_ACTIVITY" + android:value=".AIMSICD"/> + android:name=".activities.PrefActivity" + android:exported="true" + android:icon="@drawable/ic_action_settings" + android:label="@string/preferences" + android:parentActivityName=".AIMSICD"> - + @@ -84,15 +91,15 @@ android:exported="true" android:icon="@drawable/ic_action_settings" android:label="@string/preferences" - android:parentActivityName=".AIMSICD" > + android:parentActivityName=".AIMSICD"> - + + android:name="com.google.android.maps.v2.API_KEY" + android:value="AIzaSyDI1lvgpBmNhQS33JfJA4w8GAmrtFeg078"/> diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java b/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java index 4f66689e6..025cfc114 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java @@ -18,10 +18,12 @@ package com.SecUpwN.AIMSICD; import android.app.AlertDialog; +import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; @@ -33,13 +35,14 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.telephony.TelephonyManager; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.widget.ProgressBar; import android.widget.Toast; import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter; @@ -50,8 +53,10 @@ import com.SecUpwN.AIMSICD.fragments.CellInfoFragment; import com.SecUpwN.AIMSICD.fragments.DbViewerFragment; import com.SecUpwN.AIMSICD.fragments.DeviceFragment; +import com.SecUpwN.AIMSICD.fragments.SilentSmsFragment; import com.SecUpwN.AIMSICD.service.AimsicdService; import com.SecUpwN.AIMSICD.utils.Helpers; +import com.SecUpwN.AIMSICD.utils.RequestTask; import java.util.ArrayList; import java.util.List; @@ -69,6 +74,13 @@ public class AIMSICD extends FragmentActivity { private AimsicdService mAimsicdService; + private FragmentManager fm; + private List mFragmentList; + private List titles; + + private FragmentStatePagerAdapter adapterViewPager; + public static ProgressBar mProgressBar; + //Back press to exit timer private long mLastPress = 0; @@ -85,11 +97,11 @@ public void onCreate(Bundle savedInstanceState) { //Start Service before binding to keep it resident when activity is destroyed startService(intent); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - - MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter( - getSupportFragmentManager()); + fm = getSupportFragmentManager(); + adapterViewPager = new MyPagerAdapter(fm); ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager); - viewPager.setAdapter(myFragmentPagerAdapter); + viewPager.setAdapter(adapterViewPager); + mProgressBar = (ProgressBar) findViewById(R.id.progressBar); prefs = mContext.getSharedPreferences( AimsicdService.SHARED_PREFERENCES_BASENAME, 0); @@ -128,6 +140,8 @@ public void onClick(DialogInterface dialog, int which) { //Create DB Instance dbHelper = new AIMSICDDbAdapter(mContext); + //Register receiver for Silent SMS Interception Notification + mContext.registerReceiver(mMessageReceiver, new IntentFilter(AimsicdService.SILENT_SMS)); } @Override @@ -139,12 +153,14 @@ protected void onDestroy() { mBound = false; } - final String KEY_KILL_SERVICE = mContext.getString(R.string.pref_persistservice_key); - boolean persistService = prefs.getBoolean(KEY_KILL_SERVICE, true); + final String PERSIST_SERVICE = mContext.getString(R.string.pref_persistservice_key); + boolean persistService = prefs.getBoolean(PERSIST_SERVICE, false); if (!persistService) { - Intent intent = new Intent(this, AimsicdService.class); + Intent intent = new Intent(mContext, AimsicdService.class); stopService(intent); } + + mContext.unregisterReceiver(mMessageReceiver); } /** @@ -238,9 +254,12 @@ public boolean onOptionsItemSelected(MenuItem item) { intent = new Intent(this, PrefActivity.class); startActivity(intent); return true; - case R.id.export_database: + case R.id.backup_database: dbHelper.exportDB(); return true; + case R.id.restore_database: + new RequestTask(mContext, RequestTask.RESTORE_DATABASE).execute(); + return true; case R.id.update_opencelldata: Location loc = mAimsicdService.lastKnownLocation(); if (loc != null) { @@ -305,28 +324,68 @@ private void trackFemtocell() { } } - class MyFragmentPagerAdapter extends FragmentPagerAdapter { - private final List fragments; - private final List titles; + private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final Bundle bundle = intent.getExtras(); + if (bundle != null) { + String originatingAddress = (bundle.getString("address") != null ? + "Originating Address: " + bundle.getString("address") + : "Originating Address: Unknown"); + String displayAddress = (bundle.getString("display_address") != null ? + "Display Address: " + bundle.getString("display_address") + : "Display Address: Unknown"); + String messageClass = (bundle.getString("class") != null ? + "Message Class: " + bundle.getString("class") + : "Message Class: Unknown"); + String serviceCentre = (bundle.getString("service_centre") != null ? + "Routing Service Centre: " + bundle.getString("service_centre") + : "Routing Service Centre: Unknown"); + String messageBody = (bundle.getString("message") != null ? + "Message: " + bundle.getString("message") : "Message: Unknown"); + int timestamp = bundle.getInt("timestamp"); + + Bundle smsCardBundle = new Bundle(); + smsCardBundle.putString("address", originatingAddress); + smsCardBundle.putString("display_address", displayAddress); + smsCardBundle.putString("message_class", messageClass); + smsCardBundle.putString("service_centre", serviceCentre); + smsCardBundle.putString("message", messageBody); + smsCardBundle.putInt("timestamp", timestamp); + dbHelper.open(); + dbHelper.insertSilentSms(smsCardBundle); + dbHelper.close(); + Fragment fragment = new SilentSmsFragment(); + //fragment.setArguments(smsCardBundle); + titles.add(getString(R.string.sms_title)); + mFragmentList.add(fragment); + adapterViewPager.notifyDataSetChanged(); + adapterViewPager.getItem(adapterViewPager.getCount()-1); + } + } + }; + + class MyPagerAdapter extends FragmentStatePagerAdapter { - public MyFragmentPagerAdapter(FragmentManager fm) { + public MyPagerAdapter(FragmentManager fm) { super(fm); - this.fragments = new ArrayList<>(); + mFragmentList = new ArrayList<>(); titles = new ArrayList<>(); - fragments.add(new DeviceFragment()); + mFragmentList.add(new DeviceFragment()); titles.add(getString(R.string.device_info)); - fragments.add(new CellInfoFragment()); + mFragmentList.add(new CellInfoFragment()); titles.add(getString(R.string.cell_info_title)); - fragments.add(new AtCommandFragment()); + mFragmentList.add(new AtCommandFragment()); titles.add(getString(R.string.at_command_title)); - fragments.add(new DbViewerFragment()); + mFragmentList.add(new DbViewerFragment()); titles.add(getString(R.string.db_viewer)); - fragments.add(new AboutFragment()); + mFragmentList.add(new AboutFragment()); titles.add(getString(R.string.about_aimsicd)); } + @Override public Fragment getItem(int position) { - return fragments.get(position); + return mFragmentList.get(position); } @Override @@ -334,9 +393,10 @@ public CharSequence getPageTitle(int position) { return titles.get(position); } - @Override + @Override public int getCount() { - return fragments.size(); + return mFragmentList.size(); } + } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java index f8c8d1ec1..e19af9ee4 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -1,6 +1,8 @@ package com.SecUpwN.AIMSICD.adapters; +import com.SecUpwN.AIMSICD.AIMSICD; import com.SecUpwN.AIMSICD.R; +import com.SecUpwN.AIMSICD.utils.Helpers; import android.app.AlertDialog; import android.content.ContentValues; @@ -10,6 +12,7 @@ import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import android.os.Bundle; import android.os.Environment; import android.util.Log; @@ -18,6 +21,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.InputStream; +import java.util.ArrayList; import java.util.List; import au.com.bytecode.opencsv.CSVReader; @@ -30,18 +34,22 @@ public class AIMSICDDbAdapter { private final DbHelper mDbHelper; private SQLiteDatabase mDb; private final Context mContext; - private static final int DATABASE_VERSION = 5; + private static final int DATABASE_VERSION = 6; private static final String COLUMN_ID = "_id"; + private String[] mTables; private final String LOCATION_TABLE = "locationinfo"; private final String CELL_TABLE = "cellinfo"; private final String OPENCELLID_TABLE = "opencellid"; private final String DEFAULT_MCC_TABLE = "defaultlocation"; + private final String SILENT_SMS_TABLE = "silentsms"; private final String DB_NAME = "myCellInfo"; private final String FOLDER = Environment.getExternalStorageDirectory() + "/AIMSICD/"; public AIMSICDDbAdapter(Context context) { mContext = context; mDbHelper = new DbHelper(context); + mTables = new String[] { LOCATION_TABLE, CELL_TABLE, OPENCELLID_TABLE, + SILENT_SMS_TABLE }; } public AIMSICDDbAdapter open() throws SQLException { @@ -53,6 +61,17 @@ public void close() { mDbHelper.close(); } + public long insertSilentSms(Bundle bundle) { + ContentValues smsValues = new ContentValues(); + smsValues.put("Address", bundle.getString("address")); + smsValues.put("Display", bundle.getString("display_address")); + smsValues.put("ServiceCtr", bundle.getString("service_centre")); + smsValues.put("Message", bundle.getString("message")); + smsValues.put("Timestamp", bundle.getInt("timestamp")); + + return mDb.insert(SILENT_SMS_TABLE, null, smsValues); + } + /** * Inserts Cell Details into Database * @@ -144,6 +163,14 @@ public long insertLocation(int lac, int cellID, return 0; } + /** + * Returns Silent Sms database contents + */ + public Cursor getSilentSmsData() { + return mDb.query(SILENT_SMS_TABLE, new String[] {"Address", "Display", "ServiceCtr", + "Message", "Timestamp"}, + null,null,"Timestamp DESC",null, null); + } /** * Returns Cell Information database contents @@ -283,9 +310,12 @@ public void updateOpenCellID () { try { CSVReader csvReader = new CSVReader(new FileReader(file)); List csvCellID = csvReader.readAll(); - - for (int i=1; i records = new ArrayList<>(); + String next[]; + CSVReader csvReader = new CSVReader(new FileReader(file)); + while ((next = csvReader.readNext()) != null) { + records.add(next); + } + + if (!records.isEmpty()) { + int lines = records.size(); + AIMSICD.mProgressBar.setMax(lines); + AIMSICD.mProgressBar.setProgress(0); + for (int i = 1; i < lines; i++) { + AIMSICD.mProgressBar.setProgress(i); + switch (table) { + case CELL_TABLE: + insertCell(Integer.parseInt(records.get(i)[1]), + Integer.parseInt(records.get(i)[2]), + Integer.parseInt(records.get(i)[3]), + Double.parseDouble(records.get(i)[4]), + Double.parseDouble(records.get(i)[5]), + Integer.parseInt(records.get(i)[6]), + String.valueOf(records.get(i)[7]), + String.valueOf(records.get(i)[8]), + String.valueOf(records.get(i)[9]), + String.valueOf(records.get(i)[10])); + break; + case LOCATION_TABLE: + insertLocation(Integer.parseInt(records.get(i)[1]), + Integer.parseInt(records.get(i)[2]), + Integer.parseInt(records.get(i)[3]), + Double.parseDouble(records.get(i)[4]), + Double.parseDouble(records.get(i)[5]), + Integer.parseInt(records.get(i)[6]), + String.valueOf(records.get(i)[7])); + break; + case OPENCELLID_TABLE: + insertOpenCell(Double.parseDouble(records.get(i)[1]), + Double.parseDouble(records.get(i)[2]), + Integer.parseInt(records.get(i)[3]), + Integer.parseInt(records.get(i)[4]), + Integer.parseInt(records.get(i)[5]), + Integer.parseInt(records.get(i)[6]), + Integer.parseInt(records.get(i)[7]), + Integer.parseInt(records.get(i)[8])); + break; + case SILENT_SMS_TABLE: + Bundle bundle = new Bundle(); + bundle.putString("address", String.valueOf(records.get(i)[1])); + bundle.putString("display_address", + String.valueOf(records.get(i)[2])); + bundle.putString("message_class", + String.valueOf(records.get(i)[3])); + bundle.putString("service_centre", + String.valueOf(records.get(i)[4])); + bundle.putString("message", String.valueOf(records.get(i)[5])); + bundle.putInt("timestamp", Integer.parseInt(records.get(i)[6])); + insertSilentSms(bundle); + break; + } + + } + } + } + } + return true; + } catch (Exception e) { + Log.e(TAG, "importDB() " + e); + return false; + } finally { + AIMSICD.mProgressBar.setProgress(0); } } @@ -310,15 +424,16 @@ public void updateOpenCellID () { */ public void exportDB () { try { - export(LOCATION_TABLE); - export(CELL_TABLE); - export(OPENCELLID_TABLE); + for (String table : mTables) { + export(table); + } final AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(R.string.database_export_successful) .setMessage("Database tables exported succesfully to:\n" + FOLDER); builder.create().show(); } catch (Exception ioe) { - Log.e (TAG, "exportDB() " + ioe.getMessage()); + Helpers.sendMsg(mContext, "Error exporting database tables"); + Log.e (TAG, "exportDB() " + ioe); } } @@ -346,10 +461,13 @@ private void export(String tableName) { csvWrite.writeNext(c.getColumnNames()); String[] rowData = new String[c.getColumnCount()]; - + int size = c.getColumnCount(); + AIMSICD.mProgressBar.setProgress(0); + AIMSICD.mProgressBar.setMax(size); while (c.moveToNext()) { - for (int i = 0; i < c.getColumnCount(); i++) { + for (int i = 0; i < size; i++) { rowData[i] = c.getString(i); + AIMSICD.mProgressBar.setProgress(i); } csvWrite.writeNext(rowData); } @@ -358,6 +476,8 @@ private void export(String tableName) { c.close(); } catch (Exception e) { Log.e(TAG, "Error exporting table " + tableName + " " + e); + } finally { + AIMSICD.mProgressBar.setProgress(0); } Log.i(TAG, "exporting database complete"); @@ -374,6 +494,16 @@ public class DbHelper extends SQLiteOpenHelper { @Override public void onCreate(SQLiteDatabase database) { + + /* + * Silent Sms Database + */ + String SMS_DATABASE_CREATE = "create table " + + SILENT_SMS_TABLE + " (" + COLUMN_ID + + " integer primary key autoincrement, Address VARCHAR, Display VARCHAR, " + + "ServiceCtr VARCHAR, Message VARCHAR, Timestamp INTEGER);"; + database.execSQL(SMS_DATABASE_CREATE); + /* * Location Tracking Database */ @@ -430,6 +560,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + LOCATION_TABLE); db.execSQL("DROP TABLE IF EXISTS " + CELL_TABLE); db.execSQL("DROP TABLE IF EXISTS " + OPENCELLID_TABLE); + db.execSQL("DROP TABLE IF EXISTS " + SILENT_SMS_TABLE); db.execSQL("DROP TABLE IF EXISTS " + DEFAULT_MCC_TABLE); onCreate(db); diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/SilentSmsCardData.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/SilentSmsCardData.java new file mode 100644 index 000000000..d0b4dcb53 --- /dev/null +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/SilentSmsCardData.java @@ -0,0 +1,46 @@ +package com.SecUpwN.AIMSICD.adapters; + +public class SilentSmsCardData { + private String mAddress; + private String mDisplayAddress; + private String mMessageClass; + private String mServiceCentre; + private String mMessage; + private int mTimestamp; + + public SilentSmsCardData(String address, String displayAddress, String messageClass, + String serviceCentre, String messageBody, int timestamp) + { + mAddress = address; + mDisplayAddress = displayAddress; + mMessageClass = messageClass; + mServiceCentre = serviceCentre; + mMessage = messageBody; + mTimestamp = timestamp; + } + + public String getAddress() { + return mAddress; + } + + public String getDisplayAddress() { + return mDisplayAddress; + } + + public String getMessageClass() { + return mMessageClass; + } + + public String getServiceCentre() { + return mServiceCentre; + } + + public String getMessage() { + return mMessage; + } + + public String getTimestamp() { + return "Timestamp: " + mTimestamp; + } + +} diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/SilentSmsCardInflater.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/SilentSmsCardInflater.java new file mode 100644 index 000000000..c87fd91bb --- /dev/null +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/SilentSmsCardInflater.java @@ -0,0 +1,67 @@ +package com.SecUpwN.AIMSICD.adapters; + +import com.SecUpwN.AIMSICD.R; +import com.SecUpwN.AIMSICD.fragments.SilentSmsFragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class SilentSmsCardInflater implements IAdapterViewInflater { + + @Override + public View inflate(final BaseInflaterAdapter adapter, final int pos, View convertView, ViewGroup parent) + { + ViewHolder holder; + + if (convertView == null) + { + LayoutInflater inflater = LayoutInflater.from(parent.getContext()); + convertView = inflater.inflate(R.layout.silent_sms_items, parent, false); + holder = new ViewHolder(convertView); + } + else + { + holder = (ViewHolder) convertView.getTag(); + } + + final SilentSmsCardData item = adapter.getTItem(pos); + holder.updateDisplay(item); + + return convertView; + } + + private class ViewHolder + { + private final View mRootView; + private final TextView mAddress; + private final TextView mDisplayAddress; + private final TextView mMessageClass; + private final TextView mServiceCentre; + private final TextView mMessageBody; + private final TextView mTimestamp; + + public ViewHolder(View rootView) + { + mRootView = rootView; + mAddress= (TextView) mRootView.findViewById(R.id.address); + mDisplayAddress = (TextView) mRootView.findViewById(R.id.display_address); + mMessageClass = (TextView) mRootView.findViewById(R.id.message_class); + mServiceCentre = (TextView) mRootView.findViewById(R.id.service_centre); + mMessageBody = (TextView) mRootView.findViewById(R.id.message_body); + mTimestamp = (TextView) mRootView.findViewById(R.id.message_timestamp); + rootView.setTag(this); + } + + public void updateDisplay(SilentSmsCardData item) + { + mAddress.setText(item.getAddress()); + mDisplayAddress.setText(item.getDisplayAddress()); + mMessageClass.setText(item.getMessageClass()); + mServiceCentre.setText(item.getServiceCentre()); + mMessageBody.setText(item.getMessage()); + mTimestamp.setText(item.getTimestamp()); + } + } +} diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java index 047ed5b6c..cea8107ca 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java @@ -1,6 +1,8 @@ package com.SecUpwN.AIMSICD.fragments; import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter; +import com.SecUpwN.AIMSICD.adapters.SilentSmsCardData; +import com.SecUpwN.AIMSICD.adapters.SilentSmsCardInflater; import com.SecUpwN.AIMSICD.utils.Helpers; import com.SecUpwN.AIMSICD.R; import com.SecUpwN.AIMSICD.adapters.BaseInflaterAdapter; @@ -155,6 +157,23 @@ private void BuildTable(Cursor tableData) { lv.setAdapter(adapter); break; } + case "Silent Sms": { + BaseInflaterAdapter adapter + = new BaseInflaterAdapter<>( + new SilentSmsCardInflater()); + int count = tableData.getCount(); + while (tableData.moveToNext()) { + SilentSmsCardData data = new SilentSmsCardData("Address: " + tableData.getString(0), + "Display Address: " + tableData.getString(1), + "Message Class: " + tableData.getString(2), + "Service Centre: " + tableData.getString(3), + "Message: " + tableData.getString(4), + tableData.getInt(5)); + adapter.addItem(data, false); + } + lv.setAdapter(adapter); + break; + } default: { BaseInflaterAdapter adapter = new BaseInflaterAdapter<>( @@ -195,6 +214,8 @@ protected Cursor doInBackground(Cursor... params) { return mDb.getOpenCellIDData(); case "Default MCC Locations": return mDb.getDefaultMccLocationData(); + case "Silent Sms": + return mDb.getSilentSmsData(); } return null; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/SilentSmsFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/SilentSmsFragment.java new file mode 100644 index 000000000..ca009f03d --- /dev/null +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/SilentSmsFragment.java @@ -0,0 +1,67 @@ +package com.SecUpwN.AIMSICD.fragments; + +import com.SecUpwN.AIMSICD.R; +import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter; +import com.SecUpwN.AIMSICD.adapters.BaseInflaterAdapter; +import com.SecUpwN.AIMSICD.adapters.SilentSmsCardData; +import com.SecUpwN.AIMSICD.adapters.SilentSmsCardInflater; + +import android.database.Cursor; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; + +public class SilentSmsFragment extends Fragment { + + private AIMSICDDbAdapter mDbHelper; + + public SilentSmsFragment() {} + + @Override + public void onCreate(Bundle savedInstance) { + super.onCreate(savedInstance); + mDbHelper = new AIMSICDDbAdapter(getActivity().getBaseContext()); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.sms_fragment, + container, false); + + if (view != null) { + ListView lv = (ListView) view.findViewById(R.id.list_view); +/* String originatingAddress = getArguments().getString("address"); + String displayAddress = getArguments().getString("display_address"); + String messageClass = getArguments().getString("message_class"); + String serviceCentre = getArguments().getString("service_centre"); + String messageBody = getArguments().getString("message"); + int timestamp = getArguments().getInt("timestamp");*/ + mDbHelper.open(); + Cursor smsData = mDbHelper.getSilentSmsData(); + BaseInflaterAdapter adapter + = new BaseInflaterAdapter<>( + new SilentSmsCardInflater()); + while (smsData.moveToNext()) { + SilentSmsCardData data = new SilentSmsCardData(smsData.getString(0), smsData.getString(1), + smsData.getString(2), smsData.getString(3), smsData.getString(4), + smsData.getInt(5)); + adapter.addItem(data, false); + } + mDbHelper.close(); + lv.setAdapter(adapter); + lv.setVisibility(View.VISIBLE); + } + + return view; + } + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + } + +} diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/receiver/SmsReceiver.java b/app/src/main/java/com/SecUpwN/AIMSICD/receiver/SmsReceiver.java new file mode 100644 index 000000000..c24f10f3d --- /dev/null +++ b/app/src/main/java/com/SecUpwN/AIMSICD/receiver/SmsReceiver.java @@ -0,0 +1,51 @@ +package com.SecUpwN.AIMSICD.receiver; + +import com.SecUpwN.AIMSICD.service.AimsicdService; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.telephony.SmsMessage; +import android.util.Log; + +public class SmsReceiver extends BroadcastReceiver { + + private final String TAG = "AIMSICD_SmsReceiver"; + + public void onReceive(Context context, Intent intent) { + try { + final Bundle bundle = intent.getExtras(); + if (bundle != null) { + Object[] pdus = (Object[])bundle.get("pdus"); + final SmsMessage[] messages = new SmsMessage[pdus.length]; + for (int i = 0; i < pdus.length; i++) { + messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]); + } + if (messages.length > -1) { + for (SmsMessage sms : messages) { + if (sms.getMessageClass().equals(SmsMessage.MessageClass.CLASS_0)) { + Intent smsIntent = new Intent(AimsicdService.SILENT_SMS); + intent.putExtra("address", sms.getOriginatingAddress()); + intent.putExtra("display_address", + sms.getDisplayOriginatingAddress()); + intent.putExtra("class", sms.getMessageClass().toString()); + intent.putExtra("service_centre", sms.getServiceCenterAddress()); + intent.putExtra("message", sms.getMessageBody()); + intent.putExtra("timestamp", sms.getTimestampMillis()); + context.sendBroadcast(smsIntent); + Log.i(TAG, "Class 0 Message received, Sender: " + + sms.getOriginatingAddress() + " Message: " + + sms.getMessageBody()); + } + } + } + } + + } catch (NullPointerException npe) { + Log.e("SmsReceiver", "Exception smsReceiver" + npe); + } + } + + +} diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/SamsungMulticlientRilExecutor.java b/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/SamsungMulticlientRilExecutor.java index 0d3c406e8..125249d0b 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/SamsungMulticlientRilExecutor.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/SamsungMulticlientRilExecutor.java @@ -37,6 +37,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { public static final String MULTICLIENT_SOCKET = "Multiclient"; + public static final String SOCKET_NAME_RIL = "rild"; private static final int RIL_REQUEST_OEM_RAW = 59; private static final int RIL_REQUEST_OEM_STRINGS = 60; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java index 064fa053e..912abdcf3 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java @@ -23,19 +23,21 @@ public class RequestTask extends AsyncTask { public static final int OPEN_CELL_ID_REQUEST = 1; + public static final int RESTORE_DATABASE = 2; - private AIMSICDDbAdapter mDbAdapter; - private Context mContext; + private final AIMSICDDbAdapter mDbAdapter; + private final Context mContext; private int mType; - RequestTask (Context context, int type) { - mContext = context; + public RequestTask (Context context, int type) { mType = type; + mContext = context; + mDbAdapter = new AIMSICDDbAdapter(mContext); } @Override protected String doInBackground(String... uri) { - String responseString = null; + String responseString = ""; switch (mType) { case OPEN_CELL_ID_REQUEST: HttpClient httpclient = new DefaultHttpClient(); @@ -58,6 +60,12 @@ protected String doInBackground(String... uri) { //TODO Handle problems.. } break; + case RESTORE_DATABASE: + mDbAdapter.open(); + if (mDbAdapter.importDB()) + responseString = "Successful"; + mDbAdapter.close(); + break; } return responseString; @@ -77,8 +85,6 @@ protected void onPostExecute(String result) { if (!dir.exists()) { dir.mkdirs(); } - String fileName = Environment.getExternalStorageDirectory() - + "/AIMSICD/OpenCellID/opencellid.csv"; File file = new File(dir, "opencellid.csv"); FileOutputStream fOut = new FileOutputStream(file); @@ -86,9 +92,10 @@ protected void onPostExecute(String result) { myOutWriter.append(result); myOutWriter.close(); fOut.close(); - mDbAdapter = new AIMSICDDbAdapter(mContext); + mDbAdapter.open(); mDbAdapter.updateOpenCellID(); + mDbAdapter.close(); } catch (Exception e) { Log.e("AIMSICD", "RequestTask() write OpenCellID response - " + e.getMessage()); @@ -96,6 +103,15 @@ protected void onPostExecute(String result) { } } break; + case RESTORE_DATABASE: + if (result != null) { + if (result.equals("Successful")){ + Helpers.sendMsg(mContext, "Restore database completed successfully"); + } else { + Helpers.sendMsg(mContext, "Error restoring database"); + } + } + break; } } } \ No newline at end of file diff --git a/app/src/main/res/drawable/progress_bar_states.xml b/app/src/main/res/drawable/progress_bar_states.xml new file mode 100644 index 000000000..c9dc81261 --- /dev/null +++ b/app/src/main/res/drawable/progress_bar_states.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/silent_sms_items.xml b/app/src/main/res/layout/silent_sms_items.xml new file mode 100644 index 000000000..b77e7eeed --- /dev/null +++ b/app/src/main/res/layout/silent_sms_items.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/sms_fragment.xml b/app/src/main/res/layout/sms_fragment.xml new file mode 100644 index 000000000..c69a7a370 --- /dev/null +++ b/app/src/main/res/layout/sms_fragment.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/top.xml b/app/src/main/res/layout/top.xml index a00eaad79..ff8b31ad8 100644 --- a/app/src/main/res/layout/top.xml +++ b/app/src/main/res/layout/top.xml @@ -1,11 +1,19 @@ + + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:layout_below="@+id/progressBar"> - - diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml index 34db064cb..9bd7bedfe 100644 --- a/app/src/main/res/menu/main_menu.xml +++ b/app/src/main/res/menu/main_menu.xml @@ -19,9 +19,13 @@ android:showAsAction="ifRoom"/> - + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ac6f8e2eb..4eff87c8a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -46,7 +46,8 @@ Track Femtocell Untrack Femtocell Show Map - Export Database tables + Backup Database + Restore Database Preferences Press again to exit Update OpenCellID Data @@ -170,7 +171,6 @@ Lat: Lng: - Load Data Select Table @@ -179,6 +179,7 @@ Location Data OpenCellID Data Default MCC Locations + Silent Sms Export Successful @@ -187,4 +188,7 @@ Enter AT Command: Response: Execute + + + Silent SMS Intercepted