Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #251

Merged
merged 4 commits into from
Jul 21, 2024
Merged

Dev #251

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<manifest package="com.volla.launcher" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="2.4.14" android:versionCode="311" android:installLocation="auto">
<manifest package="com.volla.launcher" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="2.4.15" android:versionCode="312" android:installLocation="auto">
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29"/>

<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public interface NotificationListener {

public void addListener(NotificationListener listener) {
Log.d(TAG,"Adding Listener");
if(!listeners.contains(listener)){
if(!listeners.contains(listener)){
listeners.add(listener);
}
}
Expand Down Expand Up @@ -164,6 +164,9 @@ public IBinder onBind(Intent intent) {
@Override
public void onNotificationPosted(StatusBarNotification sbn){
Log.d(TAG, "onNotificationPosted");
if(!sbn.getNotification().category.equalsIgnoreCase("msg")) {
return;
}
storageManager.storeNotificationCount(sbn.getPackageName(), storageManager.getNotificationCount(sbn.getPackageName()) +1 );
Log.d(TAG, "listeners size : " +listeners.size());
for (NotificationListener listener : listeners) {
Expand Down Expand Up @@ -216,18 +219,18 @@ public void onNotificationPosted(StatusBarNotification sbn){
appIcon.compress(Bitmap.CompressFormat.PNG, 10, outStream);
bitmapData = outStream.toByteArray();
String largeIcon = Base64.encodeToString(bitmapData, Base64.NO_WRAP);
Log.d("com.volla.launcher", "image : "+largeIcon);
Log.d("com.volla.launcher", "image : "+largeIcon);
users.largeIcon = largeIcon;
}

// Droping the Notifications received for attachments but contains no attachment data
Message msg = new Message();
msg = storeNotificationMessage(sbn);
if(msg == null){
if(msg == null){
Log.d(TAG, "storeNotificationMessage returned null msg object");
return;
}
if(msg.getText() != null && msg.getText().contains("\uD83D\uDCF7") && msg.getLargeIcon().length() <=2){
return;
}
if(msg.getText() != null && msg.getText().contains("\uD83D\uDCF7") && msg.getLargeIcon().length() <=2){
msg.setLargeIcon("403");
}
if(msg.getLargeIcon() != null && msg.getLargeIcon().equalsIgnoreCase("403")){
Expand All @@ -236,7 +239,7 @@ public void onNotificationPosted(StatusBarNotification sbn){
} else {
msg.setNotification("");
}
if(lastNotificationTime == msg.getTimeStamp()){
if(lastNotificationTime == msg.getTimeStamp()){
if(msg.getLargeIcon() != null && msg.getLargeIcon().length() >= 10){
if(lastAttachment.equalsIgnoreCase(msg.getLargeIcon()) && lastMessage.equalsIgnoreCase(msg.getText())){
return;
Expand All @@ -245,12 +248,12 @@ public void onNotificationPosted(StatusBarNotification sbn){
return;
}
}
lastNotificationTime = msg.getTimeStamp();
lastAttachment = msg.getLargeIcon();
lastMessage = msg.getText();
Log.d(TAG, "Keeping Volla notifications messages");
lastNotificationTime = msg.getTimeStamp();
lastAttachment = msg.getLargeIcon();
lastMessage = msg.getText();
Log.d(TAG, "Keeping Volla notifications messages");
repository.insertMessage(msg);

users.uuid = msg.getSelfDisplayName();
users.body = msg.getText();
users.user_name = String.valueOf(msg.getUuid());
Expand Down Expand Up @@ -296,8 +299,8 @@ public void onNotificationPosted(StatusBarNotification sbn){
@Override
public void onNotificationRemoved(StatusBarNotification sbn){
Log.d(TAG, "onNotificationPosted");

int notificationCode = matchNotificationCode(sbn);
storageManager.clearNotificationCount(sbn.getPackageName());
if(notificationCode != InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE) {
StatusBarNotification[] activeNotifications = this.getActiveNotifications();
if(activeNotifications != null && activeNotifications.length > 0) {
Expand All @@ -318,7 +321,7 @@ private Message storeNotificationMessage(StatusBarNotification sbn){
Message msg = new Message();
Bundle extras = NotificationCompat.getExtras(sbn.getNotification());
if(!extras.containsKey(NotificationCompat.EXTRA_MESSAGES)){
Log.d(TAG, "SBN does't contains EXTRA_MESSAGES");
Log.d(TAG, "SBN does't contains EXTRA_MESSAGES");
return msg;
}
Parcelable[] messageArray =extras.getParcelableArray(NotificationCompat.EXTRA_MESSAGES);
Expand Down Expand Up @@ -356,21 +359,21 @@ private String getBase64OfAttachment(Bundle latestMessageBundle){
base64 = getBitmapFromUri(this,Uri.parse(Uri.decode(latestMessageBundle.get("uri").toString())));
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
e.printStackTrace();
e.printStackTrace();
}
} else {
Log.d(TAG, "No attachment URI available in latest message");
}
}
return base64;
}

public String getBitmapFromUri(Context context, Uri uri) throws IOException {
InputStream input;
String base64OfImage = "";
byte[] bitmapData = null;
String base64OfImage = "";
byte[] bitmapData = null;
BitmapFactory.Options onlyBoundsOptions;
try {
context.grantUriPermission(context.getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.grantUriPermission(context.getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
input = context.getContentResolver().openInputStream(uri);
onlyBoundsOptions = new BitmapFactory.Options();
onlyBoundsOptions.inJustDecodeBounds = true;
Expand All @@ -379,7 +382,7 @@ public String getBitmapFromUri(Context context, Uri uri) throws IOException {
} catch (SecurityException se) {
Log.e(TAG, se.getMessage());
base64OfImage = "403";
return base64OfImage;
return base64OfImage;
}
if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1))
return base64OfImage;
Expand All @@ -389,7 +392,7 @@ public String getBitmapFromUri(Context context, Uri uri) throws IOException {
Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);
input.close();
try{
if (bitmap == null) return base64OfImage;
if (bitmap == null) return base64OfImage;
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int maxHeight = 640;
int maxWidth = 640;
Expand All @@ -406,8 +409,8 @@ public String getBitmapFromUri(Context context, Uri uri) throws IOException {
Log.e(TAG, "Exception: " + e.getMessage());
e.printStackTrace();
} finally {
return base64OfImage;
}
return base64OfImage;
}
}

public void storeMessage(Message msg){
Expand Down
14 changes: 9 additions & 5 deletions android/src/com/volla/launcher/worker/SignalWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import androidx.core.app.NotificationManagerCompat;
import com.volla.launcher.util.NotificationPlugin;
import android.content.pm.PackageManager;
import com.volla.launcher.storage.NotificationStorageManager;
public class SignalWorker {

private static final String TAG = "SignalWorker";
Expand Down Expand Up @@ -74,13 +75,14 @@ public void run() {
Thread thread = new Thread(runnable);
thread.start();
}
}
}
});
}

static void retrieveMessageConversations(Map message, Activity activity){
Log.d(TAG, "Invoked JAVA retrieveMessageConversations: " + message.toString());
MessageRepository repository = new MessageRepository(QtNative.activity().getApplication());
NotificationStorageManager storageManager = new NotificationStorageManager(QtNative.activity().getApplication());
ArrayList<Map> messageList = new ArrayList();
String person = (String) message.get("person");
String threadId = (String) message.get("threadId");
Expand Down Expand Up @@ -114,12 +116,13 @@ static void retrieveMessageConversations(Map message, Activity activity){
reply.put("attachments", "");
messageList.add(reply);
}
Map result = new HashMap();
Map result = new HashMap();
result.put("messages", messageList );
result.put("messagesCount", messageList.size());
Log.d(TAG, "Will dispatch messages: " + result.toString());
SystemDispatcher.dispatch(GOT_SIGNAL_MESSAGES, result);
repository.updateReadStatusInUserTableUsingName(person);
storageManager.clearNotificationCount("org.thoughtcrime.securesms");
});
} else {
repository.getAllMessageByThreadId(threadId,timeFrame).subscribe(it -> {
Expand Down Expand Up @@ -149,12 +152,13 @@ static void retrieveMessageConversations(Map message, Activity activity){
reply.put("attachments", "");
messageList.add(reply);
}
Map result = new HashMap();
Map result = new HashMap();
result.put("messages", messageList);
result.put("messagesCount", messageList.size());
Log.d(TAG, "Will dispatch messages: " + result.toString());
SystemDispatcher.dispatch(GOT_SIGNAL_MESSAGES, result);
repository.updateReadStatusInUserTableUsingThreadId(threadId);
storageManager.clearNotificationCount("org.thoughtcrime.securesms");
});

}
Expand Down Expand Up @@ -201,8 +205,8 @@ static void checkPermission(Activity activity){
}

public static boolean isSignalInstalled(Activity activity) {
String packageName = "org.thoughtcrime.securesms";
PackageManager packageManager = activity.getPackageManager();
String packageName = "org.thoughtcrime.securesms";
PackageManager packageManager = activity.getPackageManager();
try {
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true;
Expand Down