More defensive programming around odd Android exceptions

This commit is contained in:
Sean Owen 2017-06-04 15:51:39 +01:00
parent 458923c3cd
commit 9fae90bc3c
3 changed files with 12 additions and 2 deletions

View file

@ -25,6 +25,8 @@ import android.os.AsyncTask;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.util.Log; import android.util.Log;
import java.util.concurrent.RejectedExecutionException;
/** /**
* Finishes an activity after a period of inactivity if the device is on battery power. * Finishes an activity after a period of inactivity if the device is on battery power.
*/ */
@ -49,7 +51,11 @@ final class InactivityTimer {
synchronized void onActivity() { synchronized void onActivity() {
cancel(); cancel();
inactivityTask = new InactivityAsyncTask(); inactivityTask = new InactivityAsyncTask();
try {
inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (RejectedExecutionException ree) {
Log.w(TAG, "Couldn't schedule inactivity task; ignoring");
}
} }
synchronized void onPause() { synchronized void onPause() {

View file

@ -41,7 +41,7 @@ public final class ClipboardInterface {
if (text != null) { if (text != null) {
try { try {
getManager(context).setPrimaryClip(ClipData.newPlainText(null, text)); getManager(context).setPrimaryClip(ClipData.newPlainText(null, text));
} catch (NullPointerException | IllegalStateException e) { } catch (NullPointerException | IllegalStateException | SecurityException e) {
// Have seen this in the wild, bizarrely // Have seen this in the wild, bizarrely
Log.w(TAG, "Clipboard bug", e); Log.w(TAG, "Clipboard bug", e);
} }

View file

@ -16,6 +16,7 @@
package com.google.zxing.client.android.history; package com.google.zxing.client.android.history;
import android.database.CursorIndexOutOfBoundsException;
import android.database.SQLException; import android.database.SQLException;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result; import com.google.zxing.Result;
@ -112,6 +113,9 @@ public final class HistoryManager {
Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp); Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
items.add(new HistoryItem(result, display, details)); items.add(new HistoryItem(result, display, details));
} }
} catch (CursorIndexOutOfBoundsException cioobe) {
Log.w(TAG, cioobe);
// continue
} finally { } finally {
close(cursor, db); close(cursor, db);
} }