[automerger skipped] Import translations. DO NOT MERGE ANYWHERE am: c774d3d6fd -s ours
am skip reason: subject contains skip directive
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/services/Telecomm/+/22688821
Change-Id: Idbc83e3b86f5383a406dc7517321d10750bec503
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/server/telecom/HeadsetMediaButton.java b/src/com/android/server/telecom/HeadsetMediaButton.java
index 8e9caff..7458f54 100644
--- a/src/com/android/server/telecom/HeadsetMediaButton.java
+++ b/src/com/android/server/telecom/HeadsetMediaButton.java
@@ -23,16 +23,11 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
-import android.telecom.CallAudioState;
-import android.telecom.CallEndpoint;
import android.telecom.Log;
-import android.util.ArraySet;
import android.view.KeyEvent;
import com.android.internal.annotations.VisibleForTesting;
-import java.util.Set;
-
/**
* Static class to handle listening to the headset media buttons.
*/
@@ -154,10 +149,8 @@
private final Context mContext;
private final CallsManager mCallsManager;
private final TelecomSystem.SyncRoot mLock;
- private final Set<Call> mCalls = new ArraySet<>();
private MediaSessionAdapter mSession;
private KeyEvent mLastHookEvent;
- private @CallEndpoint.EndpointType int mCurrentEndpointType;
/**
* Constructor used for testing purposes to initialize a {@link HeadsetMediaButton} with a
@@ -219,7 +212,7 @@
return mCallsManager.onMediaButton(LONG_PRESS);
} else if (event.getAction() == KeyEvent.ACTION_UP) {
// We should not judge SHORT_PRESS by ACTION_UP event repeatCount, because it always
- // returns 0.
+ // return 0.
// Actually ACTION_DOWN event repeatCount only increases when LONG_PRESS performed.
if (mLastHookEvent != null && mLastHookEvent.getRepeatCount() == 0) {
return mCallsManager.onMediaButton(SHORT_PRESS);
@@ -233,70 +226,50 @@
return true;
}
- @Override
- public void onCallEndpointChanged(CallEndpoint callEndpoint) {
- mCurrentEndpointType = callEndpoint.getEndpointType();
- Log.i(this, "onCallEndpointChanged: endPoint=%s", callEndpoint);
- maybeChangeSessionState();
- }
-
/** ${inheritDoc} */
@Override
public void onCallAdded(Call call) {
- handleCallAddition(call);
+ if (call.isExternalCall()) {
+ return;
+ }
+ handleCallAddition();
}
/**
* Triggers session activation due to call addition.
*/
- private void handleCallAddition(Call call) {
- mCalls.add(call);
- maybeChangeSessionState();
+ private void handleCallAddition() {
+ mMediaSessionHandler.obtainMessage(MSG_MEDIA_SESSION_SET_ACTIVE, 1, 0).sendToTarget();
+ }
+
+ /** ${inheritDoc} */
+ @Override
+ public void onCallRemoved(Call call) {
+ if (call.isExternalCall()) {
+ return;
+ }
+ handleCallRemoval();
}
/**
- * Based on whether there are tracked calls and the audio is routed to a wired headset,
- * potentially activate or deactive the media session.
+ * Triggers session deactivation due to call removal.
*/
- private void maybeChangeSessionState() {
- boolean hasNonExternalCalls = !mCalls.isEmpty()
- && mCalls.stream().anyMatch(c -> !c.isExternalCall());
- if (hasNonExternalCalls && mCurrentEndpointType == CallEndpoint.TYPE_WIRED_HEADSET) {
- Log.i(this, "maybeChangeSessionState: hasCalls=%b, currentEndpointType=%s, ACTIVATE",
- hasNonExternalCalls, CallEndpoint.endpointTypeToString(mCurrentEndpointType));
- mMediaSessionHandler.obtainMessage(MSG_MEDIA_SESSION_SET_ACTIVE, 1, 0).sendToTarget();
- } else {
- Log.i(this, "maybeChangeSessionState: hasCalls=%b, currentEndpointType=%s, DEACTIVATE",
- hasNonExternalCalls, CallEndpoint.endpointTypeToString(mCurrentEndpointType));
+ private void handleCallRemoval() {
+ if (!mCallsManager.hasAnyCalls()) {
mMediaSessionHandler.obtainMessage(MSG_MEDIA_SESSION_SET_ACTIVE, 0, 0).sendToTarget();
}
}
/** ${inheritDoc} */
@Override
- public void onCallRemoved(Call call) {
- handleCallRemoval(call);
- }
-
- /**
- * Triggers session deactivation due to call removal.
- */
- private void handleCallRemoval(Call call) {
- // If we were tracking the call, potentially change session state.
- if (mCalls.remove(call)) {
- if (mCalls.isEmpty()) {
- // When there are no calls, don't cache that we previously had a wired headset
- // connected; we'll be updated on the next call.
- mCurrentEndpointType = CallEndpoint.TYPE_UNKNOWN;
- }
- maybeChangeSessionState();
- }
- }
-
- /** ${inheritDoc} */
- @Override
public void onExternalCallChanged(Call call, boolean isExternalCall) {
- maybeChangeSessionState();
+ // Note: We don't use the onCallAdded/onCallRemoved methods here since they do checks to see
+ // if the call is external or not and would skip the session activation/deactivation.
+ if (isExternalCall) {
+ handleCallRemoval();
+ } else {
+ handleCallAddition();
+ }
}
@VisibleForTesting
diff --git a/testapps/transactionalVoipApp/res/values-en-rCA/strings.xml b/testapps/transactionalVoipApp/res/values-en-rCA/strings.xml
index 5986f59..1014001 100644
--- a/testapps/transactionalVoipApp/res/values-en-rCA/strings.xml
+++ b/testapps/transactionalVoipApp/res/values-en-rCA/strings.xml
@@ -18,31 +18,18 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name" msgid="2907804426411305091">"Transactional API test Activity"</string>
- <!-- no translation found for in_call_activity_name (7545884666442897585) -->
- <skip />
+ <string name="in_call_activity_name" msgid="7545884666442897585">"Transactional In Call Activity"</string>
<string name="register_phone_account" msgid="1920315963082350332">"Register Phone Account"</string>
- <!-- no translation found for start_foreground_service (8968755699895128574) -->
- <skip />
- <!-- no translation found for start_outgoing (1441644037370361864) -->
- <skip />
- <!-- no translation found for start_incoming (6444983300186361271) -->
- <skip />
- <!-- no translation found for get_call_id (5513943242738347108) -->
- <skip />
- <!-- no translation found for set_call_active (3365404393507589899) -->
- <skip />
- <!-- no translation found for answer (5423590397665409939) -->
- <skip />
- <!-- no translation found for set_call_inactive (7106775211368705195) -->
- <skip />
- <!-- no translation found for disconnect_call (1349412380315371385) -->
- <skip />
- <!-- no translation found for request_earpiece_endpoint (6649571985089296573) -->
- <skip />
- <!-- no translation found for request_speaker_endpoint (1033259535289845405) -->
- <skip />
- <!-- no translation found for request_bluetooth_endpoint (5933254250623451836) -->
- <skip />
- <!-- no translation found for start_stream (3567634786280097431) -->
- <skip />
+ <string name="start_foreground_service" msgid="8968755699895128574">"Start FGS (simulate MT + app in background)"</string>
+ <string name="start_outgoing" msgid="1441644037370361864">"Start Outgoing Call"</string>
+ <string name="start_incoming" msgid="6444983300186361271">"Start Incoming Call"</string>
+ <string name="get_call_id" msgid="5513943242738347108">"call id not set"</string>
+ <string name="set_call_active" msgid="3365404393507589899">"setActive"</string>
+ <string name="answer" msgid="5423590397665409939">"answer"</string>
+ <string name="set_call_inactive" msgid="7106775211368705195">"setInactive"</string>
+ <string name="disconnect_call" msgid="1349412380315371385">"disconnect"</string>
+ <string name="request_earpiece_endpoint" msgid="6649571985089296573">"Earpiece"</string>
+ <string name="request_speaker_endpoint" msgid="1033259535289845405">"Speaker"</string>
+ <string name="request_bluetooth_endpoint" msgid="5933254250623451836">"Bluetooth"</string>
+ <string name="start_stream" msgid="3567634786280097431">"start streaming"</string>
</resources>
diff --git a/testapps/transactionalVoipApp/res/values-en-rXC/strings.xml b/testapps/transactionalVoipApp/res/values-en-rXC/strings.xml
index 764ebda..40b0016 100644
--- a/testapps/transactionalVoipApp/res/values-en-rXC/strings.xml
+++ b/testapps/transactionalVoipApp/res/values-en-rXC/strings.xml
@@ -18,31 +18,18 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name" msgid="2907804426411305091">"Transactional API test Activity"</string>
- <!-- no translation found for in_call_activity_name (7545884666442897585) -->
- <skip />
+ <string name="in_call_activity_name" msgid="7545884666442897585">"Transactional In Call Activity"</string>
<string name="register_phone_account" msgid="1920315963082350332">"Register Phone Account"</string>
- <!-- no translation found for start_foreground_service (8968755699895128574) -->
- <skip />
- <!-- no translation found for start_outgoing (1441644037370361864) -->
- <skip />
- <!-- no translation found for start_incoming (6444983300186361271) -->
- <skip />
- <!-- no translation found for get_call_id (5513943242738347108) -->
- <skip />
- <!-- no translation found for set_call_active (3365404393507589899) -->
- <skip />
- <!-- no translation found for answer (5423590397665409939) -->
- <skip />
- <!-- no translation found for set_call_inactive (7106775211368705195) -->
- <skip />
- <!-- no translation found for disconnect_call (1349412380315371385) -->
- <skip />
- <!-- no translation found for request_earpiece_endpoint (6649571985089296573) -->
- <skip />
- <!-- no translation found for request_speaker_endpoint (1033259535289845405) -->
- <skip />
- <!-- no translation found for request_bluetooth_endpoint (5933254250623451836) -->
- <skip />
- <!-- no translation found for start_stream (3567634786280097431) -->
- <skip />
+ <string name="start_foreground_service" msgid="8968755699895128574">"Start FGS (simulate MT + app in background)"</string>
+ <string name="start_outgoing" msgid="1441644037370361864">"Start Outgoing Call"</string>
+ <string name="start_incoming" msgid="6444983300186361271">"Start Incoming Call"</string>
+ <string name="get_call_id" msgid="5513943242738347108">"call id not set"</string>
+ <string name="set_call_active" msgid="3365404393507589899">"setActive"</string>
+ <string name="answer" msgid="5423590397665409939">"answer"</string>
+ <string name="set_call_inactive" msgid="7106775211368705195">"setInactive"</string>
+ <string name="disconnect_call" msgid="1349412380315371385">"disconnect"</string>
+ <string name="request_earpiece_endpoint" msgid="6649571985089296573">"Earpiece"</string>
+ <string name="request_speaker_endpoint" msgid="1033259535289845405">"Speaker"</string>
+ <string name="request_bluetooth_endpoint" msgid="5933254250623451836">"Bluetooth"</string>
+ <string name="start_stream" msgid="3567634786280097431">"start streaming"</string>
</resources>
diff --git a/tests/src/com/android/server/telecom/tests/HeadsetMediaButtonTest.java b/tests/src/com/android/server/telecom/tests/HeadsetMediaButtonTest.java
index ce23724..0bfa987 100644
--- a/tests/src/com/android/server/telecom/tests/HeadsetMediaButtonTest.java
+++ b/tests/src/com/android/server/telecom/tests/HeadsetMediaButtonTest.java
@@ -18,7 +18,6 @@
import android.content.Intent;
import android.media.session.MediaSession;
-import android.telecom.CallEndpoint;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.KeyEvent;
@@ -81,7 +80,7 @@
}
/**
- * Nominal case; just add a call and remove it; this happens when the audio state is earpiece.
+ * Nominal case; just add a call and remove it.
*/
@SmallTest
@Test
@@ -91,95 +90,14 @@
when(mMockCallsManager.hasAnyCalls()).thenReturn(true);
mHeadsetMediaButton.onCallAdded(regularCall);
waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter, never()).setActive(eq(true));
-
- // Report that the endpoint is earpiece and other routes that don't matter
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("Earpiece", CallEndpoint.TYPE_EARPIECE));
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("Speaker", CallEndpoint.TYPE_SPEAKER));
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("BT", CallEndpoint.TYPE_BLUETOOTH));
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter, never()).setActive(eq(true));
-
- // ... and thus we see how the original code isn't amenable to tests.
- when(mMediaSessionAdapter.isActive()).thenReturn(false);
-
- // Still should not have done anything; we never hit wired headset
- mHeadsetMediaButton.onCallRemoved(regularCall);
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter, never()).setActive(eq(false));
- }
-
- /**
- * Call is added and then routed to headset after call start
- */
- @SmallTest
- @Test
- public void testAddCallThenRouteToHeadset() {
- Call regularCall = getRegularCall();
-
- mHeadsetMediaButton.onCallAdded(regularCall);
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter, never()).setActive(eq(true));
-
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("Wired Headset", CallEndpoint.TYPE_WIRED_HEADSET));
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
verify(mMediaSessionAdapter).setActive(eq(true));
-
// ... and thus we see how the original code isn't amenable to tests.
when(mMediaSessionAdapter.isActive()).thenReturn(true);
- // Remove the one call; we should release the session.
+ when(mMockCallsManager.hasAnyCalls()).thenReturn(false);
mHeadsetMediaButton.onCallRemoved(regularCall);
waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
verify(mMediaSessionAdapter).setActive(eq(false));
- when(mMediaSessionAdapter.isActive()).thenReturn(false);
-
- // Add a new call; make sure we go active once more.
- mHeadsetMediaButton.onCallAdded(regularCall);
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("Wired Headset", CallEndpoint.TYPE_WIRED_HEADSET));
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter, times(2)).setActive(eq(true));
- }
-
- /**
- * Call is added and then routed to headset after call start
- */
- @SmallTest
- @Test
- public void testAddCallThenRouteToHeadsetAndBack() {
- Call regularCall = getRegularCall();
-
- when(mMockCallsManager.hasAnyCalls()).thenReturn(true);
- mHeadsetMediaButton.onCallAdded(regularCall);
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter, never()).setActive(eq(true));
-
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("Wired Headset", CallEndpoint.TYPE_WIRED_HEADSET));
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter).setActive(eq(true));
-
- // ... and thus we see how the original code isn't amenable to tests.
- when(mMediaSessionAdapter.isActive()).thenReturn(true);
-
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("Earpiece", CallEndpoint.TYPE_EARPIECE));
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter).setActive(eq(false));
- when(mMediaSessionAdapter.isActive()).thenReturn(false);
-
- // Remove the one call; we should not release again.
- mHeadsetMediaButton.onCallRemoved(regularCall);
- waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- // Remember, mockito counts total invocations; we should have went active once and then
- // inactive again when we hit earpiece.
- verify(mMediaSessionAdapter, times(1)).setActive(eq(true));
- verify(mMediaSessionAdapter, times(1)).setActive(eq(false));
}
/**
@@ -193,8 +111,6 @@
// Start with a regular old call.
when(mMockCallsManager.hasAnyCalls()).thenReturn(true);
mHeadsetMediaButton.onCallAdded(regularCall);
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("Wired Headset", CallEndpoint.TYPE_WIRED_HEADSET));
waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
verify(mMediaSessionAdapter).setActive(eq(true));
when(mMediaSessionAdapter.isActive()).thenReturn(true);
@@ -206,7 +122,6 @@
// Expect to set session inactive.
waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
verify(mMediaSessionAdapter).setActive(eq(false));
- when(mMediaSessionAdapter.isActive()).thenReturn(false);
// For good measure lets make it non-external again.
when(regularCall.isExternalCall()).thenReturn(false);
@@ -214,7 +129,7 @@
mHeadsetMediaButton.onExternalCallChanged(regularCall, false);
// Expect to set session active.
waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
- verify(mMediaSessionAdapter, times(2)).setActive(eq(true));
+ verify(mMediaSessionAdapter).setActive(eq(true));
}
@MediumTest
@@ -224,8 +139,6 @@
when(externalCall.isExternalCall()).thenReturn(true);
mHeadsetMediaButton.onCallAdded(externalCall);
- mHeadsetMediaButton.onCallEndpointChanged(
- new CallEndpoint("Wired Headset", CallEndpoint.TYPE_WIRED_HEADSET));
waitForHandlerAction(mHeadsetMediaButton.getHandler(), TEST_TIMEOUT_MILLIS);
verify(mMediaSessionAdapter, never()).setActive(eq(true));