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

Commit da990db6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't throw uri exceptions for user chosen sounds"

parents 3d5d5718 218871ee
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ public final class NotificationRecord {
    static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
    private static final int MAX_LOGTAG_LENGTH = 35;
    final StatusBarNotification sbn;
    IActivityManager mAm;
    final int mTargetSdkVersion;
    final int mOriginalFlags;
    private final Context mContext;
@@ -174,6 +175,7 @@ public final class NotificationRecord {
        this.sbn = sbn;
        mTargetSdkVersion = LocalServices.getService(PackageManagerInternal.class)
                .getPackageTargetSdkVersion(sbn.getPackageName());
        mAm = ActivityManager.getService();
        mOriginalFlags = sbn.getNotification().flags;
        mRankingTimeMs = calculateRankingTimeMs(0L);
        mCreationTimeMs = sbn.getPostTime();
@@ -1036,16 +1038,17 @@ public final class NotificationRecord {
     * Collect all {@link Uri} that should have permission granted to whoever
     * will be rendering it.
     */
    private void calculateGrantableUris() {
    protected void calculateGrantableUris() {
        final Notification notification = getNotification();
        notification.visitUris((uri) -> {
            visitGrantableUri(uri);
            visitGrantableUri(uri, false);
        });

        if (notification.getChannelId() != null) {
            NotificationChannel channel = getChannel();
            if (channel != null) {
                visitGrantableUri(channel.getSound());
                visitGrantableUri(channel.getSound(), (channel.getUserLockedFields()
                        & NotificationChannel.USER_LOCKED_SOUND) != 0);
            }
        }
    }
@@ -1058,18 +1061,17 @@ public final class NotificationRecord {
     * {@link #mGrantableUris}. Otherwise, this will either log or throw
     * {@link SecurityException} depending on target SDK of enqueuing app.
     */
    private void visitGrantableUri(Uri uri) {
    private void visitGrantableUri(Uri uri, boolean userOverriddenUri) {
        if (uri == null || !ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) return;

        // We can't grant Uri permissions from system
        final int sourceUid = sbn.getUid();
        if (sourceUid == android.os.Process.SYSTEM_UID) return;

        final IActivityManager am = ActivityManager.getService();
        final long ident = Binder.clearCallingIdentity();
        try {
            // This will throw SecurityException if caller can't grant
            am.checkGrantUriPermission(sourceUid, null,
            mAm.checkGrantUriPermission(sourceUid, null,
                    ContentProvider.getUriWithoutUserId(uri),
                    Intent.FLAG_GRANT_READ_URI_PERMISSION,
                    ContentProvider.getUserIdFromUri(uri, UserHandle.getUserId(sourceUid)));
@@ -1081,11 +1083,13 @@ public final class NotificationRecord {
        } catch (RemoteException ignored) {
            // Ignored because we're in same process
        } catch (SecurityException e) {
            if (!userOverriddenUri) {
                if (mTargetSdkVersion >= Build.VERSION_CODES.P) {
                    throw e;
                } else {
                    Log.w(TAG, "Ignoring " + uri + " from " + sourceUid + ": " + e.getMessage());
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
+3 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ public class UiServiceTestCase {

    protected static final String PKG_N_MR1 = "com.example.n_mr1";
    protected static final String PKG_O = "com.example.o";
    protected static final String PKG_P = "com.example.p";

    @Rule
    public final TestableContext mContext =
@@ -57,6 +58,8 @@ public class UiServiceTestCase {
                            return Build.VERSION_CODES.N_MR1;
                        case PKG_O:
                            return Build.VERSION_CODES.O;
                        case PKG_P:
                            return Build.VERSION_CODES.P;
                        default:
                            return Build.VERSION_CODES.CUR_DEVELOPMENT;
                    }
+104 −50

File changed.

Preview size limit exceeded, changes collapsed.