Skip to content
Snippets Groups Projects
Commit c5c225b1 authored by Shunkai Yao's avatar Shunkai Yao
Browse files

Fix the string reference equality comparison in MusicFxHelper

Bug: 332981866
Test: atest com.android.server.audio.MusicFxHelperTest
Flag: NONE, impact of this fix is limited
Change-Id: I996951c7f71678c76afec78efd452b275f17213e
(cherry picked from commit 52c9b652)
Merged-In: I996951c7f71678c76afec78efd452b275f17213e
parent 52a3a399
No related branches found
No related tags found
No related merge requests found
...@@ -92,7 +92,6 @@ public class MusicFxHelper { ...@@ -92,7 +92,6 @@ public class MusicFxHelper {
* observer will also be removed, and observer token reset to null * observer will also be removed, and observer token reset to null
*/ */
private class MySparseArray extends SparseArray<PackageSessions> { private class MySparseArray extends SparseArray<PackageSessions> {
private final String mMusicFxPackageName = "com.android.musicfx";
@RequiresPermission(anyOf = { @RequiresPermission(anyOf = {
android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
...@@ -235,6 +234,10 @@ public class MusicFxHelper { ...@@ -235,6 +234,10 @@ public class MusicFxHelper {
if (ril != null && ril.size() != 0) { if (ril != null && ril.size() != 0) {
ResolveInfo ri = ril.get(0); ResolveInfo ri = ril.get(0);
final String senderPackageName = intent.getStringExtra(AudioEffect.EXTRA_PACKAGE_NAME); final String senderPackageName = intent.getStringExtra(AudioEffect.EXTRA_PACKAGE_NAME);
if (senderPackageName == null) {
Log.w(TAG, "Intent package name must not be null");
return;
}
try { try {
if (ri != null && ri.activityInfo != null && ri.activityInfo.packageName != null) { if (ri != null && ri.activityInfo != null && ri.activityInfo.packageName != null) {
final int senderUid = pm.getPackageUidAsUser(senderPackageName, final int senderUid = pm.getPackageUidAsUser(senderPackageName,
...@@ -271,7 +274,7 @@ public class MusicFxHelper { ...@@ -271,7 +274,7 @@ public class MusicFxHelper {
+ senderUid + ", package: " + senderPackageName + ", abort"); + senderUid + ", package: " + senderPackageName + ", abort");
return false; return false;
} }
if (pkgSessions.mPackageName != senderPackageName) { if (!pkgSessions.mPackageName.equals(senderPackageName)) {
Log.w(TAG, "Inconsistency package names for UID open: " + senderUid + " prev: " Log.w(TAG, "Inconsistency package names for UID open: " + senderUid + " prev: "
+ pkgSessions.mPackageName + ", now: " + senderPackageName); + pkgSessions.mPackageName + ", now: " + senderPackageName);
return false; return false;
...@@ -303,7 +306,7 @@ public class MusicFxHelper { ...@@ -303,7 +306,7 @@ public class MusicFxHelper {
Log.e(TAG, senderPackageName + " UID " + senderUid + " does not exist in map, abort"); Log.e(TAG, senderPackageName + " UID " + senderUid + " does not exist in map, abort");
return false; return false;
} }
if (pkgSessions.mPackageName != senderPackageName) { if (!pkgSessions.mPackageName.equals(senderPackageName)) {
Log.w(TAG, "Inconsistency package names for UID " + senderUid + " close, prev: " Log.w(TAG, "Inconsistency package names for UID " + senderUid + " close, prev: "
+ pkgSessions.mPackageName + ", now: " + senderPackageName); + pkgSessions.mPackageName + ", now: " + senderPackageName);
return false; return false;
......
...@@ -57,8 +57,9 @@ public class MusicFxHelperTest { ...@@ -57,8 +57,9 @@ public class MusicFxHelperTest {
private ResolveInfo mResolveInfo1 = new ResolveInfo(); private ResolveInfo mResolveInfo1 = new ResolveInfo();
private ResolveInfo mResolveInfo2 = new ResolveInfo(); private ResolveInfo mResolveInfo2 = new ResolveInfo();
private final String mTestPkg1 = "testPkg1", mTestPkg2 = "testPkg2", mTestPkg3 = "testPkg3"; private final String mTestPkg1 = new String("testPkg1"), mTestPkg2 = new String("testPkg2"),
private final String mMusicFxPkgName = "com.android.musicfx"; 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 mTestUid1 = 1, mTestUid2 = 2, mTestUid3 = 3, mMusicFxUid = 78;
private final int mTestSession1 = 11, mTestSession2 = 22, mTestSession3 = 33; private final int mTestSession1 = 11, mTestSession2 = 22, mTestSession3 = 33;
...@@ -191,7 +192,8 @@ public class MusicFxHelperTest { ...@@ -191,7 +192,8 @@ public class MusicFxHelperTest {
public void testCloseBroadcastIntent() { public void testCloseBroadcastIntent() {
Log.i(TAG, "running 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 { ...@@ -225,8 +227,10 @@ public class MusicFxHelperTest {
public void testBroadcastIntentWithNoPackageAndNoBroadcastReceiver() { public void testBroadcastIntentWithNoPackageAndNoBroadcastReceiver() {
Log.i(TAG, "running testBroadcastIntentWithNoPackageAndNoBroadcastReceiver"); Log.i(TAG, "running testBroadcastIntentWithNoPackageAndNoBroadcastReceiver");
openSessionWithResList(mEmptyList, 0, 0, null, mTestSession1, mTestUid1); openSessionWithResList(mEmptyList, 0 /* bind */, 0 /* broadcast */, null /* packageName */,
closeSessionWithResList(mEmptyList, 0, 0, null, mTestSession1, mTestUid1); mTestSession1, mTestUid1);
closeSessionWithResList(mEmptyList, 0 /* unbind */, 0 /* broadcast */,
null /* packageName */, mTestSession1, mTestUid1);
} }
/** /**
...@@ -236,37 +240,63 @@ public class MusicFxHelperTest { ...@@ -236,37 +240,63 @@ public class MusicFxHelperTest {
public void testBroadcastIntentWithNoPackageAndOneBroadcastReceiver() { public void testBroadcastIntentWithNoPackageAndOneBroadcastReceiver() {
Log.i(TAG, "running 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; int broadcasts = 1, bind = 1, unbind = 1;
openSessionWithResList(mSingleList, bind, broadcasts, null, mTestSession1, mTestUid1); openSessionWithResList(mSingleList, bind, broadcasts, mTestPkg1, mTestSession1, mTestUid1);
broadcasts = broadcasts + 1; broadcasts = broadcasts + 1;
closeSessionWithResList(mSingleList, unbind, broadcasts, null, mTestSession1, mTestUid1); closeSessionWithResList(mSingleList, unbind, broadcasts, mTestPkg1, mTestSession1,
mTestUid1);
// repeat with different session ID // repeat with different session ID
broadcasts = broadcasts + 1; broadcasts = broadcasts + 1;
bind = bind + 1; bind = bind + 1;
unbind = unbind + 1; unbind = unbind + 1;
openSessionWithResList(mSingleList, bind, broadcasts, null, mTestSession2, mTestUid1); openSessionWithResList(mSingleList, bind, broadcasts, mTestPkg2, mTestSession2, mTestUid1);
broadcasts = broadcasts + 1; broadcasts = broadcasts + 1;
closeSessionWithResList(mSingleList, unbind, broadcasts, null, mTestSession2, mTestUid1); closeSessionWithResList(mSingleList, unbind, broadcasts, mTestPkg2, mTestSession2,
mTestUid1);
// repeat with different UID // repeat with different UID
broadcasts = broadcasts + 1; broadcasts = broadcasts + 1;
bind = bind + 1; bind = bind + 1;
unbind = unbind + 1; unbind = unbind + 1;
openSessionWithResList(mSingleList, bind, broadcasts, null, mTestSession1, mTestUid2); openSessionWithResList(mSingleList, bind, broadcasts, mTestPkg3, mTestSession1, mTestUid2);
broadcasts = broadcasts + 1; 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 @Test
public void testBroadcastIntentWithNoPackageAndTwoBroadcastReceivers() { public void testBroadcastIntentWithPackageAndTwoBroadcastReceivers() {
Log.i(TAG, "running testBroadcastIntentWithNoPackageAndTwoBroadcastReceivers"); Log.i(TAG, "running testBroadcastIntentWithPackageAndTwoBroadcastReceivers");
openSessionWithResList(mDoubleList, 1, 1, null, mTestSession1, mTestUid1); openSessionWithResList(mDoubleList, 1 /* bind */, 1 /* broadcast */,
closeSessionWithResList(mDoubleList, 1, 2, null, mTestSession1, mTestUid1); mTestPkg1 /* packageName */, mTestSession1, mTestUid1);
closeSessionWithResList(mDoubleList, 1 /* unbind */, 2 /* broadcast */,
mTestPkg1 /* packageName */, mTestSession1, mTestUid1);
} }
/** /**
...@@ -639,4 +669,18 @@ public class MusicFxHelperTest { ...@@ -639,4 +669,18 @@ public class MusicFxHelperTest {
unbind = unbind + 1; unbind = unbind + 1;
sendMessage(MusicFxHelper.MSG_EFFECT_CLIENT_GONE, mTestUid3, unbind, broadcasts); 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);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment