diff --git a/app/build.gradle b/app/build.gradle index c55434a1..32eccdba 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,7 +34,7 @@ android { dependencies { implementation "com.github.nextcloud:Android-SingleSignOn:0.5.0-rc2" - implementation 'com.github.stefan-niedermann:nextcloud-commons:6250e5fe73' + implementation 'com.github.stefan-niedermann:nextcloud-commons:0.0.1' implementation 'com.yydcdut:markdown-processor:0.1.3' implementation 'com.yydcdut:rxmarkdown-wrapper:0.1.3' diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java index 5a081c0d..16654e21 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java @@ -14,11 +14,11 @@ import com.google.android.material.tabs.TabLayout; import butterknife.BindView; import butterknife.ButterKnife; +import it.niedermann.nextcloud.exception.ExceptionHandler; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.fragment.about.AboutFragmentContributingTab; import it.niedermann.owncloud.notes.android.fragment.about.AboutFragmentCreditsTab; import it.niedermann.owncloud.notes.android.fragment.about.AboutFragmentLicenseTab; -import it.niedermann.owncloud.notes.util.ExceptionHandler; public class AboutActivity extends AppCompatActivity { @@ -32,7 +32,7 @@ public class AboutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); + Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class)); setContentView(R.layout.activity_about); ButterKnife.bind(this); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java index fee85762..df65cc17 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java @@ -21,6 +21,7 @@ import java.util.Objects; import butterknife.BindView; import butterknife.ButterKnife; +import it.niedermann.nextcloud.exception.ExceptionHandler; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.fragment.BaseNoteFragment; import it.niedermann.owncloud.notes.android.fragment.NoteEditFragment; @@ -30,7 +31,6 @@ import it.niedermann.owncloud.notes.model.Category; import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.LocalAccount; -import it.niedermann.owncloud.notes.util.ExceptionHandler; import it.niedermann.owncloud.notes.util.NoteUtil; import static it.niedermann.owncloud.notes.android.fragment.AccountChooserAdapter.AccountChooserListener; @@ -55,7 +55,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); + Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class)); setContentView(R.layout.activity_edit); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java index 6917863c..1d35170a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java @@ -14,8 +14,10 @@ import androidx.appcompat.widget.Toolbar; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import it.niedermann.nextcloud.exception.ExceptionUtil; import it.niedermann.owncloud.notes.R; -import it.niedermann.owncloud.notes.util.ExceptionUtil; + +import static it.niedermann.nextcloud.exception.ExceptionHandler.KEY_THROWABLE; public class ExceptionActivity extends AppCompatActivity { @@ -28,8 +30,6 @@ public class ExceptionActivity extends AppCompatActivity { @BindView(R.id.stacktrace) TextView stacktrace; - public static final String KEY_THROWABLE = "T"; - @SuppressLint("SetTextI18n") // only used for logging @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -38,7 +38,6 @@ public class ExceptionActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setSupportActionBar(toolbar); throwable = ((Throwable) getIntent().getSerializableExtra(KEY_THROWABLE)); - throwable.printStackTrace(); toolbar.setTitle(getString(R.string.simple_error)); this.message.setText(throwable.getMessage()); this.stacktrace.setText(ExceptionUtil.getDebugInfos(this, throwable)); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java index ea8085b4..d6cf77b8 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java @@ -51,6 +51,7 @@ import java.util.Map; import butterknife.BindView; import butterknife.ButterKnife; +import it.niedermann.nextcloud.exception.ExceptionHandler; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.MultiSelectedActionModeCallback; import it.niedermann.owncloud.notes.android.NotesListViewItemTouchHelper; @@ -68,7 +69,6 @@ import it.niedermann.owncloud.notes.persistence.LoadNotesListTask; import it.niedermann.owncloud.notes.persistence.LoadNotesListTask.NotesLoadedListener; import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper; -import it.niedermann.owncloud.notes.util.ExceptionHandler; import it.niedermann.owncloud.notes.util.NoteUtil; import static it.niedermann.owncloud.notes.util.SSOUtil.askForNewAccount; @@ -155,7 +155,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); + Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class)); setContentView(R.layout.drawer_layout); ButterKnife.bind(this); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/PreferencesActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/PreferencesActivity.java index a30c0ede..b3e78a8a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/PreferencesActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/PreferencesActivity.java @@ -8,9 +8,9 @@ import androidx.appcompat.widget.Toolbar; import butterknife.BindView; import butterknife.ButterKnife; +import it.niedermann.nextcloud.exception.ExceptionHandler; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.fragment.PreferencesFragment; -import it.niedermann.owncloud.notes.util.ExceptionHandler; /** * Allows to change application settings. @@ -24,7 +24,7 @@ public class PreferencesActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); + Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class)); setContentView(R.layout.activity_preferences); ButterKnife.bind(this); setSupportActionBar(toolbar); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java index 56cb5c9b..3fb5998c 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java @@ -11,11 +11,11 @@ import android.view.View; import butterknife.BindView; import butterknife.ButterKnife; +import it.niedermann.nextcloud.exception.ExceptionHandler; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.appwidget.SingleNoteWidget; import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.Item; -import it.niedermann.owncloud.notes.util.ExceptionHandler; import it.niedermann.owncloud.notes.util.Notes; public class SelectSingleNoteActivity extends NotesListViewActivity { @@ -26,7 +26,7 @@ public class SelectSingleNoteActivity extends NotesListViewActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); + Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class)); setResult(Activity.RESULT_CANCELED); ButterKnife.bind(this); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SplashscreenActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SplashscreenActivity.java index a8ec91e9..c2beafef 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SplashscreenActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SplashscreenActivity.java @@ -5,7 +5,8 @@ import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; -import it.niedermann.owncloud.notes.util.ExceptionHandler; +import it.niedermann.nextcloud.exception.ExceptionHandler; + /** * Created by stefan on 18.04.17. @@ -15,7 +16,7 @@ public class SplashscreenActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); + Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class)); Intent intent = new Intent(this, NotesListViewActivity.class); startActivity(intent); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java index c4371b9a..bfbe899a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java @@ -42,6 +42,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import it.niedermann.nextcloud.exception.ExceptionUtil; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.model.DBNote; @@ -50,7 +51,6 @@ import it.niedermann.owncloud.notes.model.ISyncCallback; import it.niedermann.owncloud.notes.model.LocalAccount; import it.niedermann.owncloud.notes.model.LoginStatus; import it.niedermann.owncloud.notes.model.SyncResultStatus; -import it.niedermann.owncloud.notes.util.ExceptionUtil; import it.niedermann.owncloud.notes.util.SSOUtil; import it.niedermann.owncloud.notes.util.ServerResponse; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/ExceptionHandler.java b/app/src/main/java/it/niedermann/owncloud/notes/util/ExceptionHandler.java deleted file mode 100644 index 8bd9faa9..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/util/ExceptionHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -package it.niedermann.owncloud.notes.util; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; - -import java.io.Serializable; - -import it.niedermann.owncloud.notes.android.activity.ExceptionActivity; - -import static it.niedermann.owncloud.notes.android.activity.ExceptionActivity.KEY_THROWABLE; - -public class ExceptionHandler implements Thread.UncaughtExceptionHandler { - - private Activity context; - - public ExceptionHandler(Activity context) { - super(); - this.context = context; - } - - @Override - public void uncaughtException(Thread t, Throwable e) { - e.printStackTrace(); - Intent intent = new Intent(context.getApplicationContext(), ExceptionActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - Bundle extras = new Bundle(); - intent.putExtra(KEY_THROWABLE, (Serializable) e); - extras.putSerializable(KEY_THROWABLE, e); - intent.putExtras(extras); - context.getApplicationContext().startActivity(intent); - context.finish(); - Runtime.getRuntime().exit(0); - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/ExceptionUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/util/ExceptionUtil.java deleted file mode 100644 index 1778b83a..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/util/ExceptionUtil.java +++ /dev/null @@ -1,72 +0,0 @@ -package it.niedermann.owncloud.notes.util; - -import android.app.Activity; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; - -import com.nextcloud.android.sso.helper.VersionCheckHelper; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; - -public class ExceptionUtil { - - private ExceptionUtil() { - - } - - public static String getDebugInfos(Activity activity, Throwable throwable) { - List throwables = new ArrayList<>(); - throwables.add(throwable); - return getDebugInfos(activity, throwables); - } - - public static String getDebugInfos(Activity activity, List throwables) { - StringBuilder debugInfos = new StringBuilder("" - + getAppVersions(activity) - + "\n\n---\n" - + getDeviceInfos() - + "\n\n---" - + "\n\n"); - for (Throwable throwable : throwables) { - debugInfos.append(getStacktraceOf(throwable)); - } - return debugInfos.toString(); - } - - private static String getAppVersions(Activity activity) { - String versions = ""; - try { - PackageInfo pInfo = activity.getApplicationContext().getPackageManager().getPackageInfo(activity.getApplicationContext().getPackageName(), 0); - versions += "App Version: " + pInfo.versionName; - versions += "\nApp Version Code: " + pInfo.versionCode; - } catch (PackageManager.NameNotFoundException e) { - versions += "\nApp Version: " + e.getMessage(); - e.printStackTrace(); - } - - try { - versions += "\nFiles App Version Code: " + VersionCheckHelper.getNextcloudFilesVersionCode(activity); - } catch (PackageManager.NameNotFoundException e) { - versions += "\nFiles App Version Code: " + e.getMessage(); - e.printStackTrace(); - } - return versions; - } - - private static String getDeviceInfos() { - return "" - + "\nOS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")" - + "\nOS API Level: " + android.os.Build.VERSION.SDK_INT - + "\nDevice: " + android.os.Build.DEVICE - + "\nModel (and Product): " + android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")"; - } - - private static String getStacktraceOf(Throwable e) { - StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); - return sw.toString(); - } -}