From dd96fa3cb56993c93f43854b7817b5bda5a2ce9f Mon Sep 17 00:00:00 2001 From: Arvind Date: Sat, 17 Feb 2024 12:29:37 +0530 Subject: [PATCH 1/3] Implemented code to update SMS read status from Luncher conversation --- android/libs/smssdk.aar | Bin 0 -> 6996 bytes .../activity/ReceiveTextActivity.java | 35 ++++++- .../com/volla/launcher/util/MessageUtil.java | 91 +++++++++++++++++- 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 android/libs/smssdk.aar diff --git a/android/libs/smssdk.aar b/android/libs/smssdk.aar new file mode 100644 index 0000000000000000000000000000000000000000..a02c39cea82ca1366aa6eaa004e788db36c706d6 GIT binary patch literal 6996 zcmbuERa6|zvbG_(OpxI2?(PJF!{F{VxI2RrAV`2A5MXe33GVK}B?NbO3oa*npNsSF zZ~f=$bg#Fodv#Z>s=n)fR2AXiabRGOkzrt9B>oBp=H0(X7#M`VR-Mhm#{&*V^*;^` zU!zPw{%#Kb)rY^5aI$oBwzUMBIoVo)+&$QQ936P$Bv3zdU`pR*QH`w?6sA)}kx3o| z%E8##+bHsP|w@<((_0}QIO7>3`WV%=F@ zJ+xwM90;)00(R`3RsJNz{DyyIFOY49uv(?(a_1|EvM`O=v5B0N6KjgCb4rJpK54-D zVN`8Kpi{7!zLZ#uWbP5%@eFX3szG_{TB=TZCXZEhU@%>p$-xK(h95i z4~HFDvP#mCd5W$b;WvwTx>;Z14d8s{_y5`m?&$--t4E4L`!_O!5;6_D4ECW`4;@Ey0ziMqlTGl1%2W1Exn{Hp@&;y z08(zFarvsi##BsF>-e}Ga{= z<$)Ixc?N$G7@*{g^Knuxs{CodlikscT6e^Jsg1m7b` z=UJb%mi>e5Z0kif_qetMjp?e*tHsD5u<9Ql%xaa)!Ble?d^aw%`i_O=p`Wix#T^S3 zRNipOZR+QeZ`|jSOEsvy91pidP?%7UZ_FQNsfpXEi7SO<^&9;yPK|TWQOnW9d8UD_ z-!v*uR6A23@P-TTB+1LiQFnKv_2ZAzf*1LGW2en~f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cmV?d00001 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..0fe19074 100644 --- a/android/src/com/volla/launcher/util/MessageUtil.java +++ b/android/src/com/volla/launcher/util/MessageUtil.java @@ -31,6 +31,13 @@ import com.klinker.android.send_message.Message; import com.klinker.android.send_message.Utils; import com.volla.launcher.util.MMSManager; +import android.database.Cursor; +import android.database.sqlite.SQLiteException; +import com.volla.launcher.activity.ReceiveTextActivity; +import com.volla.smssdk.SMSUpdateManager; +import android.os.Looper; +import android.os.Handler; +import android.provider.Telephony; public class MessageUtil { @@ -44,8 +51,10 @@ 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"; - + private static final String GET_CONVERSATION = "volla.launcher.conversationAction"; public static final int PERMISSIONS_REQUEST_SEND_SMS = 123; + public static List smsPid = new ArrayList<>(); + static { SystemDispatcher.addListener(new SystemDispatcher.Listener() { @@ -248,11 +257,91 @@ public void run() { Thread thread = new Thread(runnable); thread.start(); + } else if(type.equals(GET_CONVERSATION)){ + Runnable runnable = new Runnable () { + + public void run() { + Looper.prepare(); + + // Create a Handler associated with this thread's Looper + Handler handler = new Handler(); + Log.d(TAG, "getConversation "); + getConversation(message, activity); + // Perform operations using the Handler + + // Quit the Looper after finishing + Looper.loop(); + + + } + }; + Thread thread = new Thread(runnable); + thread.start(); + + } } }); } + static void getConversation(Map message, Activity activity) { + Log.d(TAG, "Invoked JAVA getConversation" ); + + // params are threadId, age , after, afterId, read , match , count, threadAge + + 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 uriSmsMms = Uri.parse("content://mms-sms/conversations/" + thId + "/"); + Uri uriSms = Uri.parse("content://sms/"); + //String[] projection = new String[] { "_id", "address", "date", "body", "person", "read", "ct_t", "type" }; + 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 { + String filter = " 1=1 " ; + Log.d(TAG, "Message Filter is : " + filter ); + + Cursor c = activity.getContentResolver().query(uriSms, projection, selection, selectionArgs, null);; + + int mesgCount = c.getCount(); + Log.d(TAG, "MessagesCount = " + mesgCount ); + 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 String getSystemProperty(String key) { String value = null; From b6fd3601e63545c73356df0c816bcb051e252061 Mon Sep 17 00:00:00 2001 From: arvibuddy <111645029+arvibuddy@users.noreply.github.com> Date: Sat, 6 Apr 2024 15:27:31 +0530 Subject: [PATCH 2/3] Update build.gradle to include smssdk.aar Update build.gradle to include smssdk.aar --- android/build.gradle | 1 + 1 file changed, 1 insertion(+) 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' From c6634bc1e48cfff8866c02bf48e72c296c99cfb6 Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 18 Apr 2024 23:07:34 +0530 Subject: [PATCH 3/3] Mving smsUpdate code from MessageUtil.java class to MessageWorker.java class --- .../com/volla/launcher/util/MessageUtil.java | 90 ------------------- .../volla/launcher/worker/MessageWorker.java | 67 ++++++++++++++ 2 files changed, 67 insertions(+), 90 deletions(-) diff --git a/android/src/com/volla/launcher/util/MessageUtil.java b/android/src/com/volla/launcher/util/MessageUtil.java index 0fe19074..4387bf3c 100644 --- a/android/src/com/volla/launcher/util/MessageUtil.java +++ b/android/src/com/volla/launcher/util/MessageUtil.java @@ -31,13 +31,6 @@ import com.klinker.android.send_message.Message; import com.klinker.android.send_message.Utils; import com.volla.launcher.util.MMSManager; -import android.database.Cursor; -import android.database.sqlite.SQLiteException; -import com.volla.launcher.activity.ReceiveTextActivity; -import com.volla.smssdk.SMSUpdateManager; -import android.os.Looper; -import android.os.Handler; -import android.provider.Telephony; public class MessageUtil { @@ -51,10 +44,7 @@ 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"; - private static final String GET_CONVERSATION = "volla.launcher.conversationAction"; public static final int PERMISSIONS_REQUEST_SEND_SMS = 123; - public static List smsPid = new ArrayList<>(); - static { SystemDispatcher.addListener(new SystemDispatcher.Listener() { @@ -257,91 +247,11 @@ public void run() { Thread thread = new Thread(runnable); thread.start(); - } else if(type.equals(GET_CONVERSATION)){ - Runnable runnable = new Runnable () { - - public void run() { - Looper.prepare(); - - // Create a Handler associated with this thread's Looper - Handler handler = new Handler(); - Log.d(TAG, "getConversation "); - getConversation(message, activity); - // Perform operations using the Handler - - // Quit the Looper after finishing - Looper.loop(); - - - } - }; - Thread thread = new Thread(runnable); - thread.start(); - - } } }); } - static void getConversation(Map message, Activity activity) { - Log.d(TAG, "Invoked JAVA getConversation" ); - - // params are threadId, age , after, afterId, read , match , count, threadAge - - 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 uriSmsMms = Uri.parse("content://mms-sms/conversations/" + thId + "/"); - Uri uriSms = Uri.parse("content://sms/"); - //String[] projection = new String[] { "_id", "address", "date", "body", "person", "read", "ct_t", "type" }; - 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 { - String filter = " 1=1 " ; - Log.d(TAG, "Message Filter is : " + filter ); - - Cursor c = activity.getContentResolver().query(uriSms, projection, selection, selectionArgs, null);; - - int mesgCount = c.getCount(); - Log.d(TAG, "MessagesCount = " + mesgCount ); - 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 String getSystemProperty(String key) { String value = null; 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" );