aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfionaxu <fionaxu@google.com>2016-06-28 01:14:05 -0700
committerJessica Wagantall <jwagantall@cyngn.com>2016-09-12 15:12:58 -0700
commit2605685e9c0452a893d02737c2efb9441b30781f (patch)
tree920b57cf0f1ee4de4f08865883413c466e23276a
parent95a09a1eb66249bb7bae0e30841b0d055c5e2ecd (diff)
downloadandroid_frameworks_opt_telephony-stable/cm-12.1-YOG4P.tar.gz
android_frameworks_opt_telephony-stable/cm-12.1-YOG4P.tar.bz2
android_frameworks_opt_telephony-stable/cm-12.1-YOG4P.zip
DO NOT MERGE add private function converSafeLabelstable/cm-12.1-YOG4P
CYNGNOS-3235 Bug: 28557603 Change-Id: I4618013bd07b697063872e51ae3d88aa59a2864e
-rw-r--r--src/java/com/android/internal/telephony/SMSDispatcher.java53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/java/com/android/internal/telephony/SMSDispatcher.java b/src/java/com/android/internal/telephony/SMSDispatcher.java
index dc806beb3..75b55738a 100644
--- a/src/java/com/android/internal/telephony/SMSDispatcher.java
+++ b/src/java/com/android/internal/telephony/SMSDispatcher.java
@@ -15,6 +15,7 @@
*/
package com.android.internal.telephony;
+import android.annotation.NonNull;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
@@ -52,6 +53,7 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.Html;
import android.text.Spanned;
+import android.text.TextPaint;
import android.text.TextUtils;
import android.util.EventLog;
import android.view.LayoutInflater;
@@ -88,6 +90,7 @@ public abstract class SMSDispatcher extends Handler {
static final String TAG = "SMSDispatcher"; // accessed from inner class
static final boolean DBG = false;
private static final String SEND_NEXT_MSG_EXTRA = "SendNextMsg";
+ private static final float MAX_LABEL_SIZE_PX = 500f;
/** Permission required to send SMS to short codes without user confirmation. */
private static final String SEND_RESPOND_VIA_MESSAGE_PERMISSION =
@@ -1228,7 +1231,8 @@ public abstract class SMSDispatcher extends Handler {
PackageManager pm = mContext.getPackageManager();
try {
ApplicationInfo appInfo = pm.getApplicationInfo(appPackage, 0);
- return appInfo.loadLabel(pm);
+ String label = appInfo.loadLabel(pm).toString();
+ return convertSafeLabel(label, appPackage);
} catch (PackageManager.NameNotFoundException e) {
Rlog.e(TAG, "PackageManager Name Not Found for package " + appPackage);
return appPackage; // fall back to package name if we can't get app label
@@ -1282,6 +1286,53 @@ public abstract class SMSDispatcher extends Handler {
d.show();
}
+ /**
+ * Check appLabel with the addition that the returned label is safe for being presented
+ * in the UI since it will not contain new lines and the length will be limited to a
+ * reasonable amount. This prevents a malicious party to influence UI
+ * layout via the app label misleading the user into performing a
+ * detrimental for them action. If the label is too long it will be
+ * truncated and ellipsized at the end.
+ *
+ * @param label A string of appLabel from PackageItemInfo#loadLabel
+ * @param appPackage the package name of the app requesting to send an SMS
+ * @return Returns a CharSequence containing the item's label. If the
+ * item does not have a label, its name is returned.
+ */
+ private CharSequence convertSafeLabel(@NonNull String labelStr, String appPackage) {
+ // If the label contains new line characters it may push the UI
+ // down to hide a part of it. Labels shouldn't have new line
+ // characters, so just truncate at the first time one is seen.
+ final int labelLength = labelStr.length();
+ int offset = 0;
+ while (offset < labelLength) {
+ final int codePoint = labelStr.codePointAt(offset);
+ final int type = Character.getType(codePoint);
+ if (type == Character.LINE_SEPARATOR
+ || type == Character.CONTROL
+ || type == Character.PARAGRAPH_SEPARATOR) {
+ labelStr = labelStr.substring(0, offset);
+ break;
+ }
+ // replace all non-break space to " " in order to be trimmed
+ if (type == Character.SPACE_SEPARATOR) {
+ labelStr = labelStr.substring(0, offset) + " " + labelStr.substring(offset +
+ Character.charCount(codePoint));
+ }
+ offset += Character.charCount(codePoint);
+ }
+
+ labelStr = labelStr.trim();
+ if (labelStr.isEmpty()) {
+ return appPackage;
+ }
+ TextPaint paint = new TextPaint();
+ paint.setTextSize(42);
+
+ return TextUtils.ellipsize(labelStr, paint, MAX_LABEL_SIZE_PX,
+ TextUtils.TruncateAt.END);
+ }
+
/**
* Post an alert for user confirmation when sending to a potential short code.
* @param isPremium true if the destination is known to be a premium short code