summaryrefslogtreecommitdiff
path: root/src/com/android/documentsui
diff options
context:
space:
mode:
author Ben Reich <benreich@google.com> 2025-04-09 11:02:01 +1000
committer Kampalus <kampalus@protonmail.ch> 2025-09-18 12:17:18 +0200
commitd40c037bccbae7537698968c1650a633710c5b6e (patch)
tree29a85b8012c33bd81e9eb5c8de6d2f5a846cf4df /src/com/android/documentsui
parentb0f64324499a3f65aca817d3f221c716d953a800 (diff)
[SP 2025-09-01] Trim the application name to make it safe for presentationbanksia-dev
The application name is presented in the ConfirmFragment and as such we don't want to allow for any length. This follows a similar approach to PackageManager using the TextUtils.makeSafeForPresentation with a total available character length of 500. This removes the unused getCallingAppName from the DirectoryFragment as it was causing false positives from DirectoryFragment to avoid false positives when trying to find who calls the Shared function. On top of this, add some quotation marks around the app name to avoid the app name being a contination of the existing text in the dialog, e.g. 'This will let app name access current and future content storage in Alarms' will now be 'This will let "app name" access current and future content storage'. Bug: 397216537 Test: atest com.android.documentsui.picker.ApplicationNameTest Flag: EXEMPT bug fix Change-Id: Iad0d03de09b1e4ad953bd6bd46a619cfcc56d384 (cherry picked from commit c8ef2db3bb4645704384226976e59583b9e8d3d3)
Diffstat (limited to 'src/com/android/documentsui')
-rw-r--r--src/com/android/documentsui/base/Shared.java12
-rw-r--r--src/com/android/documentsui/dirlist/DirectoryFragment.java5
-rw-r--r--src/com/android/documentsui/dirlist/DocumentsAdapter.java1
3 files changed, 10 insertions, 8 deletions
diff --git a/src/com/android/documentsui/base/Shared.java b/src/com/android/documentsui/base/Shared.java
index ac089999f..bb8a39393 100644
--- a/src/com/android/documentsui/base/Shared.java
+++ b/src/com/android/documentsui/base/Shared.java
@@ -16,6 +16,9 @@
package com.android.documentsui.base;
+import static android.text.TextUtils.SAFE_STRING_FLAG_SINGLE_LINE;
+import static android.text.TextUtils.SAFE_STRING_FLAG_TRIM;
+
import static com.android.documentsui.base.SharedMinimal.TAG;
import static com.android.documentsui.ChangeIds.RESTRICT_STORAGE_ACCESS_FRAMEWORK;
@@ -265,7 +268,7 @@ public final class Shared {
* @return the calling app name or general anonymous name if not found
*/
@NonNull
- public static String getCallingAppName(Activity activity) {
+ public static CharSequence getCallingAppName(Activity activity) {
final String anonymous = activity.getString(R.string.anonymous_application);
final String packageName = getCallingPackageName(activity);
if (TextUtils.isEmpty(packageName)) {
@@ -281,7 +284,12 @@ public final class Shared {
}
CharSequence result = pm.getApplicationLabel(ai);
- return TextUtils.isEmpty(result) ? anonymous : result.toString();
+ if (TextUtils.isEmpty(result)) {
+ return anonymous;
+ }
+
+ return TextUtils.makeSafeForPresentation(
+ result.toString(), 500, 0, SAFE_STRING_FLAG_TRIM | SAFE_STRING_FLAG_SINGLE_LINE);
}
/**
diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java
index 2911d04e9..ae728f616 100644
--- a/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -1634,10 +1634,5 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
public ActionHandler getActionHandler() {
return mActions;
}
-
- @Override
- public String getCallingAppName() {
- return Shared.getCallingAppName(mActivity);
- }
}
}
diff --git a/src/com/android/documentsui/dirlist/DocumentsAdapter.java b/src/com/android/documentsui/dirlist/DocumentsAdapter.java
index 41ce73c8c..b32c15335 100644
--- a/src/com/android/documentsui/dirlist/DocumentsAdapter.java
+++ b/src/com/android/documentsui/dirlist/DocumentsAdapter.java
@@ -90,7 +90,6 @@ public abstract class DocumentsAdapter extends RecyclerView.Adapter<DocumentHold
boolean isInSearchMode();
boolean isSelected(String id);
Model getModel();
- String getCallingAppName();
boolean isDocumentEnabled(String mimeType, int flags);
void initDocumentHolder(DocumentHolder holder);
void onBindDocumentHolder(DocumentHolder holder, Cursor cursor);