diff --git a/app/src/main/java/com/noti/main/receiver/plugin/PluginReceiver.java b/app/src/main/java/com/noti/main/receiver/plugin/PluginReceiver.java index 56dbe3c..01ab4f9 100644 --- a/app/src/main/java/com/noti/main/receiver/plugin/PluginReceiver.java +++ b/app/src/main/java/com/noti/main/receiver/plugin/PluginReceiver.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.util.Log; import androidx.annotation.VisibleForTesting; @@ -68,11 +67,11 @@ public void onReceive(Context context, Intent intent) { break; case PluginConst.ACTION_PUSH_CALL_DATA: - NotiListenerService.getInstance().sendTelecomNotification(context, BuildConfig.DEBUG, rawData.getString(PluginConst.DATA_KEY_EXTRA_DATA)); + NotiListenerService.getInstance().sendTelecomNotification(context, BuildConfig.DEBUG, data[0], data.length > 1 ? data[1] : ""); break; case PluginConst.ACTION_PUSH_MESSAGE_DATA: - NotiListenerService.getInstance().sendSmsNotification(context, BuildConfig.DEBUG, "noti.func", data[0], data[1], Calendar.getInstance().getTime()); + NotiListenerService.getInstance().sendSmsNotification(context, BuildConfig.DEBUG, "noti.func", data[0], data[1], data[2], Calendar.getInstance().getTime()); break; case PluginConst.ACTION_RESPONSE_REMOTE_DATA: diff --git a/app/src/main/java/com/noti/main/service/FirebaseMessageService.java b/app/src/main/java/com/noti/main/service/FirebaseMessageService.java index 8513292..83ca39b 100644 --- a/app/src/main/java/com/noti/main/service/FirebaseMessageService.java +++ b/app/src/main/java/com/noti/main/service/FirebaseMessageService.java @@ -499,6 +499,7 @@ protected void sendFindTaskNotification() { protected void sendTelecomNotification(Map map) { String address = map.get("address"); String Package = map.get("package"); + String nickname = map.get("nickname"); String Device_name = map.get("device_name"); String Device_id = map.get("device_id"); String Date = map.get("date"); @@ -506,6 +507,7 @@ protected void sendTelecomNotification(Map map) { Intent notificationIntent = new Intent(FirebaseMessageService.this, TelecomViewActivity.class); notificationIntent.putExtra("device_id", Device_id); notificationIntent.putExtra("address", address); + notificationIntent.putExtra("nickname", nickname); notificationIntent.putExtra("device_name", Device_name); notificationIntent.putExtra("date", Date); notificationIntent.putExtra("package", Package); @@ -525,7 +527,7 @@ protected void sendTelecomNotification(Map map) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notify_channel_id)) - .setContentTitle("New call inbound from " + address) + .setContentTitle("New call inbound from " + address + (nickname == null || nickname.isEmpty() ? "" : " (" + nickname + ")")) .setContentText("click here to reply or open dialer") .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentIntent(pendingIntent) @@ -551,6 +553,7 @@ protected void sendTelecomNotification(Map map) { protected void sendSmsNotification(Map map) { String address = map.get("address"); + String nickname = map.get("nickname"); String message = map.get("message"); String Package = map.get("package"); String Device_name = map.get("device_name"); @@ -561,6 +564,7 @@ protected void sendSmsNotification(Map map) { notificationIntent.putExtra("device_id", Device_id); notificationIntent.putExtra("message", message); notificationIntent.putExtra("address", address); + notificationIntent.putExtra("nickname", nickname); notificationIntent.putExtra("device_name", Device_name); notificationIntent.putExtra("date", Date); notificationIntent.putExtra("package", Package); @@ -580,7 +584,7 @@ protected void sendSmsNotification(Map map) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notify_channel_id)) - .setContentTitle("New message from " + address) + .setContentTitle("New message from " + address + (nickname == null || nickname.isEmpty() ? "" : " (" + nickname + ")")) .setContentText(message) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentIntent(pendingIntent) diff --git a/app/src/main/java/com/noti/main/service/NotiListenerService.java b/app/src/main/java/com/noti/main/service/NotiListenerService.java index 5b1f0d5..a080d14 100644 --- a/app/src/main/java/com/noti/main/service/NotiListenerService.java +++ b/app/src/main/java/com/noti/main/service/NotiListenerService.java @@ -204,15 +204,15 @@ private String getSystemDialerApp(Context context) { } } - private boolean isTelephonyApp(String packageName) { - return Telephony.Sms.getDefaultSmsPackage(this).equals(packageName) || getSystemDialerApp(this).equals(packageName); + private boolean isTelephonyApp(Context context, String packageName) { + return Telephony.Sms.getDefaultSmsPackage(context).equals(packageName) || getSystemDialerApp(context).equals(packageName); } @Override public void onNotificationPosted(StatusBarNotification sbn) { super.onNotificationPosted(sbn); - Log.d("ddd", sbn.getPackageName()); + if(BuildConfig.DEBUG) Log.d("ddd", sbn.getPackageName()); if (manager == null) manager = PowerUtils.getInstance(this); manager.acquire(); synchronized (pastNotificationLock) { @@ -241,7 +241,7 @@ public void onNotificationPosted(StatusBarNotification sbn) { if (PackageName.equals(getPackageName()) && (!TITLE.toLowerCase().contains("test") || TITLE.contains("main"))) { manager.release(); return; - } else if(isTelephonyApp(PackageName)) { + } else if(isTelephonyApp(this, PackageName)) { manager.release(); return; } else if (isWhitelist(PackageName)) { @@ -301,7 +301,7 @@ public void onNotificationPosted(StatusBarNotification sbn) { } } - public void sendTelecomNotification(Context context, Boolean isLogging, String address) { + public void sendTelecomNotification(Context context, Boolean isLogging, String address, String nickname) { if (prefs == null) { prefs = context.getSharedPreferences(Application.PREFS_NAME, MODE_PRIVATE); } @@ -320,6 +320,7 @@ public void sendTelecomNotification(Context context, Boolean isLogging, String a try { notificationBody.put("type", "send|telecom"); notificationBody.put("address", address); + notificationBody.put("nickname", nickname); notificationBody.put("package", PackageName); notificationBody.put("device_name", DEVICE_NAME); notificationBody.put("device_id", DEVICE_ID); @@ -335,7 +336,7 @@ public void sendTelecomNotification(Context context, Boolean isLogging, String a } } - public void sendSmsNotification(Context context, Boolean isLogging, String PackageName, String address, String message, Date time) { + public void sendSmsNotification(Context context, Boolean isLogging, String PackageName, String address, String nickname, String message, Date time) { String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(time); if (isSmsIntervalGaped(context, address, message, time)) { @@ -349,6 +350,7 @@ public void sendSmsNotification(Context context, Boolean isLogging, String Packa notificationBody.put("type", "send|sms"); notificationBody.put("message", message); notificationBody.put("address", address); + notificationBody.put("nickname", nickname); notificationBody.put("device_name", DEVICE_NAME); notificationBody.put("device_id", DEVICE_ID); notificationBody.put("date", date); diff --git a/app/src/main/java/com/noti/main/ui/OptionActivity.java b/app/src/main/java/com/noti/main/ui/OptionActivity.java index 71607c5..b6b7369 100644 --- a/app/src/main/java/com/noti/main/ui/OptionActivity.java +++ b/app/src/main/java/com/noti/main/ui/OptionActivity.java @@ -26,6 +26,7 @@ public class OptionActivity extends AppCompatActivity { boolean hideDefaultTitleBar = false; private static String title = "Default Message"; + private static String lastType = ""; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -34,8 +35,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { Fragment fragment; fragment = getSupportFragmentManager().findFragmentById(R.id.content_frame); - if(savedInstanceState == null || fragment == null) { - switch (getIntent().getStringExtra("Type")) { + if (savedInstanceState == null || fragment == null) { + String type = getIntent().getStringExtra("Type"); + if (type != null) lastType = type; + + switch (lastType) { case "Send": fragment = new SendPreference(); title = "Send Options"; @@ -94,7 +98,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { DynamicColors.applyToActivityIfAvailable(this); Bundle bundle = new Bundle(0); - if(fragment != null) { + if (fragment != null) { fragment.setArguments(bundle); getSupportFragmentManager() .beginTransaction() @@ -102,7 +106,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { .commit(); } - if(!hideDefaultTitleBar) { + if (!hideDefaultTitleBar) { MaterialToolbar toolbar = findViewById(R.id.toolbar); toolbar.setTitle(title); toolbar.setNavigationOnClickListener((v) -> this.finish()); diff --git a/app/src/main/java/com/noti/main/ui/receive/SmsViewActivity.java b/app/src/main/java/com/noti/main/ui/receive/SmsViewActivity.java index 367b001..b2b96d5 100644 --- a/app/src/main/java/com/noti/main/ui/receive/SmsViewActivity.java +++ b/app/src/main/java/com/noti/main/ui/receive/SmsViewActivity.java @@ -30,6 +30,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { String Topic = "/topics/" + getSharedPreferences(Application.PREFS_NAME,MODE_PRIVATE).getString("UID",""); String address = i.getStringExtra("address"); + String nickname = i.getStringExtra("nickname"); String message = i.getStringExtra("message"); String Device_name = i.getStringExtra("device_name"); String Date = i.getStringExtra("date"); @@ -42,7 +43,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { TextView TitleView = findViewById(R.id.titleDetail); String content = ""; - content += "From : " + address + "
"; + content += "From : " + address + (nickname == null || nickname.isEmpty() ? "" : " (" + nickname + ")") + "
"; content += "Date : " + Date + "
"; content += "Sent device : " + Device_name + "
"; content += "Message : " + message; diff --git a/app/src/main/java/com/noti/main/ui/receive/TelecomViewActivity.java b/app/src/main/java/com/noti/main/ui/receive/TelecomViewActivity.java index 48b566f..9d07732 100644 --- a/app/src/main/java/com/noti/main/ui/receive/TelecomViewActivity.java +++ b/app/src/main/java/com/noti/main/ui/receive/TelecomViewActivity.java @@ -33,6 +33,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { String Topic = "/topics/" + getSharedPreferences(Application.PREFS_NAME,MODE_PRIVATE).getString("UID",""); String address = i.getStringExtra("address"); + String nickname = i.getStringExtra("nickname"); String Device_name = i.getStringExtra("device_name"); String Date = i.getStringExtra("date"); String Package = i.getStringExtra("package"); @@ -44,7 +45,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { TextView TitleView = findViewById(R.id.titleDetail); String content = ""; - content += "From : " + address + "
"; + content += "From : " + address + (nickname == null || nickname.isEmpty() ? "" : " (" + nickname + ")") + "
"; content += "Date : " + Date + "
"; content += "Sent device : " + Device_name + "
"; ContentView.setText(Html.fromHtml(content));