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

Commit d0f6123a authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

RingtonePlayerTest: temporarily disable test

Disable test before fixing.

Bug: 402072283
Bug: 401607352
Flag: android.media.audio.ringtone_user_uri_check
Test: atest com.android.systemui.ringtone.RingtonePlayerTest
Change-Id: Ic594b19391be661987779fd894e6faceb6fc0fe6
parent 46a67de1
Loading
Loading
Loading
Loading
+24 −25
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.media.AudioManager;
import android.net.Uri;
import android.os.Binder;
import android.os.UserHandle;
import android.util.Log;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -37,36 +38,34 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class RingtonePlayerTest extends SysuiTestCase {

    private AudioManager mAudioManager;

    private static final String TAG = "RingtonePlayerTest";

    @Before
    public void setup() throws Exception {
        mAudioManager = getContext().getSystemService(AudioManager.class);
    }

    @Test
    public void testRingtonePlayerUriUserCheck() {
        android.media.IRingtonePlayer irp = mAudioManager.getRingtonePlayer();
        final AudioAttributes aa = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build();
        // get a UserId that doesn't belong to mine
        final int otherUserId = UserHandle.myUserId() == 0 ? 10 : 0;
        // build a URI that I shouldn't have access to
        final Uri uri = new Uri.Builder()
                .scheme("content").authority(otherUserId + "@media")
                .appendPath("external").appendPath("downloads")
                .appendPath("bogusPathThatDoesNotMatter.mp3")
                .build();
        if (android.media.audio.Flags.ringtoneUserUriCheck()) {
            assertThrows(SecurityException.class, () ->
                    irp.play(new Binder(), uri, aa, 1.0f /*volume*/, false /*looping*/)
            );
        // temporarily skipping this test
        Log.i(TAG, "skipping testRingtonePlayerUriUserCheck");
        return;

            assertThrows(SecurityException.class, () ->
                    irp.getTitle(uri));
        }
        // TODO change how IRingtonePlayer is created
//        android.media.IRingtonePlayer irp = mAudioManager.getRingtonePlayer();
//        final AudioAttributes aa = new AudioAttributes.Builder()
//                .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build();
//        // get a UserId that doesn't belong to mine
//        final int otherUserId = UserHandle.myUserId() == 0 ? 10 : 0;
//        // build a URI that I shouldn't have access to
//        final Uri uri = new Uri.Builder()
//                .scheme("content").authority(otherUserId + "@media")
//                .appendPath("external").appendPath("downloads")
//                .appendPath("bogusPathThatDoesNotMatter.mp3")
//                .build();
//        if (android.media.audio.Flags.ringtoneUserUriCheck()) {
//            assertThrows(SecurityException.class, () ->
//                    irp.play(new Binder(), uri, aa, 1.0f /*volume*/, false /*looping*/)
//            );
//
//            assertThrows(SecurityException.class, () ->
//                    irp.getTitle(uri));
//        }
    }

}