Skip to content

Commit

Permalink
Merge pull request #218 from HelloVolla/smsUpdate
Browse files Browse the repository at this point in the history
Sms update
  • Loading branch information
wurzer authored Apr 21, 2024
2 parents 0461333 + c6634bc commit 64eb632
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Binary file added android/libs/smssdk.aar
Binary file not shown.
35 changes: 34 additions & 1 deletion android/src/com/volla/launcher/activity/ReceiveTextActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,29 @@
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";

public static final String GOT_TEXT = "volla.launcher.receiveTextResponse";
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<String> smsPid;
private Handler handler;

private NotificationBroadcastReceiver notificationBroadcastReceiver;
public static ReceiveTextActivity instance;
private String channel_d;
SMSUpdateManager smsUpdateManager;

private static Map pendingShortcutMessage;
static {
Expand Down Expand Up @@ -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<String> 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();
Expand Down
1 change: 0 additions & 1 deletion android/src/com/volla/launcher/util/MessageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
67 changes: 67 additions & 0 deletions android/src/com/volla/launcher/worker/MessageWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<String> smsPid = new ArrayList<>();

static {
SystemDispatcher.addListener(new SystemDispatcher.Listener() {
Expand All @@ -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<Map> messageList = new ArrayList();
Expand Down Expand Up @@ -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<String> 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" );

Expand Down

0 comments on commit 64eb632

Please sign in to comment.