mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Fixed: Catch rare RuntimeException while loading bell
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)
This commit is contained in:
@@ -79,7 +79,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
// Just initialize the mBellSoundPool and load the sound, otherwise bell might not run
|
||||
// the first time bell key is pressed and play() is called, since sound may not be loaded
|
||||
// quickly enough before the call to play(). https://stackoverflow.com/questions/35435625
|
||||
getBellSoundPool();
|
||||
loadBellSoundPool();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,7 +202,9 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
BellHandler.getInstance(mActivity).doBell();
|
||||
break;
|
||||
case TermuxPropertyConstants.IVALUE_BELL_BEHAVIOUR_BEEP:
|
||||
getBellSoundPool().play(mBellSoundId, 1.f, 1.f, 1, 0, 1.f);
|
||||
loadBellSoundPool();
|
||||
if (mBellSoundPool != null)
|
||||
mBellSoundPool.play(mBellSoundId, 1.f, 1.f, 1, 0, 1.f);
|
||||
break;
|
||||
case TermuxPropertyConstants.IVALUE_BELL_BEHAVIOUR_IGNORE:
|
||||
// Ignore the bell character.
|
||||
@@ -247,17 +249,20 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
|
||||
|
||||
|
||||
/** Initialize and get mBellSoundPool */
|
||||
private synchronized SoundPool getBellSoundPool() {
|
||||
/** Load mBellSoundPool */
|
||||
private synchronized void loadBellSoundPool() {
|
||||
if (mBellSoundPool == null) {
|
||||
mBellSoundPool = new SoundPool.Builder().setMaxStreams(1).setAudioAttributes(
|
||||
new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION).build()).build();
|
||||
|
||||
mBellSoundId = mBellSoundPool.load(mActivity, R.raw.bell, 1);
|
||||
try {
|
||||
mBellSoundId = mBellSoundPool.load(mActivity, R.raw.bell, 1);
|
||||
} catch (Exception e){
|
||||
// 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
|
||||
Logger.logStackTraceWithMessage(LOG_TAG, "Failed to load bell sound pool", e);
|
||||
}
|
||||
}
|
||||
|
||||
return mBellSoundPool;
|
||||
}
|
||||
|
||||
/** Release mBellSoundPool resources */
|
||||
|
Reference in New Issue
Block a user