About Gtalk
程序员文章站
2022-03-28 16:15:06
问题:Gtalkhttp://androidxref.com/2.3.6/xref/frameworks/base/media/java/android/media/AudioService.java#706705 /** @see AudioManager#setMode(int) */706 public void setMode(int mode, IB...
问题:Gtalk
http://androidxref.com/2.3.6/xref/frameworks/base/media/java/android/media/AudioService.java#706
705 /** @see AudioManager#setMode(int) */
706 public void setMode(int mode, IBinder cb) {
707 if (!checkAudioSettingsPermission("setMode()")) {
708 return;
709 }
710
711 if (mode < AudioSystem.MODE_CURRENT || mode >= AudioSystem.NUM_MODES) {
712 return;
713 }
714
715 synchronized (mSettingsLock) {
716 if (mode == AudioSystem.MODE_CURRENT) {
717 mode = mMode;
718 }
719 if (mode != mMode) {
720 if (AudioSystem.setPhoneState(mode) == AudioSystem.AUDIO_STATUS_OK) {
721 mMode = mode;
722
723 synchronized(mSetModeDeathHandlers) {
724 SetModeDeathHandler hdlr = null;
725 Iterator iter = mSetModeDeathHandlers.iterator();
726 while (iter.hasNext()) {
727 SetModeDeathHandler h = (SetModeDeathHandler)iter.next();
728 if (h.getBinder() == cb) {
729 hdlr = h;
730 // Remove from client list so that it is re-inserted at top of list
731 iter.remove();
732 break;
733 }
734 }
735 if (hdlr == null) {
736 hdlr = new SetModeDeathHandler(cb);
737 // cb is null when setMode() is called by AudioService constructor
738 if (cb != null) {
739 // Register for client death notification
740 try {
741 cb.linkToDeath(hdlr, 0);
742 } catch (RemoteException e) {
743 // Client has died!
744 Log.w(TAG, "setMode() could not link to "+cb+" binder death");
745 }
746 }
747 }
748 // Last client to call setMode() is always at top of client list
749 // as required by SetModeDeathHandler.binderDied()
750 mSetModeDeathHandlers.add(0, hdlr);
751 hdlr.setMode(mode);
752 }
753
754 if (mode != AudioSystem.MODE_NORMAL) {
755 clearAllScoClients();
756 }
757 }
758 }
759 int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
760 int index = mStreamStates[STREAM_VOLUME_ALIAS[streamType]].mIndex;
761 setStreamVolumeInt(STREAM_VOLUME_ALIAS[streamType], index, true, false);
762 }
763 }
764
http://androidxref.com/4.0.4/xref/frameworks/base/media/java/android/media/AudioService.java#854
853 /** @see AudioManager#setMode(int) */
854 public void setMode(int mode, IBinder cb) {
855 if (!checkAudioSettingsPermission("setMode()")) {
856 return;
857 }
858
859 if (mode < AudioSystem.MODE_CURRENT || mode >= AudioSystem.NUM_MODES) {
860 return;
861 }
862
863 int newModeOwnerPid = 0;
864 synchronized(mSetModeDeathHandlers) {
865 if (mode == AudioSystem.MODE_CURRENT) {
866 mode = mMode;
867 }
868 newModeOwnerPid = setModeInt(mode, cb, Binder.getCallingPid());
869 }
870 // when entering RINGTONE, IN_CALL or IN_COMMUNICATION mode, clear all
871 // SCO connections not started by the application changing the mode
872 if (newModeOwnerPid != 0) {
873 disconnectBluetoothSco(newModeOwnerPid);
874 }
875 }
876
877 // must be called synchronized on mSetModeDeathHandlers
878 // setModeInt() returns a valid PID if the audio mode was successfully set to
879 // any mode other than NORMAL.
880 int setModeInt(int mode, IBinder cb, int pid) {
881 int newModeOwnerPid = 0;
882 if (cb == null) {
883 Log.e(TAG, "setModeInt() called with null binder");
884 return newModeOwnerPid;
885 }
886
887 SetModeDeathHandler hdlr = null;
888 Iterator iter = mSetModeDeathHandlers.iterator();
889 while (iter.hasNext()) {
890 SetModeDeathHandler h = (SetModeDeathHandler)iter.next();
891 if (h.getPid() == pid) {
892 hdlr = h;
893 // Remove from client list so that it is re-inserted at top of list
894 iter.remove();
895 hdlr.getBinder().unlinkToDeath(hdlr, 0);
896 break;
897 }
898 }
899 int status = AudioSystem.AUDIO_STATUS_OK;
900 do {
901 if (mode == AudioSystem.MODE_NORMAL) {
902 // get new mode from client at top the list if any
903 if (!mSetModeDeathHandlers.isEmpty()) {
904 hdlr = mSetModeDeathHandlers.get(0);
905 cb = hdlr.getBinder();
906 mode = hdlr.getMode();
907 }
908 } else {
909 if (hdlr == null) {
910 hdlr = new SetModeDeathHandler(cb, pid);
911 }
912 // Register for client death notification
913 try {
914 cb.linkToDeath(hdlr, 0);
915 } catch (RemoteException e) {
916 // Client has died!
917 Log.w(TAG, "setMode() could not link to "+cb+" binder death");
918 }
919
920 // Last client to call setMode() is always at top of client list
921 // as required by SetModeDeathHandler.binderDied()
922 mSetModeDeathHandlers.add(0, hdlr);
923 hdlr.setMode(mode);
924 }
925
926 if (mode != mMode) {
927 status = AudioSystem.setPhoneState(mode);
928 if (status == AudioSystem.AUDIO_STATUS_OK) {
929 // automatically handle audio focus for mode changes
930 handleFocusForCalls(mMode, mode, cb);
931 mMode = mode;
932 } else {
933 if (hdlr != null) {
934 mSetModeDeathHandlers.remove(hdlr);
935 cb.unlinkToDeath(hdlr, 0);
936 }
937 // force reading new top of mSetModeDeathHandlers stack
938 mode = AudioSystem.MODE_NORMAL;
939 }
940 } else {
941 status = AudioSystem.AUDIO_STATUS_OK;
942 }
943 } while (status != AudioSystem.AUDIO_STATUS_OK && !mSetModeDeathHandlers.isEmpty());
944
945 if (status == AudioSystem.AUDIO_STATUS_OK) {
946 if (mode != AudioSystem.MODE_NORMAL) {
947 if (mSetModeDeathHandlers.isEmpty()) {
948 Log.e(TAG, "setMode() different from MODE_NORMAL with empty mode client stack");
949 } else {
950 newModeOwnerPid = mSetModeDeathHandlers.get(0).getPid();
951 }
952 }
953 int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
954 int index = mStreamStates[STREAM_VOLUME_ALIAS[streamType]].mIndex;
955 setStreamVolumeInt(STREAM_VOLUME_ALIAS[streamType], index, true, false);
956 }
957 return newModeOwnerPid;
958 }
959
本文地址:https://blog.csdn.net/LongZh_CN/article/details/12196427
下一篇: Android手势滑动实现
推荐阅读
-
javascript asp教程More About Recordsets
-
解析android中的帮助、about、关于作者、HELP等提示页面
-
javascript asp教程More About Recordsets
-
Review: Basic Knowledge about WebForm
-
解析android中的帮助、about、关于作者、HELP等提示页面
-
Python接收Gmail新邮件并发送到gtalk的方法
-
全能PDF编辑软件All About PDF安装及激活教程(附注册机下载)
-
About Windows 10 SDK Preview Build 17110
-
Android Studio完美解决 you are about to commit crlf line separators,warning: CRLF will be replaced by LF
-
ios的警告不针对react native A warning from Apple [resolved, not about React Native]