Merge "Optimize media button stack traversal for remote volume"
This commit is contained in:
committed by
Android (Google) Code Review
commit
26bf4d9020
@@ -5708,17 +5708,19 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
private void onRegisterVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) {
|
private void onRegisterVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) {
|
||||||
synchronized(mRCStack) {
|
synchronized(mRCStack) {
|
||||||
// The stack traversal order doesn't matter because there is only one stack entry
|
// The stack traversal order doesn't matter because there is only one stack entry
|
||||||
// with this RCC ID, and we can stop iterating over the stack entries once the matching
|
// with this RCC ID, but the matching ID is more likely at the top of the stack, so
|
||||||
// ID has been found.
|
// start iterating from the top.
|
||||||
// FIXME optimize by traversing stack from top to bottom, the matching ID is more likely
|
try {
|
||||||
// at the top of the stack
|
for (int index = mRCStack.size()-1; index >= 0; index--) {
|
||||||
Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
|
final RemoteControlStackEntry rcse = mRCStack.elementAt(index);
|
||||||
while(stackIterator.hasNext()) {
|
if (rcse.mRccId == rccId) {
|
||||||
RemoteControlStackEntry rcse = stackIterator.next();
|
rcse.mRemoteVolumeObs = rvo;
|
||||||
if (rcse.mRccId == rccId) {
|
break;
|
||||||
rcse.mRemoteVolumeObs = rvo;
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
// not expected to happen, indicates improper concurrent modification
|
||||||
|
Log.e(TAG, "Wrong index accessing media button stack, lock error? ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5813,18 +5815,20 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
IRemoteVolumeObserver rvo = null;
|
IRemoteVolumeObserver rvo = null;
|
||||||
synchronized (mRCStack) {
|
synchronized (mRCStack) {
|
||||||
// The stack traversal order doesn't matter because there is only one stack entry
|
// The stack traversal order doesn't matter because there is only one stack entry
|
||||||
// with this RCC ID, and we can stop iterating over the stack entries once the matching
|
// with this RCC ID, but the matching ID is more likely at the top of the stack, so
|
||||||
// ID has been found.
|
// start iterating from the top.
|
||||||
// FIXME optimize by traversing stack from top to bottom, the matching ID is more likely
|
try {
|
||||||
// at the top of the stack
|
for (int index = mRCStack.size()-1; index >= 0; index--) {
|
||||||
Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
|
final RemoteControlStackEntry rcse = mRCStack.elementAt(index);
|
||||||
while(stackIterator.hasNext()) {
|
//FIXME OPTIMIZE store this info in mMainRemote so we don't have to iterate?
|
||||||
RemoteControlStackEntry rcse = stackIterator.next();
|
if (rcse.mRccId == rccId) {
|
||||||
//FIXME OPTIMIZE store this info in mMainRemote so we don't have to iterate?
|
rvo = rcse.mRemoteVolumeObs;
|
||||||
if (rcse.mRccId == rccId) {
|
break;
|
||||||
rvo = rcse.mRemoteVolumeObs;
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
// not expected to happen, indicates improper concurrent modification
|
||||||
|
Log.e(TAG, "Wrong index accessing media button stack, lock error? ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rvo != null) {
|
if (rvo != null) {
|
||||||
@@ -5866,18 +5870,20 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
IRemoteVolumeObserver rvo = null;
|
IRemoteVolumeObserver rvo = null;
|
||||||
synchronized (mRCStack) {
|
synchronized (mRCStack) {
|
||||||
// The stack traversal order doesn't matter because there is only one stack entry
|
// The stack traversal order doesn't matter because there is only one stack entry
|
||||||
// with this RCC ID, and we can stop iterating over the stack entries once the matching
|
// with this RCC ID, but the matching ID is more likely at the top of the stack, so
|
||||||
// ID has been found.
|
// start iterating from the top.
|
||||||
// FIXME optimize by traversing stack from top to bottom, the matching ID is more likely
|
try {
|
||||||
// at the top of the stack
|
for (int index = mRCStack.size()-1; index >= 0; index--) {
|
||||||
Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
|
final RemoteControlStackEntry rcse = mRCStack.elementAt(index);
|
||||||
while(stackIterator.hasNext()) {
|
|
||||||
RemoteControlStackEntry rcse = stackIterator.next();
|
|
||||||
if (rcse.mRccId == rccId) {
|
|
||||||
//FIXME OPTIMIZE store this info in mMainRemote so we don't have to iterate?
|
//FIXME OPTIMIZE store this info in mMainRemote so we don't have to iterate?
|
||||||
rvo = rcse.mRemoteVolumeObs;
|
if (rcse.mRccId == rccId) {
|
||||||
break;
|
rvo = rcse.mRemoteVolumeObs;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
// not expected to happen, indicates improper concurrent modification
|
||||||
|
Log.e(TAG, "Wrong index accessing media button stack, lock error? ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rvo != null) {
|
if (rvo != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user