blob: 8599f0b6d541d298980ffcbd37e66c2846c49ee5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package it.niedermann.nextcloud.deck.util;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException;
import com.nextcloud.android.sso.helper.VersionCheckHelper;
import com.nextcloud.android.sso.ui.UiExceptionManager;
import java.io.PrintWriter;
import java.io.StringWriter;
import it.niedermann.nextcloud.deck.BuildConfig;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.model.Account;
public class ExceptionUtil {
private ExceptionUtil() {
}
public static String getDebugInfos(@NonNull Context context, Throwable throwable, @Nullable Account account) {
return "" +
getAppVersions(context, account) +
"\n\n---\n" +
getDeviceInfos() +
"\n\n---" +
"\n\n" +
getStacktraceOf(throwable);
}
private static String getAppVersions(Context context, @Nullable Account account) {
String versions = ""
+ "App Version: " + BuildConfig.VERSION_NAME + "\n"
+ "App Version Code: " + BuildConfig.VERSION_CODE + "\n"
+ "App Flavor: " + BuildConfig.FLAVOR + "\n";
if (account != null) {
versions += "\n";
versions += "Deck Server Version: " + account.getServerDeckVersion() + "\n";
}
versions += "\n";
try {
versions += "Files App Version Code: " + VersionCheckHelper.getNextcloudFilesVersionCode(context);
} catch (PackageManager.NameNotFoundException e) {
versions += "Files App Version Code: " + e.getMessage();
e.printStackTrace();
}
return versions;
}
private static String getDeviceInfos() {
return ""
+ "\nOS Version: " + System.getProperty("os.version") + "(" + Build.VERSION.INCREMENTAL + ")"
+ "\nOS API Level: " + Build.VERSION.SDK_INT
+ "\nDevice: " + Build.DEVICE
+ "\nManufacturer: " + Build.MANUFACTURER
+ "\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")";
}
private static String getStacktraceOf(Throwable e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
@UiThread
public static void handleNextcloudFilesAppNotInstalledException(@NonNull Context context, @NonNull NextcloudFilesAppNotInstalledException exception) {
UiExceptionManager.showDialogForException(context, exception);
DeckLog.warn("=============================================================");
DeckLog.warn("Nextcloud app is not installed. Cannot choose account");
exception.printStackTrace();
}
}
|