Skip to content

Commit

Permalink
Show names stored in Contacts when telephony synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
choiman1559 committed Apr 1, 2023
1 parent c8d78c8 commit 50e5f23
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.VisibleForTesting;

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,15 @@ protected void sendFindTaskNotification() {
protected void sendTelecomNotification(Map<String, String> 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");

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);
Expand All @@ -525,7 +527,7 @@ protected void sendTelecomNotification(Map<String, String> 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)
Expand All @@ -551,6 +553,7 @@ protected void sendTelecomNotification(Map<String, String> map) {

protected void sendSmsNotification(Map<String, String> 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");
Expand All @@ -561,6 +564,7 @@ protected void sendSmsNotification(Map<String, String> 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);
Expand All @@ -580,7 +584,7 @@ protected void sendSmsNotification(Map<String, String> 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)
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/noti/main/service/NotiListenerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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)) {
Expand All @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/com/noti/main/ui/OptionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
Expand Down Expand Up @@ -94,15 +98,15 @@ 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()
.replace(R.id.content_frame, fragment)
.commit();
}

if(!hideDefaultTitleBar) {
if (!hideDefaultTitleBar) {
MaterialToolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(title);
toolbar.setNavigationOnClickListener((v) -> this.finish());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -42,7 +43,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
TextView TitleView = findViewById(R.id.titleDetail);

String content = "";
content += "<b>From</b> : " + address + "<br>";
content += "<b>From</b> : " + address + (nickname == null || nickname.isEmpty() ? "" : " (" + nickname + ")") + "<br>";
content += "<b>Date</b> : " + Date + "<br>";
content += "<b>Sent device</b> : " + Device_name + "<br>";
content += "<b>Message</b> : " + message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -44,7 +45,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
TextView TitleView = findViewById(R.id.titleDetail);

String content = "";
content += "<b>From</b> : " + address + "<br>";
content += "<b>From</b> : " + address + (nickname == null || nickname.isEmpty() ? "" : " (" + nickname + ")") + "<br>";
content += "<b>Date</b> : " + Date + "<br>";
content += "<b>Sent device</b> : " + Device_name + "<br>";
ContentView.setText(Html.fromHtml(content));
Expand Down

0 comments on commit 50e5f23

Please sign in to comment.