dummy crash upload dialog
authorBartek Przybylski <bart.p.pl@gmail.com>
Wed, 13 Jun 2012 18:47:38 +0000 (20:47 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Wed, 13 Jun 2012 18:47:38 +0000 (20:47 +0200)
AndroidManifest.xml
res/values/strings.xml
src/eu/alefzero/owncloud/CrashHandler.java
src/eu/alefzero/owncloud/CrashlogSendActivity.java

index 5e2cdee..86af069 100644 (file)
             <intent-filter>
                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
             </intent-filter>\r
             <intent-filter>
                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
             </intent-filter>\r
-        </receiver>\r
+        </receiver>
+        <activity android:name="CrashlogSendActivity"></activity>\r
     </application>\r
 \r
 </manifest>
\ No newline at end of file
     </application>\r
 \r
 </manifest>
\ No newline at end of file
index e7bd45f..c111f8b 100644 (file)
     <string name="auth_unknow_error">Unknown error occured!</string>
     <string name="auth_login_details">Login details</string>
     
     <string name="auth_unknow_error">Unknown error occured!</string>
     <string name="auth_login_details">Login details</string>
     
+    <string name="crashlog_message">Application terminated unexpectedly. Would you like to submit crash report?</string>
+    <string name="crashlog_send_report">Send report</string>
+    <string name="crashlog_dont_send_report">Don\'t send report</string>
+    
     <string name="extensions_avail_title">Extensions available!</string>
     <string name="extensions_avail_message">Looks like your ownCloud instance is supporting advanced extensions. Would you like to see extensions available for android ?</string>
 </resources>
     <string name="extensions_avail_title">Extensions available!</string>
     <string name="extensions_avail_message">Looks like your ownCloud instance is supporting advanced extensions. Would you like to see extensions available for android ?</string>
 </resources>
index 69298e8..ffad248 100644 (file)
@@ -1,3 +1,21 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012  Bartek Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 package eu.alefzero.owncloud;
 
 import java.io.BufferedReader;
 package eu.alefzero.owncloud;
 
 import java.io.BufferedReader;
@@ -15,19 +33,25 @@ import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
 
 import android.accounts.Account;
 import android.accounts.AccountManager;
 
 import android.accounts.Account;
 import android.accounts.AccountManager;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Context;
+import android.content.Intent;
 import android.net.ConnectivityManager;
 import android.os.Environment;
 import android.util.Log;
 
 public class CrashHandler implements UncaughtExceptionHandler {
 
 import android.net.ConnectivityManager;
 import android.os.Environment;
 import android.util.Log;
 
 public class CrashHandler implements UncaughtExceptionHandler {
 
+    public static final String KEY_CRASH_FILENAME = "KEY_CRASH_FILENAME";
+    
     private Context mContext;
     private static final String TAG = "CrashHandler";
     private static final String crash_filename_template = "crash";
     private static List<String> TAGS;
     private UncaughtExceptionHandler defaultUEH;
     
     private Context mContext;
     private static final String TAG = "CrashHandler";
     private static final String crash_filename_template = "crash";
     private static List<String> TAGS;
     private UncaughtExceptionHandler defaultUEH;
     
+    // TODO: create base activity which will register for crashlog tag automaticly
     static {
         TAGS = new LinkedList<String>();
         TAGS.add("AccountAuthenticator");
     static {
         TAGS = new LinkedList<String>();
         TAGS.add("AccountAuthenticator");
@@ -99,9 +123,21 @@ public class CrashHandler implements UncaughtExceptionHandler {
             
             br.close();
             fw.close();
             
             br.close();
             fw.close();
-
+            
+            Intent dataintent = new Intent(mContext, CrashlogSendActivity.class);
+            dataintent.putExtra(KEY_CRASH_FILENAME, crashfile.getAbsolutePath());
+            PendingIntent intent = PendingIntent.getActivity(mContext.getApplicationContext(), 0, dataintent, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+            AlarmManager mngr = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
+            if (mngr == null) {
+                Log.e(TAG, "Couldn't retrieve alarm manager!");
+                defaultUEH.uncaughtException(thread, ex);
+                return;
+            }
+            mngr.set(AlarmManager.RTC, System.currentTimeMillis(), intent);
+            System.exit(2);
         } catch (Exception e1) {
         } catch (Exception e1) {
-            Log.e(TAG, "Crash handler failed to run logcat, WTF!");
+            Log.e(TAG, "Crash handler failed!");
+            Log.e(TAG, e1.toString());
             defaultUEH.uncaughtException(thread, ex);
             return;
         }
             defaultUEH.uncaughtException(thread, ex);
             return;
         }
index b921760..96331c2 100644 (file)
@@ -1,7 +1,83 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012  Bartek Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 package eu.alefzero.owncloud;
 
 package eu.alefzero.owncloud;
 
+import java.io.File;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnCancelListener;
+import android.content.DialogInterface.OnClickListener;
+import android.os.Bundle;
+import android.util.Log;
+
 import com.actionbarsherlock.app.SherlockActivity;
 
 import com.actionbarsherlock.app.SherlockActivity;
 
-public class CrashlogSendActivity extends SherlockActivity {
+public class CrashlogSendActivity extends SherlockActivity implements OnClickListener, OnCancelListener {
+    
+    private static final String TAG = "CrashlogSendActivity";
+    private static final int DIALOG_SUBMIT = 5;
+    
+    private String mLogFilename;
+    
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mLogFilename = getIntent().getStringExtra(CrashHandler.KEY_CRASH_FILENAME);
+        if (mLogFilename == null) {
+            Log.wtf(TAG, "No file crashlog path given!");
+            finish();
+            return;
+        }
+        Log.i(TAG, "crashlog file path " + mLogFilename);
+        
+        showDialog(DIALOG_SUBMIT);
+    }
+    
+
+    @Override
+    protected Dialog onCreateDialog(int id) {
+        if (id == DIALOG_SUBMIT) {
+            AlertDialog.Builder builder = new AlertDialog.Builder(this);
+            builder.setMessage(R.string.crashlog_message);
+            builder.setNegativeButton(R.string.crashlog_dont_send_report, this);
+            builder.setPositiveButton(R.string.crashlog_send_report, this);
+            builder.setCancelable(true);
+            builder.setOnCancelListener(this);
+            return builder.create();
+        }
+        return super.onCreateDialog(id);
+    }
+
+
+    @Override
+    public void onClick(DialogInterface dialog, int which) {
+        new File(mLogFilename).delete();
+        finish();
+    }
+
+
+    @Override
+    public void onCancel(DialogInterface dialog) {
+        new File(mLogFilename).delete();
+        finish();
+    }
 
 }
 
 }