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      }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值