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

Commit 567e7995 authored by Eric Laurent's avatar Eric Laurent Committed by Automerger Merge Worker
Browse files

Merge "Fix the string reference equality comparison in MusicFxHelper" into main am: 9f83523d

parents 3919403f 9f83523d
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@ public class MusicFxHelper {
     *    observer will also be removed, and observer token reset to null
     */
    private class MySparseArray extends SparseArray<PackageSessions> {
        private final String mMusicFxPackageName = "com.android.musicfx";

        @RequiresPermission(anyOf = {
                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
@@ -235,6 +234,10 @@ public class MusicFxHelper {
        if (ril != null && ril.size() != 0) {
            ResolveInfo ri = ril.get(0);
            final String senderPackageName = intent.getStringExtra(AudioEffect.EXTRA_PACKAGE_NAME);
            if (senderPackageName == null) {
                Log.w(TAG, "Intent package name must not be null");
                return;
            }
            try {
                if (ri != null && ri.activityInfo != null && ri.activityInfo.packageName != null) {
                    final int senderUid = pm.getPackageUidAsUser(senderPackageName,
@@ -271,7 +274,7 @@ public class MusicFxHelper {
                        + senderUid + ", package: " + senderPackageName + ", abort");
                return false;
            }
            if (pkgSessions.mPackageName != senderPackageName) {
            if (!pkgSessions.mPackageName.equals(senderPackageName)) {
                Log.w(TAG, "Inconsistency package names for UID open: " + senderUid + " prev: "
                        + pkgSessions.mPackageName + ", now: " + senderPackageName);
                return false;
@@ -303,7 +306,7 @@ public class MusicFxHelper {
            Log.e(TAG, senderPackageName + " UID " + senderUid + " does not exist in map, abort");
            return false;
        }
        if (pkgSessions.mPackageName != senderPackageName) {
        if (!pkgSessions.mPackageName.equals(senderPackageName)) {
            Log.w(TAG, "Inconsistency package names for UID " + senderUid + " close, prev: "
                    + pkgSessions.mPackageName + ", now: " + senderPackageName);
            return false;
+62 −18
Original line number Diff line number Diff line
@@ -57,8 +57,9 @@ public class MusicFxHelperTest {

    private ResolveInfo mResolveInfo1 = new ResolveInfo();
    private ResolveInfo mResolveInfo2 = new ResolveInfo();
    private final String mTestPkg1 = "testPkg1", mTestPkg2 = "testPkg2", mTestPkg3 = "testPkg3";
    private final String mMusicFxPkgName = "com.android.musicfx";
    private final String mTestPkg1 = new String("testPkg1"), mTestPkg2 = new String("testPkg2"),
            mTestPkg3 = new String("testPkg3"), mTestPkg1Equivalent = new String("testPkg1");
    private final String mMusicFxPkgName = new String("com.android.musicfx");
    private final int mTestUid1 = 1, mTestUid2 = 2, mTestUid3 = 3, mMusicFxUid = 78;
    private final int mTestSession1 = 11, mTestSession2 = 22, mTestSession3 = 33;

@@ -191,7 +192,8 @@ public class MusicFxHelperTest {
    public void testCloseBroadcastIntent() {
        Log.i(TAG, "running testCloseBroadcastIntent");

        closeSessionWithResList(null, 0, 0, null, mTestSession1, mTestUid1);
        closeSessionWithResList(null, 0 /* unbind */, 0 /* broadcast */, null /* packageName */,
                mTestSession1, mTestUid1);
    }

    /**
@@ -225,8 +227,10 @@ public class MusicFxHelperTest {
    public void testBroadcastIntentWithNoPackageAndNoBroadcastReceiver() {
        Log.i(TAG, "running testBroadcastIntentWithNoPackageAndNoBroadcastReceiver");

        openSessionWithResList(mEmptyList, 0, 0, null, mTestSession1, mTestUid1);
        closeSessionWithResList(mEmptyList, 0, 0, null, mTestSession1, mTestUid1);
        openSessionWithResList(mEmptyList, 0 /* bind */, 0 /* broadcast */, null /* packageName */,
                mTestSession1, mTestUid1);
        closeSessionWithResList(mEmptyList, 0 /* unbind */, 0 /* broadcast */,
                null /* packageName */, mTestSession1, mTestUid1);
    }

    /**
@@ -236,37 +240,63 @@ public class MusicFxHelperTest {
    public void testBroadcastIntentWithNoPackageAndOneBroadcastReceiver() {
        Log.i(TAG, "running testBroadcastIntentWithNoPackageAndOneBroadcastReceiver");

        openSessionWithResList(mSingleList, 0 /* bind */, 0 /* broadcast */,
                null /* packageName */, mTestSession1, mTestUid1);
        closeSessionWithResList(mSingleList, 0 /* unbind */, 0 /* broadcast */,
                null /* packageName */, mTestSession1, mTestUid1);
    }

    /**
     * OPEN/CLOSE AUDIO_EFFECT_CONTROL_SESSION with two broadcast receivers.
     */
    @Test
    public void testBroadcastIntentWithNoPackageAndTwoBroadcastReceivers() {
        Log.i(TAG, "running testBroadcastIntentWithNoPackageAndTwoBroadcastReceivers");

        openSessionWithResList(mDoubleList, 0 /* bind */, 0 /* broadcast */,
                null /* packageName */, mTestSession1, mTestUid1);
        closeSessionWithResList(mDoubleList, 0 /* bind */, 0 /* broadcast */,
                null /* packageName */, mTestSession1, mTestUid1);
    }

    @Test
    public void testBroadcastIntentWithPackageAndOneBroadcastReceiver() {
        Log.i(TAG, "running testBroadcastIntentWithPackageAndOneBroadcastReceiver");

        int broadcasts = 1, bind = 1, unbind = 1;
        openSessionWithResList(mSingleList, bind, broadcasts, null, mTestSession1, mTestUid1);
        openSessionWithResList(mSingleList, bind, broadcasts, mTestPkg1, mTestSession1, mTestUid1);

        broadcasts = broadcasts + 1;
        closeSessionWithResList(mSingleList, unbind, broadcasts, null, mTestSession1, mTestUid1);
        closeSessionWithResList(mSingleList, unbind, broadcasts, mTestPkg1, mTestSession1,
                mTestUid1);

        // repeat with different session ID
        broadcasts = broadcasts + 1;
        bind = bind + 1;
        unbind = unbind + 1;
        openSessionWithResList(mSingleList, bind, broadcasts, null, mTestSession2, mTestUid1);
        openSessionWithResList(mSingleList, bind, broadcasts, mTestPkg2, mTestSession2, mTestUid1);
        broadcasts = broadcasts + 1;
        closeSessionWithResList(mSingleList, unbind, broadcasts, null, mTestSession2, mTestUid1);
        closeSessionWithResList(mSingleList, unbind, broadcasts, mTestPkg2, mTestSession2,
                mTestUid1);

        // repeat with different UID
        broadcasts = broadcasts + 1;
        bind = bind + 1;
        unbind = unbind + 1;
        openSessionWithResList(mSingleList, bind, broadcasts, null, mTestSession1, mTestUid2);
        openSessionWithResList(mSingleList, bind, broadcasts, mTestPkg3, mTestSession1, mTestUid2);
        broadcasts = broadcasts + 1;
        closeSessionWithResList(mSingleList, unbind, broadcasts, null, mTestSession1, mTestUid2);
        closeSessionWithResList(mSingleList, unbind, broadcasts, mTestPkg3, mTestSession1,
                mTestUid2);
    }

    /**
     * OPEN/CLOSE AUDIO_EFFECT_CONTROL_SESSION with two broadcast receivers.
     */
    @Test
    public void testBroadcastIntentWithNoPackageAndTwoBroadcastReceivers() {
        Log.i(TAG, "running testBroadcastIntentWithNoPackageAndTwoBroadcastReceivers");
    public void testBroadcastIntentWithPackageAndTwoBroadcastReceivers() {
        Log.i(TAG, "running testBroadcastIntentWithPackageAndTwoBroadcastReceivers");

        openSessionWithResList(mDoubleList, 1, 1, null, mTestSession1, mTestUid1);
        closeSessionWithResList(mDoubleList, 1, 2, null, mTestSession1, mTestUid1);
        openSessionWithResList(mDoubleList, 1 /* bind */, 1 /* broadcast */,
                mTestPkg1 /* packageName */, mTestSession1, mTestUid1);
        closeSessionWithResList(mDoubleList, 1 /* unbind */, 2 /* broadcast */,
                mTestPkg1 /* packageName */, mTestSession1, mTestUid1);
    }

    /**
@@ -639,4 +669,18 @@ public class MusicFxHelperTest {
        unbind = unbind + 1;
        sendMessage(MusicFxHelper.MSG_EFFECT_CLIENT_GONE, mTestUid3, unbind, broadcasts);
    }

    /**
     * Test audio session open/close with same package name value but different String object.
     */
    @Test
    public void testSessionOpenCloseWithSamePackageNameValueButDiffObject() {
        Log.i(TAG, "running testSessionOpenCloseWithSamePackageNameValueButDiffObject");
        int broadcasts = 1;
        openSessionWithResList(mSingleList, 1 /* bind */, broadcasts, mTestPkg1, mTestSession1,
                mTestUid1);
        closeSessionWithResList(mSingleList, 1 /* unbind */, broadcasts + 1, mTestPkg1Equivalent,
                mTestSession1, mTestUid1);
    }

}