bug 622695 - allow android's logger to handle logging exceptions r=mbrubeck a=blocking-fennec
authorBrad Lassey <blassey@mozilla.com>
Mon, 03 Jan 2011 17:34:44 -0500
changeset 59799 736fd3b7b3feaabdcd19fe57e859b7027aeb838c
parent 59798 322a2dca6977ec990f277ce1cd0f4faa40bcc096
child 59800 cf4a04eb066ed5c66915279c5c97f93dcf38e077
push idunknown
push userunknown
push dateunknown
reviewersmbrubeck, blocking-fennec
bugs622695
milestone2.0b9pre
bug 622695 - allow android's logger to handle logging exceptions r=mbrubeck a=blocking-fennec
embedding/android/GeckoApp.java
embedding/android/GeckoInputConnection.java
embedding/android/GeckoSurfaceView.java
embedding/android/NotificationHandler.java.in
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -118,19 +118,21 @@ abstract public class GeckoApp
     {
         if (!checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
             return false;
 
         // unpack files in the components directory
         try {
             unpackComponents();
         } catch (FileNotFoundException fnfe) {
+            Log.e("GeckoApp", "error unpacking components", fnfe);
             showErrorDialog(getString(R.string.error_loading_file));
             return false;
         } catch (IOException ie) {
+            Log.e("GeckoApp", "error unpacking components", ie);
             String msg = ie.getMessage();
             if (msg.equalsIgnoreCase("No space left on device"))
                 showErrorDialog(getString(R.string.no_space_to_start_error));
             else
                 showErrorDialog(getString(R.string.error_loading_file));
             return false;
         }
 
@@ -407,17 +409,17 @@ abstract public class GeckoApp
             intent.setClassName(getPackageName(),
                                 getPackageName() + ".Restarter");
             addEnvToIntent(intent);
             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                             Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
             Log.i("GeckoAppJava", intent.toString());
             startActivity(intent);
         } catch (Exception e) {
-            Log.i("GeckoAppJava", e.toString());
+            Log.i("GeckoAppJava", "error doing restart", e);
         }
         finish();
     }
 
     public void handleNotification(String action, String alertName, String alertCookie) {
         GeckoAppShell.handleNotification(action, alertName, alertCookie);
     }
 
@@ -454,44 +456,44 @@ abstract public class GeckoApp
                 Log.i("GeckoAppJava", amCmd);
                 Runtime.getRuntime().exec(amCmd);
                 statusCode = 0; // OK
             } else {
                 Log.i("GeckoAppJava", "Cannot rename the update file!");
                 statusCode = 7; // WRITE_ERROR
             }
         } catch (Exception e) {
-            Log.i("GeckoAppJava", e.toString());
+            Log.i("GeckoAppJava", "error launching installer to update", e);
         }
 
         // Update the status file
         String status = statusCode == 0 ? "succeeded\n" : "failed: "+ statusCode + "\n";
 
         OutputStream outStream;
         try {
             byte[] buf = status.getBytes("UTF-8");
             outStream = new FileOutputStream(statusFile);
             outStream.write(buf, 0, buf.length);
             outStream.close();
         } catch (Exception e) {
-            Log.i("GeckoAppJava", e.toString());
+            Log.i("GeckoAppJava", "error writing status file", e);
         }
 
         if (statusCode == 0)
             System.exit(0);
     }
 
     private String readUpdateStatus(File statusFile) {
         String status = "";
         try {
             BufferedReader reader = new BufferedReader(new FileReader(statusFile));
             status = reader.readLine();
             reader.close();
         } catch (Exception e) {
-            Log.i("GeckoAppJava", e.toString());
+            Log.i("GeckoAppJava", "error reading update status", e);
         }
         return status;
     }
 
     static final int FILE_PICKER_REQUEST = 1;
 
     private SynchronousQueue<String> mFilePickerResult = new SynchronousQueue();
     public String showFilePicker(String aMimeType) {
@@ -501,17 +503,17 @@ abstract public class GeckoApp
         GeckoApp.this.
             startActivityForResult(
                 Intent.createChooser(intent,"choose a file"),
                 FILE_PICKER_REQUEST);
         String filePickerResult = "";
         try {
             filePickerResult = mFilePickerResult.take();
         } catch (InterruptedException e) {
-            Log.i("GeckoApp", "error: " + e);
+            Log.i("GeckoApp", "showing file picker ",  e);
         }
         
         return filePickerResult;
     }
     
     @Override
     protected void onActivityResult(int requestCode, int resultCode, 
                                     Intent data) {
@@ -536,18 +538,18 @@ abstract public class GeckoApp
                 int len = is.read(buf);
                 while (len != -1) {
                     fos.write(buf, 0, len);
                     len = is.read(buf);
                 }
                 fos.close();
                 filePickerResult =  file.getAbsolutePath();
             }catch (Exception e) {
-                Log.e("GeckoApp", "error : "+ e);
+                Log.e("GeckoApp", "showing file picker", e);
             }
         }
         try {
             mFilePickerResult.put(filePickerResult);
         } catch (InterruptedException e) {
-            Log.i("GeckoApp", "error: " + e);
+            Log.i("GeckoApp", "error returning file picker result", e);
         }
     }
 }
