Browse Source

android: fix running on Android < M

The android.telecom.CallAudioState class was only added in API level 23 (Android
M), so make sure we don't import it in lower versioned devices.
j8
Saúl Ibarra Corretgé 6 years ago
parent
commit
bdb3099073
1 changed files with 24 additions and 23 deletions
  1. 24
    23
      android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java

+ 24
- 23
android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java View File

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

Loading…
Cancel
Save