From 8d10bf05af4f755305b679560591d250f71bdc9d Mon Sep 17 00:00:00 2001 From: Jens Date: Thu, 19 Oct 2023 22:30:13 +0200 Subject: [PATCH] Escaped variables when triggering --- .../jens/automation2/AutomationService.java | 7 ++- .../com/jens/automation2/Miscellaneous.java | 40 ++++++++++++++++-- .../main/res/drawable-hdpi/ic_launcher.png | Bin 0 -> 2864 bytes .../main/res/drawable-ldpi/ic_launcher.png | Bin 0 -> 1418 bytes .../ic_launcher.png | Bin 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_launcher.png create mode 100644 app/src/main/res/drawable-ldpi/ic_launcher.png rename app/src/main/res/{drawable => drawable-mdpi}/ic_launcher.png (100%) diff --git a/app/src/main/java/com/jens/automation2/AutomationService.java b/app/src/main/java/com/jens/automation2/AutomationService.java index 4d107c7..8f04a96 100644 --- a/app/src/main/java/com/jens/automation2/AutomationService.java +++ b/app/src/main/java/com/jens/automation2/AutomationService.java @@ -578,7 +578,12 @@ public class AutomationService extends Service implements OnInitListener builder.setOnlyAlertOnce(true); if(Settings.showIconWhenServiceIsRunning) - builder.setSmallIcon(R.drawable.crane); + { + if (BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay)) + builder.setSmallIcon(R.drawable.crane); + else + builder.setSmallIcon(R.drawable.ic_launcher); + } // builder.setContentText(textToDisplay); // builder.setSmallIcon(icon); diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index 3ec8c11..4275f26 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -70,6 +70,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.lang.Thread.UncaughtExceptionHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -77,6 +78,8 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.security.DigestInputStream; import java.security.KeyManagementException; import java.security.KeyStore; @@ -708,7 +711,7 @@ public class Miscellaneous extends Service String notificationTitle = NotificationListener.getLastNotification().getTitle(); if (notificationTitle != null && notificationTitle.length() > 0) - source = source.replace("[notificationTitle]", notificationTitle); + source = source.replace("[notificationTitle]", escapeStringForUrl(notificationTitle)); else { source = source.replace("[notificationTitle]", "notificationTitle unknown"); @@ -729,7 +732,7 @@ public class Miscellaneous extends Service String notificationText = NotificationListener.getLastNotification().getText(); if (notificationText != null && notificationText.length() > 0) - source = source.replace("[notificationText]", notificationText); + source = source.replace("[notificationText]", escapeStringForUrl(notificationText)); else { source = source.replace("[notificationText]", "notificationText unknown"); @@ -760,7 +763,7 @@ public class Miscellaneous extends Service else replacement = "unknownVariable"; - source = source.substring(0, pos1) + replacement + source.substring(pos2 +1); + source = source.substring(0, pos1) + escapeStringForUrl(replacement) + source.substring(pos2 +1); } // Miscellaneous.logEvent("i", "URL after replace", source); @@ -1164,7 +1167,12 @@ public class Miscellaneous extends Service builder.setOnlyAlertOnce(true); if(Settings.showIconWhenServiceIsRunning && notificationChannelId.equals(AutomationService.NOTIFICATION_CHANNEL_ID_SERVICE)) - builder.setSmallIcon(R.drawable.crane); + { + if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay)) + builder.setSmallIcon(R.drawable.crane); + else + builder.setSmallIcon(R.drawable.ic_launcher); + } else if(!notificationChannelId.equals(AutomationService.NOTIFICATION_CHANNEL_ID_SERVICE)) builder.setSmallIcon(R.drawable.info); @@ -2034,4 +2042,28 @@ public class Miscellaneous extends Service //startActivity(refresh); } } + + public static String escapeStringForUrl(String input) + { + String output; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) + { + try + { + output = URLEncoder.encode(input, String.valueOf(StandardCharsets.UTF_8)); + } + catch (UnsupportedEncodingException e) + { + Miscellaneous.logEvent("e", "URLEncoder", "Error encoding string for URL. Leaving as it is. Error details: " + Log.getStackTraceString(e), 3); + output = input; + } + } + else + { + output = Uri.encode(input); + } + + return output; + } } \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..b6bbc16df44c95f37d036a1252d59b71ca8750bb GIT binary patch literal 2864 zcmV-03(xe4P)Lf5{#m^ParV0btnI6MbIRuq_F28MYLFf*s;yPokeb1&Qr12Zt5o zz32SjchC7B=l*w=EP39Zx94pUwUExv&Q}Kq2Y){@GV+nhWV&uPn^iWOP33aAoP;%e z#&U6qn3P@Wv zXd@b%gZQeMCS9cXp^eyR-xvd9Ef}(H+_({;(P%O!CMK-z*^=01Bp);zh|5O=WvI;L zw~8^YKa7E~Feb(hSYj?;zPxN;U?5?9e0L;GLzpljPctRDh~S3g!7Tm6-1l@T^&^#$>Awx zBXoc+&PrsC^!CLt;UY0~7S(IVIq-dE2g&QRa!YS#)hPLPsg}Hc zZJ3j9Ue}U${x?G6ZyU(RJr>eVXA7>mPp`pw_&Z&LPS6cH`o##>)YNP;7z|xbr&ILu z$h~JFJ1Fp9*6GRClHtdMh>`beM#<0QqvS-JN%VNo4LU;C`847ob#--7G(J&FaoGyp z1c{{}rI5lWKdBrc?SLi$+B!x6JHT{SNa7MA@z@DUano0Ea;aQX87RJSmAJJuu7#Ng*??FV4+jc4k4d8T%p`#%U;q}Ml9ZgBymDx0s8g&#hPo*oCND7XVt=Nd=?7&x$wX|E zX~`d(44e(}JO)qbbcr|IzyeIZ;wMz4QsqxhiVyOthsV9V6#nlH?kd!F$pq!okN{0h z14V=ZPaoStrLf;7T0dav?(WV9wpj;(wY9asp!t;O!C^RmS~bFJSXC^NuAu~Okw{R% zr`E@j^qVrR*YUUL>>M2zA94T_b^m*36-=Hyd2;OVHz$(?Ny+E10D#b9P6%W|_N)F^>3CqlFuz?kr zMbDn}^z_X-ole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HcmV?d00001 diff --git a/app/src/main/res/drawable/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png similarity index 100% rename from app/src/main/res/drawable/ic_launcher.png rename to app/src/main/res/drawable-mdpi/ic_launcher.png