--- a/embedding/android/GeckoInputConnection.java
+++ b/embedding/android/GeckoInputConnection.java
@@ -1,9 +1,9 @@
-/* -*- Mode: Java; tab-width: 20; indent-tabs-mode: nil; -*-
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -104,17 +104,17 @@ public class GeckoInputConnection
 
         // Select text to be deleted
         int delStart, delLen;
         GeckoAppShell.sendEventToGecko(
             new GeckoEvent(GeckoEvent.IME_GET_SELECTION, 0, 0));
         try {
             mQueryResult.take();
         } catch (InterruptedException e) {
-            Log.e("GeckoAppJava", "IME: deleteSurroundingText interrupted");
+            Log.e("GeckoAppJava", "IME: deleteSurroundingText interrupted", e);
             return false;
         }
         delStart = mSelectionStart > leftLength ?
                     mSelectionStart - leftLength : 0;
         delLen = mSelectionStart + rightLength - delStart;
         GeckoAppShell.sendEventToGecko(
             new GeckoEvent(GeckoEvent.IME_SET_SELECTION, delStart, delLen));
 
@@ -189,17 +189,17 @@ public class GeckoInputConnection
         // First we need to ask Gecko to tell us the full contents of the
         // text field we're about to operate on.
         String text;
         GeckoAppShell.sendEventToGecko(
             new GeckoEvent(GeckoEvent.IME_GET_TEXT, 0, Integer.MAX_VALUE));
         try {
             text = mQueryResult.take();
         } catch (InterruptedException e) {
-            Log.e("GeckoAppJava", "IME: performContextMenuAction interrupted");
+            Log.e("GeckoAppJava", "IME: performContextMenuAction interrupted", e);
             return false;
         }
 
         switch (id) {
             case R.id.selectAll:
                 setSelection(0, text.length());
                 break;
             case R.id.cut:
@@ -219,17 +219,17 @@ public class GeckoInputConnection
                 // If there is no selection set, we must be doing "Copy All",
                 // otherwise, we need to get the selection from Gecko
                 if (mSelectionLength > 0) {
                     GeckoAppShell.sendEventToGecko(
                         new GeckoEvent(GeckoEvent.IME_GET_SELECTION, 0, 0));
                     try {
                         text = mQueryResult.take();
                     } catch (InterruptedException e) {
-                        Log.e("GeckoAppJava", "IME: performContextMenuAction interrupted");
+                        Log.e("GeckoAppJava", "IME: performContextMenuAction interrupted", e);
                         return false;
                     }
                 }
                 GeckoAppShell.setClipboardText(text);
                 break;
         }
         return true;
     }
@@ -246,48 +246,48 @@ public class GeckoInputConnection
         extract.partialStartOffset = -1;
         extract.partialEndOffset = -1;
 
         GeckoAppShell.sendEventToGecko(
             new GeckoEvent(GeckoEvent.IME_GET_SELECTION, 0, 0));
         try {
             mQueryResult.take();
         } catch (InterruptedException e) {
-            Log.e("GeckoAppJava", "IME: getExtractedText interrupted");
+            Log.e("GeckoAppJava", "IME: getExtractedText interrupted", e);
             return null;
         }
         extract.selectionStart = mSelectionStart;
         extract.selectionEnd = mSelectionStart + mSelectionLength;
 
         GeckoAppShell.sendEventToGecko(
             new GeckoEvent(GeckoEvent.IME_GET_TEXT, 0, Integer.MAX_VALUE));
         try {
             extract.startOffset = 0;
             extract.text = mQueryResult.take();
 
             if ((flags & GET_EXTRACTED_TEXT_MONITOR) != 0)
                 mUpdateRequest = req;
             return extract;
 
         } catch (InterruptedException e) {
-            Log.e("GeckoAppJava", "IME: getExtractedText interrupted");
+            Log.e("GeckoAppJava", "IME: getExtractedText interrupted", e);
             return null;
         }
     }
 
     @Override
     public CharSequence getTextAfterCursor(int length, int flags) {
         //Log.d("GeckoAppJava", "IME: getTextAfterCursor");
 
         GeckoAppShell.sendEventToGecko(
             new GeckoEvent(GeckoEvent.IME_GET_SELECTION, 0, 0));
         try {
             mQueryResult.take();
         } catch (InterruptedException e) {
-            Log.e("GeckoAppJava", "IME: getTextBefore/AfterCursor interrupted");
+            Log.e("GeckoAppJava", "IME: getTextBefore/AfterCursor interrupted", e);
             return null;
         }
 
         /* Compatible with both positive and negative length
             (no need for separate code for getTextBeforeCursor) */
         int textStart = mSelectionStart;
         int textLength = length;
 
