|
@@ -26,7 +26,6 @@ import android.media.AudioDeviceInfo;
|
26
|
26
|
import android.media.AudioManager;
|
27
|
27
|
import android.os.Build;
|
28
|
28
|
import android.support.annotation.RequiresApi;
|
29
|
|
-import android.telecom.CallAudioState;
|
30
|
29
|
import android.util.Log;
|
31
|
30
|
|
32
|
31
|
import com.facebook.react.bridge.Arguments;
|
|
@@ -59,8 +58,7 @@ import java.util.concurrent.Executors;
|
59
|
58
|
* Before a call has started and after it has ended the
|
60
|
59
|
* {@code AudioModeModule.DEFAULT} mode should be used.
|
61
|
60
|
*/
|
62
|
|
-class AudioModeModule
|
63
|
|
- extends ReactContextBaseJavaModule
|
|
61
|
+class AudioModeModule extends ReactContextBaseJavaModule
|
64
|
62
|
implements AudioManager.OnAudioFocusChangeListener {
|
65
|
63
|
|
66
|
64
|
/**
|
|
@@ -104,29 +102,29 @@ class AudioModeModule
|
104
|
102
|
|
105
|
103
|
/**
|
106
|
104
|
* Converts any of the "DEVICE_" constants into the corresponding
|
107
|
|
- * {@link CallAudioState} "ROUTE_" number.
|
|
105
|
+ * {@link android.telecom.CallAudioState} "ROUTE_" number.
|
108
|
106
|
*
|
109
|
107
|
* @param audioDevice one of the "DEVICE_" constants.
|
110
|
|
- * @return a route number {@link CallAudioState#ROUTE_EARPIECE} if no match
|
111
|
|
- * is found.
|
|
108
|
+ * @return a route number {@link android.telecom.CallAudioState#ROUTE_EARPIECE} if
|
|
109
|
+ * no match is found.
|
112
|
110
|
*/
|
113
|
111
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
114
|
112
|
private static int audioDeviceToRouteInt(String audioDevice) {
|
115
|
113
|
if (audioDevice == null) {
|
116
|
|
- return CallAudioState.ROUTE_EARPIECE;
|
|
114
|
+ return android.telecom.CallAudioState.ROUTE_EARPIECE;
|
117
|
115
|
}
|
118
|
116
|
switch (audioDevice) {
|
119
|
117
|
case DEVICE_BLUETOOTH:
|
120
|
|
- return CallAudioState.ROUTE_BLUETOOTH;
|
|
118
|
+ return android.telecom.CallAudioState.ROUTE_BLUETOOTH;
|
121
|
119
|
case DEVICE_EARPIECE:
|
122
|
|
- return CallAudioState.ROUTE_EARPIECE;
|
|
120
|
+ return android.telecom.CallAudioState.ROUTE_EARPIECE;
|
123
|
121
|
case DEVICE_HEADPHONES:
|
124
|
|
- return CallAudioState.ROUTE_WIRED_HEADSET;
|
|
122
|
+ return android.telecom.CallAudioState.ROUTE_WIRED_HEADSET;
|
125
|
123
|
case DEVICE_SPEAKER:
|
126
|
|
- return CallAudioState.ROUTE_SPEAKER;
|
|
124
|
+ return android.telecom.CallAudioState.ROUTE_SPEAKER;
|
127
|
125
|
default:
|
128
|
126
|
Log.e(TAG, "Unsupported device name: " + audioDevice);
|
129
|
|
- return CallAudioState.ROUTE_EARPIECE;
|
|
127
|
+ return android.telecom.CallAudioState.ROUTE_EARPIECE;
|
130
|
128
|
}
|
131
|
129
|
}
|
132
|
130
|
|
|
@@ -134,25 +132,26 @@ class AudioModeModule
|
134
|
132
|
* Populates given route mask into the "DEVICE_" list.
|
135
|
133
|
*
|
136
|
134
|
* @param supportedRouteMask an integer coming from
|
137
|
|
- * {@link CallAudioState#getSupportedRouteMask()}.
|
|
135
|
+ * {@link android.telecom.CallAudioState#getSupportedRouteMask()}.
|
138
|
136
|
* @return a list of device names.
|
139
|
137
|
*/
|
|
138
|
+ @RequiresApi(api = Build.VERSION_CODES.M)
|
140
|
139
|
private static Set<String> routesToDeviceNames(int supportedRouteMask) {
|
141
|
140
|
Set<String> devices = new HashSet<>();
|
142
|
|
- if ((supportedRouteMask & CallAudioState.ROUTE_EARPIECE)
|
143
|
|
- == CallAudioState.ROUTE_EARPIECE) {
|
|
141
|
+ if ((supportedRouteMask & android.telecom.CallAudioState.ROUTE_EARPIECE)
|
|
142
|
+ == android.telecom.CallAudioState.ROUTE_EARPIECE) {
|
144
|
143
|
devices.add(DEVICE_EARPIECE);
|
145
|
144
|
}
|
146
|
|
- if ((supportedRouteMask & CallAudioState.ROUTE_BLUETOOTH)
|
147
|
|
- == CallAudioState.ROUTE_BLUETOOTH) {
|
|
145
|
+ if ((supportedRouteMask & android.telecom.CallAudioState.ROUTE_BLUETOOTH)
|
|
146
|
+ == android.telecom.CallAudioState.ROUTE_BLUETOOTH) {
|
148
|
147
|
devices.add(DEVICE_BLUETOOTH);
|
149
|
148
|
}
|
150
|
|
- if ((supportedRouteMask & CallAudioState.ROUTE_SPEAKER)
|
151
|
|
- == CallAudioState.ROUTE_SPEAKER) {
|
|
149
|
+ if ((supportedRouteMask & android.telecom.CallAudioState.ROUTE_SPEAKER)
|
|
150
|
+ == android.telecom.CallAudioState.ROUTE_SPEAKER) {
|
152
|
151
|
devices.add(DEVICE_SPEAKER);
|
153
|
152
|
}
|
154
|
|
- if ((supportedRouteMask & CallAudioState.ROUTE_WIRED_HEADSET)
|
155
|
|
- == CallAudioState.ROUTE_WIRED_HEADSET) {
|
|
153
|
+ if ((supportedRouteMask & android.telecom.CallAudioState.ROUTE_WIRED_HEADSET)
|
|
154
|
+ == android.telecom.CallAudioState.ROUTE_WIRED_HEADSET) {
|
156
|
155
|
devices.add(DEVICE_HEADPHONES);
|
157
|
156
|
}
|
158
|
157
|
return devices;
|
|
@@ -272,7 +271,7 @@ class AudioModeModule
|
272
|
271
|
/**
|
273
|
272
|
* Used on API >= 26 to store the most recently reported audio devices.
|
274
|
273
|
* Makes it easier to compare for a change, because the devices are stored
|
275
|
|
- * as a mask in the {@link CallAudioState}. The mask is populated into
|
|
274
|
+ * as a mask in the {@link android.telecom.CallAudioState}. The mask is populated into
|
276
|
275
|
* the {@link #availableDevices} on each update.
|
277
|
276
|
*/
|
278
|
277
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
@@ -433,7 +432,9 @@ class AudioModeModule
|
433
|
432
|
}
|
434
|
433
|
|
435
|
434
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
436
|
|
- void onCallAudioStateChange(final CallAudioState callAudioState) {
|
|
435
|
+ void onCallAudioStateChange(Object callAudioState_) {
|
|
436
|
+ final android.telecom.CallAudioState callAudioState
|
|
437
|
+ = (android.telecom.CallAudioState)callAudioState_;
|
437
|
438
|
runInAudioThread(new Runnable() {
|
438
|
439
|
@Override
|
439
|
440
|
public void run() {
|