-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add current activity name to app context (#2999)
- Loading branch information
Showing
21 changed files
with
256 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
sentry-android-core/src/main/java/io/sentry/android/core/internal/util/ClassUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.sentry.android.core.internal.util; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@ApiStatus.Internal | ||
public class ClassUtil { | ||
|
||
public static @Nullable String getClassName(final @Nullable Object object) { | ||
if (object == null) { | ||
return null; | ||
} | ||
final @Nullable String canonicalName = object.getClass().getCanonicalName(); | ||
if (canonicalName != null) { | ||
return canonicalName; | ||
} | ||
return object.getClass().getSimpleName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
sentry-android-core/src/test/java/io/sentry/android/core/internal/util/ClassUtilTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.sentry.android.core.internal.util | ||
|
||
import java.util.concurrent.Callable | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNull | ||
import kotlin.test.assertTrue | ||
|
||
class ClassUtilTest { | ||
|
||
class Outer { | ||
class Inner { | ||
val x: Callable<Boolean> = Callable<Boolean> { false } | ||
} | ||
} | ||
|
||
@Test | ||
fun `getClassName returns cannonical name by default`() { | ||
val name = ClassUtil.getClassName(Outer.Inner()) | ||
assertEquals("io.sentry.android.core.internal.util.ClassUtilTest.Outer.Inner", name) | ||
} | ||
|
||
@Test | ||
fun `getClassName falls back to simple name for anonymous classes`() { | ||
val name = ClassUtil.getClassName(Outer.Inner().x) | ||
assertTrue(name!!.contains("$")) | ||
} | ||
|
||
@Test | ||
fun `getClassName returns null when obj is null`() { | ||
val name = ClassUtil.getClassName(null) | ||
assertNull(name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.