@@ -300,17 +300,17 @@ public class GeckoInputConnection
           }
         }
 
         GeckoAppShell.sendEventToGecko(
             new GeckoEvent(GeckoEvent.IME_GET_TEXT, textStart, textLength));
         try {
             return mQueryResult.take();
         } catch (InterruptedException e) {
-            Log.e("GeckoAppJava", "IME: getTextBefore/AfterCursor: Interrupted!");
+            Log.e("GeckoAppJava", "IME: getTextBefore/AfterCursor: Interrupted!", e);
             return null;
         }
     }
 
     @Override
     public CharSequence getTextBeforeCursor(int length, int flags) {
         //Log.d("GeckoAppJava", "IME: getTextBeforeCursor");
 
@@ -326,17 +326,17 @@ public class GeckoInputConnection
 
         if (!mComposing) {
             // Get current selection
             GeckoAppShell.sendEventToGecko(
                 new GeckoEvent(GeckoEvent.IME_GET_SELECTION, 0, 0));
             try {
                 mQueryResult.take();
             } catch (InterruptedException e) {
-                Log.e("GeckoAppJava", "IME: setComposingText interrupted");
+                Log.e("GeckoAppJava", "IME: setComposingText interrupted", e);
                 return false;
             }
             // Make sure we are in a composition
             GeckoAppShell.sendEventToGecko(
                 new GeckoEvent(GeckoEvent.IME_COMPOSITION_BEGIN, 0, 0));
             mComposing = true;
             mCompositionStart = mSelectionLength >= 0 ?
                 mSelectionStart : mSelectionStart + mSelectionLength;
--- a/embedding/android/GeckoSurfaceView.java
+++ b/embedding/android/GeckoSurfaceView.java
@@ -170,17 +170,17 @@ class GeckoSurfaceView
         } finally {
             mSurfaceLock.unlock();
         }
 
         ByteBuffer bb = null;
         try {
             bb = mSyncBuf.take();
         } catch (InterruptedException ie) {
-            Log.e("GeckoAppJava", "Threw exception while getting sync buf: " + ie);
+            Log.e("GeckoAppJava", "Threw exception while getting sync buf: ", ie);
         }
         if (bb != null && bb.capacity() == (width * height * 2)) {
             mSoftwareBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.RGB_565);
             mSoftwareBitmap.copyPixelsFromBuffer(bb);
             Canvas c = holder.lockCanvas();
             c.drawBitmap(mSoftwareBitmap, 0, 0, null);
             holder.unlockCanvasAndPost(c);
         }
@@ -284,17 +284,17 @@ class GeckoSurfaceView
         try {
             if (mSyncDraw) {
                 if (buffer != mSoftwareBuffer || stride != (mWidth * 2))
                     return;
                 mSyncDraw = false;
                 try {
                     mSyncBuf.put(buffer);
                 } catch (InterruptedException ie) {
-                    Log.e("GeckoAppJava", "Threw exception while getting sync buf: " + ie);
+                    Log.e("GeckoAppJava", "Threw exception while getting sync buf: ", ie);
                 }
                 return;
             }
         } finally {
             mSurfaceLock.unlock();
         }
 
         if (buffer != mSoftwareBuffer || stride != (mWidth * 2))
--- a/embedding/android/NotificationHandler.java.in
+++ b/embedding/android/NotificationHandler.java.in
@@ -1,9 +1,9 @@
-/* -*- Mode: Java; tab-width: 20; indent-tabs-mode: nil; -*-
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -89,13 +89,13 @@ public class NotificationHandler
         if (App.ACTION_ALERT_CLICK.equals(action)) {
             // Start or bring to front the main activity
             Intent appIntent = new Intent(Intent.ACTION_MAIN);
             appIntent.setClassName(context, "@ANDROID_PACKAGE_NAME@.App");
             appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             try {
                 context.startActivity(appIntent);
             } catch (ActivityNotFoundException e) {
-                Log.e("GeckoAppJava", "NotificationHandler Exception: " + e.getMessage());
+                Log.e("GeckoAppJava", "NotificationHandler Exception: ", e);
             }
         }
     }
 }