Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35a75b24 authored by Ben Reich's avatar Ben Reich Committed by Android Build Coastguard Worker
Browse files

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 commit c8ef2db3)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:a74695f75d269a0caf2885d52833489eb97e2f72)
Merged-In: Iad0d03de09b1e4ad953bd6bd46a619cfcc56d384
Change-Id: Iad0d03de09b1e4ad953bd6bd46a619cfcc56d384
parent aa062320
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -575,7 +575,7 @@
    <!-- Confrim dialog title show on open document tree flow. [CHAR_LIMIT=80] -->
    <string name="open_tree_dialog_title">Allow <xliff:g id="appName" example="Drive">%1$s</xliff:g> to access files in <xliff:g id="directory" example="DCIM">%2$s</xliff:g>?</string>
    <!-- Confrim dialog message show on open document tree flow.-->
    <string name="open_tree_dialog_message">This will let <xliff:g id="appName" example="Drive">%1$s</xliff:g> access current and future content stored in <xliff:g id="directory" example="DCIM">%2$s</xliff:g>.</string>
    <string name="open_tree_dialog_message">This will let "<xliff:g id="appName" example="Drive">%1$s</xliff:g>" access current and future content stored in <xliff:g id="directory" example="DCIM">%2$s</xliff:g>.</string>
    <!-- Header message title show on open document tree flow when directory is blocked. [CHAR_LIMIT=48] -->
    <string name="directory_blocked_header_title">Can\u2019t use this folder</string>
    <!-- Header message subtitle show on open document tree flow when directory is blocked. [CHAR_LIMIT=90]-->
+10 −2
Original line number Diff line number Diff line
@@ -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);
    }

    /**
+0 −5
Original line number Diff line number Diff line
@@ -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);
        }
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -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);
+0 −5
Original line number Diff line number Diff line
@@ -88,9 +88,4 @@ public final class TestEnvironment implements DocumentsAdapter.Environment {
    @Override
    public void onBindDocumentHolder(DocumentHolder holder, Cursor cursor) {
    }

    @Override
    public String getCallingAppName() {
        return "unknown";
    }
}
Loading