这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit 62c713a

Browse files
Fixed: Catch rare RuntimeException while loading bell and use if instead of case
``` java.lang.RuntimeException: Unable to resume activity {com.termux/com.termux.app.TermuxActivity}: android.content.res.Resources$NotFoundException: File res/raw/bell.ogg from drawable resource ID #0x7f0f0001 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3480) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3520) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1554) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6247) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107) Caused by: android.content.res.Resources$NotFoundException: File res/raw/bell.ogg from drawable resource ID #0x7f0f0001 at android.content.res.ResourcesImpl.openRawResourceFd(ResourcesImpl.java:308) at android.content.res.Resources.openRawResourceFd(Resources.java:1272) at android.media.SoundPool.load(SoundPool.java:247) at com.termux.app.terminal.TermuxTerminalSessionClient.getBellSoundPool(TermuxTerminalSessionClient.java:257) at com.termux.app.terminal.TermuxTerminalSessionClient.onResume(TermuxTerminalSessionClient.java:82) at com.termux.app.TermuxActivity.onResume(TermuxActivity.java:290) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1270) at android.app.Activity.performResume(Activity.java:6861) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3457) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3520) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1554) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6247) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107) Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed at android.content.res.AssetManager.openNonAssetFdNative(Native Method) at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:467) at android.content.res.ResourcesImpl.openRawResourceFd(ResourcesImpl.java:306) at android.content.res.Resources.openRawResourceFd(Resources.java:1272) at android.media.SoundPool.load(SoundPool.java:247) at com.termux.app.terminal.TermuxTerminalSessionClient.getBellSoundPool(TermuxTerminalSessionClient.java:257) at com.termux.app.terminal.TermuxTerminalSessionClient.onResume(TermuxTerminalSessionClient.java:82) at com.termux.app.TermuxActivity.onResume(TermuxActivity.java:290) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1270) at android.app.Activity.performResume(Activity.java:6861) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3457) ``` at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3520) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1554) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6247) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
1 parent 93fcf5e commit 62c713a

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

app/src/main/java/com/termux/window/TermuxFloatSessionClient.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void onAttachedToWindow() {
4545
// Just initialize the mBellSoundPool and load the sound, otherwise bell might not run
4646
// the first time bell key is pressed and play() is called, since sound may not be loaded
4747
// quickly enough before the call to play(). https://stackoverflow.com/questions/35435625
48-
getBellSoundPool();
48+
loadBellSoundPool();
4949
}
5050

5151
/**
@@ -102,16 +102,15 @@ public void onPasteTextFromClipboard(TerminalSession session) {
102102
public void onBell(TerminalSession session) {
103103
if (!mView.isVisible()) return;
104104

105-
switch (mView.getProperties().getBellBehaviour()) {
106-
case TermuxPropertyConstants.IVALUE_BELL_BEHAVIOUR_VIBRATE:
107-
BellHandler.getInstance(mService).doBell();
108-
break;
109-
case TermuxPropertyConstants.IVALUE_BELL_BEHAVIOUR_BEEP:
110-
getBellSoundPool().play(mBellSoundId, 1.f, 1.f, 1, 0, 1.f);
111-
break;
112-
case TermuxPropertyConstants.IVALUE_BELL_BEHAVIOUR_IGNORE:
113-
// Ignore the bell character.
114-
break;
105+
int bellBehaviour = mView.getProperties().getBellBehaviour();
106+
if (bellBehaviour == TermuxPropertyConstants.IVALUE_BELL_BEHAVIOUR_VIBRATE) {
107+
BellHandler.getInstance(mService).doBell();
108+
} else if (bellBehaviour == TermuxPropertyConstants.IVALUE_BELL_BEHAVIOUR_BEEP) {
109+
loadBellSoundPool();
110+
if (mBellSoundPool != null)
111+
mBellSoundPool.play(mBellSoundId, 1.f, 1.f, 1, 0, 1.f);
112+
} else if (bellBehaviour == TermuxPropertyConstants.IVALUE_BELL_BEHAVIOUR_IGNORE) {
113+
// Ignore the bell character.
115114
}
116115
}
117116

@@ -127,17 +126,20 @@ public Integer getTerminalCursorStyle() {
127126
}
128127

129128

130-
/** Initialize and get mBellSoundPool */
131-
private synchronized SoundPool getBellSoundPool() {
129+
/** Load mBellSoundPool */
130+
private synchronized void loadBellSoundPool() {
132131
if (mBellSoundPool == null) {
133132
mBellSoundPool = new SoundPool.Builder().setMaxStreams(1).setAudioAttributes(
134133
new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
135134
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION).build()).build();
136135

137-
mBellSoundId = mBellSoundPool.load(mService, R.raw.bell, 1);
136+
try {
137+
mBellSoundId = mBellSoundPool.load(mService, com.termux.shared.R.raw.bell, 1);
138+
} catch (Exception e){
139+
// Catch java.lang.RuntimeException: Unable to resume activity {com.termux/com.termux.app.TermuxActivity}: android.content.res.Resources$NotFoundException: File res/raw/bell.ogg from drawable resource ID
140+
Logger.logStackTraceWithMessage(LOG_TAG, "Failed to load bell sound pool", e);
141+
}
138142
}
139-
140-
return mBellSoundPool;
141143
}
142144

143145
/** Release mBellSoundPool resources */

0 commit comments

Comments
 (0)