From 1259beab2b8fc2e1697617b4e030fc69fb8ac5b5 Mon Sep 17 00:00:00 2001 From: Ben Reich Date: Wed, 9 Apr 2025 11:02:01 +1000 Subject: [PATCH 1/3] Trim the application name to make it safe for presentation 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 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c8ef2db3bb4645704384226976e59583b9e8d3d3) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:9ed806f492cb7a8e2360c5c09caac87cb5d0f823) Merged-In: Iad0d03de09b1e4ad953bd6bd46a619cfcc56d384 Change-Id: Iad0d03de09b1e4ad953bd6bd46a619cfcc56d384 --- res/values/strings.xml | 2 +- src/com/android/documentsui/base/Shared.java | 12 ++- .../dirlist/DirectoryFragment.java | 5 - .../documentsui/dirlist/DocumentsAdapter.java | 1 - .../documentsui/dirlist/TestEnvironment.java | 5 - .../documentsui/picker/ApplicationNameTest.kt | 91 +++++++++++++++++++ 6 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 tests/unit/com/android/documentsui/picker/ApplicationNameTest.kt diff --git a/res/values/strings.xml b/res/values/strings.xml index a1d6982fd..bc23b22d2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -520,7 +520,7 @@ Allow %1$s to access files in %2$s? - This will let %1$s access current and future content stored in %2$s. + This will let "%1$s" access current and future content stored in %2$s. Can\u2019t use this folder diff --git a/src/com/android/documentsui/base/Shared.java b/src/com/android/documentsui/base/Shared.java index 5ac9de4d7..9f328be69 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 android.app.Activity; @@ -276,7 +279,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)) { @@ -292,7 +295,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 a5306bd97..cda3e1f91 100644 --- a/src/com/android/documentsui/dirlist/DirectoryFragment.java +++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java @@ -1495,10 +1495,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 + + @Before + fun setUp() { + MockitoAnnotations.openMocks(this) + whenever(mockActivity.resources).thenReturn(resources) + whenever(mockActivity.packageManager).thenReturn(pm) + whenever(resources.getString(R.string.anonymous_application)).thenReturn(ANONYMOUS_PACKAGE) + whenever(mockActivity.callingPackage).thenReturn(PACKAGE_NAME) + } + + @Test + fun testNameIsSanitized() { + val info = ApplicationInfo() + whenever(pm.getApplicationInfo(PACKAGE_NAME, 0)).thenReturn(info) + + whenever(pm.getApplicationLabel(eq(info))).thenReturn(testData.first) + assertEquals(Shared.getCallingAppName(mockActivity), testData.second) + } +} -- GitLab From 4e86c9697c3d1bfe815d57337dc9fad032776f31 Mon Sep 17 00:00:00 2001 From: LineageOS Infra Date: Fri, 1 Aug 2025 19:44:56 +0000 Subject: [PATCH 2/3] Automatic translation import Change-Id: Ib4dcbd448627fe7aa3406e7176d948e8ee498c8b --- res/values-ug/lineage_strings.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 res/values-ug/lineage_strings.xml diff --git a/res/values-ug/lineage_strings.xml b/res/values-ug/lineage_strings.xml new file mode 100644 index 000000000..217313157 --- /dev/null +++ b/res/values-ug/lineage_strings.xml @@ -0,0 +1,18 @@ + + + + قوزغاتقۇچ تېزلەتمىسىنى قوش + -- GitLab From 2de5344d31a0124e7e7b811e4cb731f6e04b6e8d Mon Sep 17 00:00:00 2001 From: LineageOS Infra Date: Mon, 1 Sep 2025 17:00:03 +0000 Subject: [PATCH 3/3] Automatic translation import Change-Id: Ib9a3eec9dc9706240be7e4ff6dca48d619986c8e --- res/values-iw/lineage_strings.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 res/values-iw/lineage_strings.xml diff --git a/res/values-iw/lineage_strings.xml b/res/values-iw/lineage_strings.xml new file mode 100644 index 000000000..64b745b58 --- /dev/null +++ b/res/values-iw/lineage_strings.xml @@ -0,0 +1,18 @@ + + + + הוספת קיצור דרך למסך הפעלה + -- GitLab