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

Commit 65c4a2b2 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Multi-user ringtone playback.

Change RingtonePlayer to open content:// Uris based on requesting
UserHandle.  Grant SystemUI visibility to all emulated storage so
it can play ringtones for apps without READ_EXTERNAL_STORAGE.

Resolve canonical file:// Uris before passing out of source app,
replacing any /emulated_legacy/-style paths with user-specific
variant so they can be opened by SystemUI.  Calling for RemoteViews,
Ringtones, and Notifications.

Bug: 7202982
Change-Id: Ibf0eca8df80c1486711144a7b648f464aadfe099
parent 5e21bf93
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -124,6 +124,9 @@ public class NotificationManager
        int[] idOut = new int[1];
        INotificationManager service = getService();
        String pkg = mContext.getPackageName();
        if (notification.sound != null) {
            notification.sound = notification.sound.getCanonicalUri();
        }
        if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
        try {
            service.enqueueNotificationWithTag(pkg, tag, id, notification, idOut,
@@ -143,6 +146,9 @@ public class NotificationManager
        int[] idOut = new int[1];
        INotificationManager service = getService();
        String pkg = mContext.getPackageName();
        if (notification.sound != null) {
            notification.sound = notification.sound.getCanonicalUri();
        }
        if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
        try {
            service.enqueueNotificationWithTag(pkg, tag, id, notification, idOut,
+38 −0
Original line number Diff line number Diff line
@@ -16,10 +16,13 @@

package android.net;

import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Environment.UserEnvironment;
import android.util.Log;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charsets;
@@ -2288,4 +2291,39 @@ public abstract class Uri implements Parcelable, Comparable<Uri> {
        builder = builder.appendEncodedPath(pathSegment);
        return builder.build();
    }

    /**
     * If this {@link Uri} is {@code file://}, then resolve and return its
     * canonical path. Also fixes legacy emulated storage paths so they are
     * usable across user boundaries. Should always be called from the app
     * process before sending elsewhere.
     *
     * @hide
     */
    public Uri getCanonicalUri() {
        if ("file".equals(getScheme())) {
            final String canonicalPath;
            try {
                canonicalPath = new File(getPath()).getCanonicalPath();
            } catch (IOException e) {
                return this;
            }

            if (Environment.isExternalStorageEmulated()) {
                final String legacyPath = Environment.getLegacyExternalStorageDirectory()
                        .toString();

                // Splice in user-specific path when legacy path is found
                if (canonicalPath.startsWith(legacyPath)) {
                    return Uri.fromFile(new File(
                            Environment.getExternalStorageDirectory().toString(),
                            canonicalPath.substring(legacyPath.length() + 1)));
                }
            }

            return Uri.fromFile(new File(canonicalPath));
        } else {
            return this;
        }
    }
}
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2012, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;

parcelable UserHandle;
+2 −0
Original line number Diff line number Diff line
@@ -2166,6 +2166,8 @@ public class RemoteViews implements Parcelable, Filter {
     * @param value The value to pass to the method.
     */
    public void setUri(int viewId, String methodName, Uri value) {
        // Resolve any filesystem path before sending remotely
        value = value.getCanonicalUri();
        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.URI, value));
    }

+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.media;

import android.net.Uri;
import android.os.UserHandle;

/**
 * @hide
@@ -28,6 +29,6 @@ interface IRingtonePlayer {
    boolean isPlaying(IBinder token);

    /** Used for Notification sound playback. */
    void playAsync(in Uri uri, boolean looping, int streamType);
    void playAsync(in Uri uri, in UserHandle user, boolean looping, int streamType);
    void stopAsync();
}
Loading