Fixed some sporadic crashes.

git-svn-id: https://zxing.googlecode.com/svn/trunk@1151 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2009-12-11 17:49:11 +00:00
parent ef4cdf1969
commit 04ffa93742
3 changed files with 27 additions and 2 deletions

View file

@ -56,6 +56,7 @@
<string name="menu_history">History</string>
<string name="menu_share">Share</string>
<string name="msg_about">Based on the open source ZXing Barcode Library</string>
<string name="msg_camera_framework_bug">Sorry, the Android camera encountered a problem. You may need to restart the device.</string>
<string name="msg_default_contents">Contents</string>
<string name="msg_default_format">Format</string>
<string name="msg_default_mms_subject">Hi</string>

View file

@ -114,7 +114,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private String decodeMode;
private String versionName;
private HistoryManager historyManager;
private final OnCompletionListener beepListener = new BeepListener();
private final DialogInterface.OnClickListener aboutListener =
@ -233,7 +233,9 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
return true;
} else if ((source == Source.NONE || source == Source.ZXING_LINK) && lastResult != null) {
resetStatusView();
handler.sendEmptyMessage(R.id.restart_preview);
if (handler != null) {
handler.sendEmptyMessage(R.id.restart_preview);
}
return true;
}
} else if (keyCode == KeyEvent.KEYCODE_FOCUS || keyCode == KeyEvent.KEYCODE_CAMERA) {
@ -546,6 +548,13 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
CameraManager.get().openDriver(surfaceHolder);
} catch (IOException ioe) {
Log.w(TAG, ioe);
displayFrameworkBugMessageAndExit();
return;
} catch (RuntimeException e) {
// Barcode Scanner has seen crashes in the wild of this variety:
// java.?lang.?RuntimeException: Fail to connect to camera service
Log.e(TAG, e.toString());
displayFrameworkBugMessageAndExit();
return;
}
if (handler == null) {
@ -554,6 +563,18 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
}
}
private void displayFrameworkBugMessageAndExit() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.app_name));
builder.setMessage(getString(R.string.msg_camera_framework_bug));
builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
builder.show();
}
private void resetStatusView() {
resultView.setVisibility(View.GONE);
statusView.setVisibility(View.VISIBLE);

View file

@ -159,6 +159,9 @@ final class QRCodeEncoder {
return false;
} catch (IOException e) {
return false;
} catch (NullPointerException e) {
// In case the uri was not found in the Intent.
return false;
}
return contents != null && contents.length() > 0;
}