其他分享
首页 > 其他分享> > android中的开发者模式关闭USB路由的实现

android中的开发者模式关闭USB路由的实现

作者:互联网

content://settings/secure/usb_audio_automatic_routing_disabled

frameworks/base/services/usb/java/com/android/server/usb/UsbAlsaManager.java

// 当有usb设备连接到手机上的时候,会将事件先通知到java层usb的manager来,然后执行selectAlsaDevice函数,进行判断是否将设备注册到音频系统,从而干预到声音的路由行为
135      private synchronized void selectAlsaDevice(UsbAlsaDevice alsaDevice) {
              ...
             // content://settings/secure/usb_audio_automatic_routing_disabled
150          int isDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
151                  Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0);
152          if (isDisabled != 0) {
153              return;
154          }
155  
156          mSelectedDevice = alsaDevice;
157          alsaDevice.start();
161      }

//alsaDevice.start()
163      public synchronized void start() {
164          mSelected = true;
165          mInputState = 0;
166          mOutputState = 0;
167          startJackDetect();
168          updateWiredDeviceConnectionState(true);
169      }

// updateWiredDeviceConnectionState(true);
181      public synchronized void updateWiredDeviceConnectionState(boolean enable) {
191              // Output Device
192              if (mHasOutput) {
193                  int device = mIsOutputHeadset
194                          ? AudioSystem.DEVICE_OUT_USB_HEADSET
195                          : AudioSystem.DEVICE_OUT_USB_DEVICE;
201                  boolean connected = isOutputJackConnected();
203                  int outputState = (enable && connected) ? 1 : 0;
204                  if (outputState != mOutputState) {
205                      mOutputState = outputState;
                         // 耳机的spk注册到音频系统
206                      mAudioService.setWiredDeviceConnectionState(device, outputState,
207                                                                  alsaCardDeviceString,
208                                                                  mDeviceName, TAG);
209                  }
210              }
211  
212              // Input Device
213              if (mHasInput) {
214                  int device = mIsInputHeadset ? AudioSystem.DEVICE_IN_USB_HEADSET
215                          : AudioSystem.DEVICE_IN_USB_DEVICE;
216                  boolean connected = isInputJackConnected();
218                  int inputState = (enable && connected) ? 1 : 0;
219                  if (inputState != mInputState) {
220                      mInputState = inputState;
                         // 耳机的mic注册到音频系统
221                      mAudioService.setWiredDeviceConnectionState(
222                              device, inputState, alsaCardDeviceString,
223                              mDeviceName, TAG);
224                  }
225              }
229      }

标签:USB,int,AudioSystem,开发者,DEVICE,inputState,android,usb
来源: https://blog.csdn.net/Death__Azreal/article/details/118422268