diff --git a/embrace-android-sdk/api/embrace-android-sdk.api b/embrace-android-sdk/api/embrace-android-sdk.api index ba8babd84c..3b553b8ccf 100644 --- a/embrace-android-sdk/api/embrace-android-sdk.api +++ b/embrace-android-sdk/api/embrace-android-sdk.api @@ -111,14 +111,6 @@ public final class io/embrace/android/embracesdk/Embrace$LastRunEndState : java/ public static fun values ()[Lio/embrace/android/embracesdk/Embrace$LastRunEndState; } -public final class io/embrace/android/embracesdk/EmbraceSamples { - public static final field INSTANCE Lio/embrace/android/embracesdk/EmbraceSamples; - public static final fun causeNdkIllegalInstruction ()V - public static final fun throwJvmException ()V - public static final fun triggerAnr ()V - public static final fun triggerLongAnr ()V -} - public final class io/embrace/android/embracesdk/ViewSwazzledHooks { } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceSamples.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceSamples.kt deleted file mode 100644 index 92014730f2..0000000000 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceSamples.kt +++ /dev/null @@ -1,57 +0,0 @@ -package io.embrace.android.embracesdk - -import io.embrace.android.embracesdk.annotation.InternalApi -import io.embrace.android.embracesdk.samples.EmbraceCrashSamples - -/** - * Helps to verify and test embrace SDK integration. - * it allows users to execute code that automatically verifies the integration by calling the verifyIntegration method. - * It also provides example code to generate ANR and JVM/NDK crashes - * - * @suppress - */ -@InternalApi -public object EmbraceSamples { - - private val embraceCrashSamples = EmbraceCrashSamples - - /** - * Throw a custom JVM crash to be part of current session. - * - * It is recommended to implement this method call via a button press once the app has loaded. - * - * After a crash is sent, the app should be restarted in order to see the error in the dashboard. - * - * @throws EmbraceSampleCodeException - */ - @JvmStatic - public fun throwJvmException() { - embraceCrashSamples.throwJvmException() - } - - /** - * Force a short ANR that lasts 4 seconds - */ - @JvmStatic - public fun triggerAnr() { - embraceCrashSamples.blockMainThreadForShortInterval() - } - - /** - * Force a long ANR that lasts 30 seconds - */ - @JvmStatic - public fun triggerLongAnr() { - embraceCrashSamples.triggerLongAnr() - } - - // NDK Crashes sections - - /** - * Throws a ndk SigIllegalInstruction - */ - @JvmStatic - public fun causeNdkIllegalInstruction() { - embraceCrashSamples.triggerNdkSigIllegalInstruction() - } -} diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/ComparableVersion.java b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/ComparableVersion.java deleted file mode 100644 index 4bfe12ba50..0000000000 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/ComparableVersion.java +++ /dev/null @@ -1,405 +0,0 @@ -package io.embrace.android.embracesdk.samples; - -/* - Licensed under the Apache License,Version2.0(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.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing,software - distributed under the License is distributed on an"AS IS"BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -import androidx.annotation.NonNull; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Properties; -import java.util.Stack; - - -/** - * ComparableVersion.java was extracted from the Maven Versioning artifact. - * (org.apache.maven.artifact.versioning) - *
- * Generic implementation of version comparison. - *
- * Features: - *
- * mixing of '-' (hyphen) and '.' (dot) separators, - *
- * transition between characters and digits also constitutes a separator: - * 1.0alpha1 => [1, 0, alpha, 1] - *
- * Unlimited number of version components, - *
- * Version components in the text can be digits or strings, - *
- * strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering. - * Well-known qualifiers (case insensitive) are: - * - alpha or a - * - beta or b - * - milestone or m - * - rc or cr - * - snapshot - * - (the empty string) or ga or final - * - sp - *
- * Unknown qualifiers are considered after known qualifiers, with lexical order (always case insensitive), - *
- * a hyphen usually precedes a qualifier, and is always less important than something preceded with a dot.
- *
- * @author Kenney Westerhof
- * @author Hervé Boutemy
- * @see "Versioning" on Maven Wiki
- */
-
-@SuppressWarnings("unchecked")
-class ComparableVersion implements Comparable
- * This method takes into account the ordering of known qualifiers then unknown qualifiers with lexical
- * ordering.
- *
- * just returning an Integer with the index here is faster, but requires a lot of if/then/else to check for -1
- * or QUALIFIERS.size and then resort to lexical ordering. Most comparisons are decided by the first character,
- * so this is still fast. If more characters are needed then it requires a lexical sort anyway.
- *
- * @return an equivalent value that can be used with lexical comparison
- */
- public static String comparableQualifier(String qualifier) {
- int i = QUALIFIERS.indexOf(qualifier);
-
- return i == -1 ? (QUALIFIERS.size() + "-" + qualifier) : String.valueOf(i);
- }
-
- public int compareTo(Item item) {
- if (item == null) {
- // 1-rc < 1, 1-ga > 1
- return comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX);
- }
- switch (item.getType()) {
- case INTEGER_ITEM:
- return -1; // 1.any < 1.1 ?
-
- case STRING_ITEM:
- return comparableQualifier(value).compareTo(comparableQualifier(((StringItem) item).value));
-
- case LIST_ITEM:
- return -1; // 1.any < 1-1
-
- default:
- throw new RuntimeException("invalid item: " + item.getClass());
- }
- }
-
- public String toString() {
- return value;
- }
- }
-
- /**
- * Represents a version list item. This class is used both for the global item list and for sub-lists (which start
- * with '-(number)' in the version specification).
- */
- protected static class ListItem extends ArrayList implements Item {
- public int getType() {
- return LIST_ITEM;
- }
-
- public boolean isNull() {
- return (size() == 0);
- }
-
- void normalize() {
- for (int i = size() - 1; i >= 0; i--) {
- Item lastItem = (Item) get(i);
-
- if (lastItem.isNull()) {
- // remove null trailing items: 0, "", empty list
- remove(i);
- } else if (!(lastItem instanceof ListItem)) {
- break;
- }
- }
- }
-
- public int compareTo(Item item) {
- if (item == null) {
- if (size() == 0) {
- return 0; // 1-0 = 1- (normalize) = 1
- }
- Item first = (Item) get(0);
- return first.compareTo(null);
- }
- switch (item.getType()) {
- case INTEGER_ITEM:
- return -1; // 1-1 < 1.0.x
-
- case STRING_ITEM:
- return 1; // 1-1 > 1-sp
-
- case LIST_ITEM:
- Iterator left = iterator();
- Iterator right = ((ListItem) item).iterator();
-
- while (left.hasNext() || right.hasNext()) {
- Item l = left.hasNext() ? (Item) left.next() : null;
- Item r = right.hasNext() ? (Item) right.next() : null;
-
- // if this is shorter, then invert the compare and mul with -1
- int result = l == null ? (r == null ? 0 : -1 * r.compareTo(l)) : l.compareTo(r);
-
- if (result != 0) {
- return result;
- }
- }
-
- return 0;
-
- default:
- throw new RuntimeException("invalid item: " + item.getClass());
- }
- }
-
- public String toString() {
- StringBuilder buffer = new StringBuilder();
- for (Object item : this) {
- if (buffer.length() > 0) {
- buffer.append((item instanceof ListItem) ? '-' : '.');
- }
- buffer.append(item);
- }
- return buffer.toString();
- }
- }
-
- public ComparableVersion(@NonNull String version) {
- parseVersion(version);
- }
-
- /**
- * Expected format MAJOR.MINOR.PATCH-qualifier
- */
- @SuppressWarnings("checkstyle:innerassignment")
- public final void parseVersion(@NonNull String version) {
- this.value = version;
-
- items = new ListItem();
-
- version = version.toLowerCase(Locale.ENGLISH);
-
- ListItem list = items;
-
- Stack stack = new Stack<>();
- stack.push(list);
-
- boolean isDigit = false;
-
- int startIndex = 0;
-
- for (int i = 0; i < version.length(); i++) {
- char c = version.charAt(i);
-
- if (c == '.') {
- if (i == startIndex) {
- list.add(IntegerItem.ZERO);
- } else {
- list.add(parseItem(isDigit, version.substring(startIndex, i)));
- }
- startIndex = i + 1;
- } else if (c == '-') {
- if (i == startIndex) {
- list.add(IntegerItem.ZERO);
- } else {
- list.add(parseItem(isDigit, version.substring(startIndex, i)));
- }
- startIndex = i + 1;
-
- list.add(list = new ListItem());
- stack.push(list);
- } else if (Character.isDigit(c)) {
- if (!isDigit && i > startIndex) {
- list.add(new StringItem(version.substring(startIndex, i), true));
- startIndex = i;
-
- list.add(list = new ListItem());
- stack.push(list);
- }
-
- isDigit = true;
- } else {
- if (isDigit && i > startIndex) {
- list.add(parseItem(true, version.substring(startIndex, i)));
- startIndex = i;
-
- list.add(list = new ListItem());
- stack.push(list);
- }
-
- isDigit = false;
- }
- }
-
- if (version.length() > startIndex) {
- list.add(parseItem(isDigit, version.substring(startIndex)));
- }
-
- while (!stack.isEmpty()) {
- list = (ListItem) stack.pop();
- list.normalize();
- }
-
- canonical = items.toString();
- }
-
- private static Item parseItem(boolean isDigit, String buf) {
- return isDigit ? new IntegerItem(buf) : new StringItem(buf, false);
- }
-
-
- public int compareTo(@NonNull ComparableVersion o) {
- return items.compareTo(o.items);
- }
-
- public String toString() {
- return value;
- }
-
- public boolean equals(Object o) {
- return (o instanceof ComparableVersion) && canonical.equals(((ComparableVersion) o).canonical);
- }
-
- public int hashCode() {
- return canonical.hashCode();
- }
-}
\ No newline at end of file
diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/CrashSamplesNdkDelegate.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/CrashSamplesNdkDelegate.kt
deleted file mode 100644
index 8b1ae00ebc..0000000000
--- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/CrashSamplesNdkDelegate.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package io.embrace.android.embracesdk.samples
-
-internal interface CrashSamplesNdkDelegate {
- fun sigIllegalInstruction()
- fun throwException()
- fun sigAbort()
- fun sigfpe()
- fun sigsegv()
-}
diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamples.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamples.kt
deleted file mode 100644
index 0c4d3c3fdc..0000000000
--- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamples.kt
+++ /dev/null
@@ -1,131 +0,0 @@
-package io.embrace.android.embracesdk.samples
-
-import io.embrace.android.embracesdk.Embrace
-import io.embrace.android.embracesdk.internal.logging.EmbLoggerImpl
-
-/**
- * Encapsulates the logic to trigger different type of crashes for testing purpose.
- * It is recommended to implement every method call via a button press once the app has loaded.
- * After a crash sent, the app should be restarted in order to see the error in the dashboard.
- */
-internal object EmbraceCrashSamples {
-
- private val logger = EmbLoggerImpl()
-
- private val ndkCrashSamplesNdkDelegate = EmbraceCrashSamplesNdkDelegateImpl()
-
- /**
- * Verifies if Embrace is initialized
- */
-
- fun isSdkStarted() {
- if (!Embrace.getInstance().isStarted) {
- val e = EmbraceSampleCodeException(
- "Embrace SDK not initialized. Please ensure you have included " +
- "Embrace.getInstance().start(this) in Application#onCreate()\n" +
- "and then trigger these crash samples via a button press once the app has loaded."
- )
- logger.logError("Embrace SDK is not initialized", e)
- throw e
- }
- }
-
- /**
- * verifies if ANR detection is enabled
- */
-
- fun checkAnrDetectionEnabled() {
- if (!Embrace.getInstance().internalInterface.isAnrCaptureEnabled()) {
- val e = EmbraceSampleCodeException(
- "ANR capture disabled - you need to enable it to test Embrace's ANR functionality:\n" +
- " - add [\"anr\":{\"pct_enabled\": 100 }]" +
- " inside the configuration file to enable ANR detection"
- )
- logger.logError("ANR detection disabled", e)
- throw e
- }
- }
-
- /**
- * Throws a custom JVM exception: EmbraceCrashException
- */
- fun throwJvmException() {
- isSdkStarted()
- throw EmbraceSampleCodeException("Custom JVM Exception")
- }
-
- /**
- * Block the app's main thread for 4 seconds.
- * Embrace detects this and samples the main thread stacktraces, so you can better debug ANRs.
- */
- fun blockMainThreadForShortInterval() {
- isSdkStarted()
- checkAnrDetectionEnabled()
- try {
- Thread.sleep(SHORT_ANR_4_SEC)
- } catch (e: InterruptedException) {
- logger.logError("Short ANR failed", e)
- }
- }
-
- /**
- * Force a long ANR that lasts 30 seconds
- */
- fun triggerLongAnr() {
- isSdkStarted()
- checkAnrDetectionEnabled()
- val embrace = Embrace.getInstance()
- val start = embrace.internalInterface.getSdkCurrentTime()
- while (true) {
- if (embrace.internalInterface.getSdkCurrentTime() - start >= LONG_ANR_LENGTH) {
- break
- }
- }
- }
-
- /**
- * verifies if NDK detection is enabled
- */
-
- fun checkNdkDetectionEnabled() {
- // First verifies is Embrace SDK is initialized
- isSdkStarted()
-
- if (!Embrace.getInstance().internalInterface.isNdkEnabled()) {
- val e = EmbraceSampleCodeException(
- "NDK crash capture is disabled - you need to enable it to test Embrace's NDK functionality" +
- " - To enable it, add [\"ndk_enabled\": true] inside the configuration file"
- )
- logger.logError("NDK detection disabled", e)
- throw e
- }
- }
-
- fun triggerNdkSigIllegalInstruction() {
- checkNdkDetectionEnabled()
- ndkCrashSamplesNdkDelegate.sigIllegalInstruction()
- }
-
- fun triggerNdkThrowCppException() {
- checkNdkDetectionEnabled()
- ndkCrashSamplesNdkDelegate.throwException()
- }
-
- fun triggerNdkSigAbort() {
- checkNdkDetectionEnabled()
- ndkCrashSamplesNdkDelegate.sigAbort()
- }
-
- fun triggerNdkSigfpe() {
- checkNdkDetectionEnabled()
- ndkCrashSamplesNdkDelegate.sigfpe()
- }
-
- fun triggerNdkSigsegv() {
- checkNdkDetectionEnabled()
- ndkCrashSamplesNdkDelegate.sigsegv()
- }
-
- private const val LONG_ANR_LENGTH = 30000
- private const val SHORT_ANR_4_SEC = 4000L
-}
diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamplesNdkDelegateImpl.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamplesNdkDelegateImpl.kt
deleted file mode 100644
index 1c95ba8e44..0000000000
--- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamplesNdkDelegateImpl.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package io.embrace.android.embracesdk.samples
-
-internal class EmbraceCrashSamplesNdkDelegateImpl : CrashSamplesNdkDelegate {
- external override fun sigIllegalInstruction()
- external override fun throwException()
- external override fun sigAbort()
- external override fun sigfpe()
- external override fun sigsegv()
-}
diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceSampleCodeException.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceSampleCodeException.kt
deleted file mode 100644
index a366bc2765..0000000000
--- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/samples/EmbraceSampleCodeException.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package io.embrace.android.embracesdk.samples
-
-internal class EmbraceSampleCodeException(val msg: String) : Exception(msg)
diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamplesTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamplesTest.kt
deleted file mode 100644
index 3f2ecb1f90..0000000000
--- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/samples/EmbraceCrashSamplesTest.kt
+++ /dev/null
@@ -1,67 +0,0 @@
-package io.embrace.android.embracesdk.samples
-
-import io.embrace.android.embracesdk.Embrace
-import io.mockk.every
-import io.mockk.mockkStatic
-import io.mockk.unmockkAll
-import org.junit.AfterClass
-import org.junit.Assert.assertThrows
-import org.junit.BeforeClass
-import org.junit.Test
-
-internal class EmbraceCrashSamplesTest {
-
- companion object {
- private lateinit var crashSampleTest: EmbraceCrashSamples
-
- @BeforeClass
- @JvmStatic
- fun beforeClass() {
- mockkStatic(Embrace::class)
- crashSampleTest = EmbraceCrashSamples
- }
-
- @AfterClass
- @JvmStatic
- fun afterClass() {
- unmockkAll()
- }
- }
-
- @Test
- fun `test isSdkStarted with isStarted false throws EmbraceNotInitializedException`() {
- every { Embrace.getInstance().isStarted } returns false
- assertThrows(EmbraceSampleCodeException::class.java) { crashSampleTest.isSdkStarted() }
- }
-
- @Test
- fun `test checkAnrDetectionEnabled throws EmbraceAnrDisabledException if isAnrCaptureEnabled is false`() {
- every { Embrace.getInstance().internalInterface.isAnrCaptureEnabled() } returns false
- assertThrows(EmbraceSampleCodeException::class.java) { crashSampleTest.checkAnrDetectionEnabled() }
- }
-
- @Test
- fun `test checkNdkDetectionEnabled throws EmbraceNotInitializedException if Embrace isStarted is false`() {
- every { Embrace.getInstance().isStarted } returns false
- assertThrows(EmbraceSampleCodeException::class.java) { crashSampleTest.checkNdkDetectionEnabled() }
- }
-
- @Test
- fun `test checkNdkDetectionEnabled with isNdkEnabled false throws EmbraceNdkDisabledException`() {
- every { Embrace.getInstance().isStarted } returns true
- every { Embrace.getInstance().internalInterface.isNdkEnabled() } returns false
- assertThrows(EmbraceSampleCodeException::class.java) { crashSampleTest.checkNdkDetectionEnabled() }
- }
-
- @Test
- fun `test throwJvmException actually throws EmbraceNotInitializedException if Embrace isStarted is false`() {
- every { Embrace.getInstance().isStarted } returns false
- assertThrows(EmbraceSampleCodeException::class.java) { crashSampleTest.throwJvmException() }
- }
-
- @Test
- fun `test throwJvmException actually throws EmbraceNotInitializedException if Embrace is initialized`() {
- every { Embrace.getInstance().isStarted } returns true
- assertThrows(EmbraceSampleCodeException::class.java) { crashSampleTest.throwJvmException() }
- }
-}
diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/samples/VersionTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/samples/VersionTest.kt
deleted file mode 100644
index 1a3a58a61e..0000000000
--- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/samples/VersionTest.kt
+++ /dev/null
@@ -1,81 +0,0 @@
-package io.embrace.android.embracesdk.samples
-
-import org.junit.Assert.assertTrue
-import org.junit.Test
-
-internal class VersionTest {
-
- @Test
- fun `compare versions`() {
- assertTrue(
- ComparableVersion("5.2.1-beta01") < ComparableVersion(
- "5.2.1"
- )
- )
- assertTrue(
- ComparableVersion("5.2.1") > ComparableVersion(
- "5.2.1-beta01"
- )
- )
- assertTrue(
- ComparableVersion("5.2.1").compareTo(
- ComparableVersion("5.2.1")
- ) == 0
- )
- assertTrue(
- ComparableVersion("5.3.0") > ComparableVersion(
- "5.2.1-beta01"
- )
- )
- assertTrue(
- ComparableVersion("5.2.1-beta01") < ComparableVersion(
- "5.2.1-beta03"
- )
- )
- assertTrue(
- ComparableVersion("5.2.1-beta01") < ComparableVersion(
- "5.2.1-beta3"
- )
- )
- assertTrue(
- ComparableVersion("5.1.0") < ComparableVersion(
- "5.2.1-beta3"
- )
- )
- assertTrue(
- ComparableVersion("4.1.0-alpha1") < ComparableVersion(
- "5.2.1-beta3"
- )
- )
- assertTrue(
- ComparableVersion("4.1.0-alpha") < ComparableVersion(
- "5.2.1-beta"
- )
- )
- assertTrue(
- ComparableVersion("5.1.0-snapshot") < ComparableVersion(
- "5.2.1-beta3"
- )
- )
- assertTrue(
- ComparableVersion("5.1.0-SNAPSHOT") < ComparableVersion(
- "5.2.1-beta3"
- )
- )
- assertTrue(
- ComparableVersion("5.1.0") > ComparableVersion(
- "5.1.0-SNAPSHOT"
- )
- )
- assertTrue(
- ComparableVersion("5.1.0") > ComparableVersion(
- "5.1.0-beta"
- )
- )
- assertTrue(
- ComparableVersion("5.1.0") > ComparableVersion(
- "5.1.0-alpha"
- )
- )
- }
-}