浏览代码

android: simplify the creation of AudioManager

Do so on the main thread at startup and pass it along.
master
Saúl Ibarra Corretgé 5 年前
父节点
当前提交
025e2b1ecb

+ 3
- 3
android/sdk/src/main/java/org/jitsi/meet/sdk/AudioDeviceHandlerConnectionService.java 查看文件

108
      */
108
      */
109
     private int supportedRouteMask = -1;
109
     private int supportedRouteMask = -1;
110
 
110
 
111
-    public AudioDeviceHandlerConnectionService() {
111
+    public AudioDeviceHandlerConnectionService(AudioManager audioManager) {
112
+        this.audioManager = audioManager;
112
     }
113
     }
113
 
114
 
114
     @Override
115
     @Override
136
     }
137
     }
137
 
138
 
138
     @Override
139
     @Override
139
-    public void start(Context context, AudioModeModule audioModeModule) {
140
+    public void start(AudioModeModule audioModeModule) {
140
         JitsiMeetLogger.i("Using " + TAG + " as the audio device handler");
141
         JitsiMeetLogger.i("Using " + TAG + " as the audio device handler");
141
 
142
 
142
         module = audioModeModule;
143
         module = audioModeModule;
143
-        audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
144
 
144
 
145
         RNConnectionService rcs = ReactInstanceManagerHolder.getNativeModule(RNConnectionService.class);
145
         RNConnectionService rcs = ReactInstanceManagerHolder.getNativeModule(RNConnectionService.class);
146
         if (rcs != null) {
146
         if (rcs != null) {

+ 3
- 3
android/sdk/src/main/java/org/jitsi/meet/sdk/AudioDeviceHandlerGeneric.java 查看文件

117
             }
117
             }
118
         };
118
         };
119
 
119
 
120
-    public AudioDeviceHandlerGeneric() {
120
+    public AudioDeviceHandlerGeneric(AudioManager audioManager) {
121
+        this.audioManager = audioManager;
121
     }
122
     }
122
 
123
 
123
     /**
124
     /**
178
     }
179
     }
179
 
180
 
180
     @Override
181
     @Override
181
-    public void start(Context context, AudioModeModule audioModeModule) {
182
+    public void start(AudioModeModule audioModeModule) {
182
         JitsiMeetLogger.i("Using " + TAG + " as the audio device handler");
183
         JitsiMeetLogger.i("Using " + TAG + " as the audio device handler");
183
 
184
 
184
         module = audioModeModule;
185
         module = audioModeModule;
185
-        audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
186
 
186
 
187
         // Setup runtime device change detection.
187
         // Setup runtime device change detection.
188
         audioManager.registerAudioDeviceCallback(audioDeviceCallback, null);
188
         audioManager.registerAudioDeviceCallback(audioDeviceCallback, null);

+ 4
- 3
android/sdk/src/main/java/org/jitsi/meet/sdk/AudioDeviceHandlerLegacy.java 查看文件

59
      */
59
      */
60
     private BluetoothHeadsetMonitor bluetoothHeadsetMonitor;
60
     private BluetoothHeadsetMonitor bluetoothHeadsetMonitor;
61
 
61
 
62
-    public AudioDeviceHandlerLegacy() {
62
+    public AudioDeviceHandlerLegacy(AudioManager audioManager) {
63
+        this.audioManager = audioManager;
63
     }
64
     }
64
 
65
 
65
     /**
66
     /**
155
     }
156
     }
156
 
157
 
157
     @Override
158
     @Override
158
-    public void start(Context context, AudioModeModule audioModeModule) {
159
+    public void start(AudioModeModule audioModeModule) {
159
         JitsiMeetLogger.i("Using " + TAG + " as the audio device handler");
160
         JitsiMeetLogger.i("Using " + TAG + " as the audio device handler");
160
 
161
 
161
         module = audioModeModule;
162
         module = audioModeModule;
162
-        audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
163
+        Context context = module.getContext();
163
 
164
 
164
         // Setup runtime device change detection.
165
         // Setup runtime device change detection.
165
         //
166
         //

+ 23
- 6
android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java 查看文件

17
 package org.jitsi.meet.sdk;
17
 package org.jitsi.meet.sdk;
18
 
18
 
19
 import android.content.Context;
19
 import android.content.Context;
20
+import android.media.AudioManager;
20
 import android.os.Build;
21
 import android.os.Build;
21
 
22
 
22
 import com.facebook.react.bridge.Arguments;
23
 import com.facebook.react.bridge.Arguments;
85
         return supportsConnectionService && useConnectionService_;
86
         return supportsConnectionService && useConnectionService_;
86
     }
87
     }
87
 
88
 
89
+    /**
90
+     * {@link AudioManager} instance used to interact with the Android audio
91
+     * subsystem.
92
+     */
93
+    private AudioManager audioManager;
94
+
88
     private AudioDeviceHandlerInterface audioDeviceHandler;
95
     private AudioDeviceHandlerInterface audioDeviceHandler;
89
 
96
 
90
     /**
97
     /**
136
      */
143
      */
137
     public AudioModeModule(ReactApplicationContext reactContext) {
144
     public AudioModeModule(ReactApplicationContext reactContext) {
138
         super(reactContext);
145
         super(reactContext);
146
+
147
+        audioManager = (AudioManager)reactContext.getSystemService(Context.AUDIO_SERVICE);
139
     }
148
     }
140
 
149
 
141
     /**
150
     /**
212
         }
221
         }
213
 
222
 
214
         if (useConnectionService()) {
223
         if (useConnectionService()) {
215
-            audioDeviceHandler = new AudioDeviceHandlerConnectionService();
224
+            audioDeviceHandler = new AudioDeviceHandlerConnectionService(audioManager);
216
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
225
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
217
-            audioDeviceHandler = new AudioDeviceHandlerGeneric();
226
+            audioDeviceHandler = new AudioDeviceHandlerGeneric(audioManager);
218
         } else {
227
         } else {
219
-            audioDeviceHandler = new AudioDeviceHandlerLegacy();
228
+            audioDeviceHandler = new AudioDeviceHandlerLegacy(audioManager);
220
         }
229
         }
221
 
230
 
222
-        audioDeviceHandler.start(getReactApplicationContext(), this);
231
+        audioDeviceHandler.start(this);
223
     }
232
     }
224
 
233
 
225
     /**
234
     /**
418
         }
427
         }
419
     }
428
     }
420
 
429
 
430
+    /**
431
+     * Needed on the legacy handler...
432
+     *
433
+     * @return Context for the application.
434
+     */
435
+    Context getContext() {
436
+        return getReactApplicationContext();
437
+    }
438
+
421
     /**
439
     /**
422
      * Interface for the modules implementing the actual audio device management.
440
      * Interface for the modules implementing the actual audio device management.
423
      */
441
      */
424
     interface AudioDeviceHandlerInterface {
442
     interface AudioDeviceHandlerInterface {
425
         /**
443
         /**
426
          * Start detecting audio device changes.
444
          * Start detecting audio device changes.
427
-         * @param context Android {@link Context} where detection should take place.
428
          * @param audioModeModule Reference to the main {@link AudioModeModule}.
445
          * @param audioModeModule Reference to the main {@link AudioModeModule}.
429
          */
446
          */
430
-        void start(Context context, AudioModeModule audioModeModule);
447
+        void start(AudioModeModule audioModeModule);
431
 
448
 
432
         /**
449
         /**
433
          * Stop audio device detection.
450
          * Stop audio device detection.

正在加载...
取消
保存