diff --git a/android/build.gradle b/android/build.gradle index 6b514fa9..2b76dcd4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -26,6 +26,7 @@ apply plugin: 'com.android.application' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) + implementation files('libs/smssdk.aar') implementation 'com.chimbori.crux:crux:2.2.0' compile 'com.klinkerapps:android-smsmms:5.2.6' implementation 'androidx.appcompat:appcompat:1.2.0' diff --git a/android/libs/smssdk.aar b/android/libs/smssdk.aar new file mode 100644 index 00000000..a02c39ce Binary files /dev/null and b/android/libs/smssdk.aar differ diff --git a/android/src/com/volla/launcher/activity/ReceiveTextActivity.java b/android/src/com/volla/launcher/activity/ReceiveTextActivity.java index 3707a12c..9175022e 100644 --- a/android/src/com/volla/launcher/activity/ReceiveTextActivity.java +++ b/android/src/com/volla/launcher/activity/ReceiveTextActivity.java @@ -44,8 +44,15 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import com.volla.launcher.util.NotificationPlugin; +import android.content.ServiceConnection; +import android.content.ComponentName; +import android.os.IBinder; +import android.os.RemoteException; +import android.util.Log; +import com.volla.smssdk.SMSUpdateManager; +import android.os.Looper; -public class ReceiveTextActivity extends AndroidNativeActivity +public class ReceiveTextActivity extends AndroidNativeActivity implements SMSUpdateManager.ServiceConnectionListener { private static final String TAG = "ReceiveTextActivity"; @@ -53,10 +60,13 @@ public class ReceiveTextActivity extends AndroidNativeActivity public static final String CHECK_SHORTCUT = "volla.launcher.checkNewShortcut"; public static final String GOT_SHORTCUT = "volla.launcher.receivedShortcut"; public static final String UIMODE_CHANGED = "volla.launcher.uiModeChanged"; + public List smsPid; + private Handler handler; private NotificationBroadcastReceiver notificationBroadcastReceiver; public static ReceiveTextActivity instance; private String channel_d; + SMSUpdateManager smsUpdateManager; private static Map pendingShortcutMessage; static { @@ -146,8 +156,31 @@ public void onCreate (Bundle savedInstanceState) { registerReceiver(notificationBroadcastReceiver, intentFilter); NotificationPlugin.getInstance(ReceiveTextActivity.this).registerListener(); Log.d(TAG, "Android activity created"); + handler = new Handler(Looper.getMainLooper()); + } + +public void connectSmsUpdateManager(Context ctx, List smsItems) { + this.smsPid = smsItems; + smsUpdateManager = new SMSUpdateManager(ctx, this); + smsUpdateManager.start(); } +@Override + public void onServiceConnected() { + if(smsPid != null && smsPid.size() > 0){ + Log.d(TAG, "SMS database update called "); + int item = smsUpdateManager.smsUpdate(smsPid); + Log.d(TAG, "SMS database updated "+ item + "for sms id "+smsPid); + } + + Log.d(TAG, "SMS database updated "); + } + + @Override + public void onServiceDisconnected() { + + } + @Override protected void onDestroy() { super.onDestroy(); diff --git a/android/src/com/volla/launcher/util/MessageUtil.java b/android/src/com/volla/launcher/util/MessageUtil.java index 801b9541..4387bf3c 100644 --- a/android/src/com/volla/launcher/util/MessageUtil.java +++ b/android/src/com/volla/launcher/util/MessageUtil.java @@ -44,7 +44,6 @@ public class MessageUtil { private static final String SMS_SEND_ACTION = "CTS_SMS_SEND_ACTION"; private static final String SMS_DELIVERY_ACTION = "CTS_SMS_DELIVERY_ACTION"; - public static final int PERMISSIONS_REQUEST_SEND_SMS = 123; static { diff --git a/android/src/com/volla/launcher/worker/MessageWorker.java b/android/src/com/volla/launcher/worker/MessageWorker.java index 01337805..64d2effc 100644 --- a/android/src/com/volla/launcher/worker/MessageWorker.java +++ b/android/src/com/volla/launcher/worker/MessageWorker.java @@ -30,6 +30,11 @@ import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; +import com.volla.launcher.activity.ReceiveTextActivity; +import com.volla.smssdk.SMSUpdateManager; +import android.os.Looper; +import android.os.Handler; + public class MessageWorker { @@ -45,6 +50,7 @@ public class MessageWorker { public static final String GOT_MMS_IMAGE = "volla.launcher.mmsImageResponse"; public static final String THREAD_ID = Telephony.TextBasedSmsColumns.THREAD_ID; public static final String RECIPIENT_IDs = Telephony.ThreadsColumns.RECIPIENT_IDS; + public static List smsPid = new ArrayList<>(); static { SystemDispatcher.addListener(new SystemDispatcher.Listener() { @@ -61,6 +67,7 @@ public void run() { if (type.equals(GET_CONVERSATION)) { if (activity.checkSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED) { getConversation(message, activity); + updateMessageHandler(message, activity); } else { Map reply = new HashMap(); ArrayList messageList = new ArrayList(); @@ -117,6 +124,66 @@ public void run() { }); } + + private static void updateMessageHandler(Map message, Activity activity) { + Runnable runnable = new Runnable () { + public void run() { + Looper.prepare(); + // Create a Handler associated with this thread's Looper + Handler handler = new Handler(); + updateMessageReadStatus(message, activity); + Looper.loop(); + } + }; + Thread thread = new Thread(runnable); + thread.start(); + } + + static void updateMessageReadStatus(Map message, Activity activity) { + String threadId = (String) message.get("threadId"); + ArrayList threadList = new ArrayList(); + if (threadId != null) { + threadList.add( threadId ); + } + for (String thId : threadList) { + Log.d(TAG, "Check messages of therad " + thId); + Uri uriSms = Uri.parse("content://sms/"); + String[] projection = {Telephony.Sms._ID, Telephony.Sms.THREAD_ID, Telephony.Sms.BODY, Telephony.Sms.TYPE, + Telephony.Sms.DATE, Telephony.Sms.ADDRESS, Telephony.Sms.READ}; + String selection = Telephony.Sms.THREAD_ID + " = ? AND " + Telephony.Sms.READ + " = ?"; + String[] selectionArgs = {String.valueOf(thId), "0"}; + + long cutOffTimeStamp = 0; + try { + Cursor c = activity.getContentResolver().query(uriSms, projection, selection, selectionArgs, null);; + Log.d(TAG, "MessagesCount = " + c.getCount() ); + if (c.moveToFirst()) { + for (int i = 0; i < c.getCount(); i++) { + + String _id = c.getString(c.getColumnIndexOrThrow("_id")); + String thread_id = c.getString(c.getColumnIndexOrThrow("thread_id")); + String msg = c.getString(c.getColumnIndexOrThrow("body")); + String type = c.getString(c.getColumnIndexOrThrow("type")); + String date = c.getString(c.getColumnIndexOrThrow("date")); + String user = c.getString(c.getColumnIndexOrThrow("address")); + String read = c.getString(c.getColumnIndexOrThrow("read")); + Log.d(TAG, "read "+ read +" : _id "+ _id + " : thread_id "+thread_id + " : msg "+ msg + + " : type " +type + " : date " + date +" : user "+ user); + smsPid.add(_id); + c.moveToNext(); + } + } + c.close(); + } catch (SQLiteException ex) { + Log.d("SQLiteException", ex.getMessage()); + } + } + ReceiveTextActivity receiveTextActivity = new ReceiveTextActivity(); + receiveTextActivity.connectSmsUpdateManager(activity, smsPid); + + } + + static void getConversation(Map message, Activity activity) { Log.d(TAG, "Invoked JAVA getConversation" );