Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import com.facebook.react.devsupport.interfaces.DevSupportManager
import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager
import com.facebook.react.devsupport.interfaces.RedBoxHandler
import com.facebook.react.packagerconnection.RequestHandler
import com.facebook.redex.annotations.IgnoreStringLiterals

/**
* A simple factory that creates instances of [DevSupportManager] implementations. Uses reflection
* to create BridgeDevSupportManager if it exists. This allows ProGuard to strip that class and its
* dependencies in release builds. If the class isn't found, [PerftestDevSupportManager] is returned
* instead.
*/
@IgnoreStringLiterals
internal class DefaultDevSupportManagerFactory : DevSupportManagerFactory {

override fun create(
Expand All @@ -47,15 +49,9 @@ internal class DefaultDevSupportManagerFactory : DevSupportManagerFactory {
// trying to return the full support DevSupportManager and if it fails, then just
// return PerftestDevSupportManager.

// ProGuard is surprisingly smart in this case and will keep a class if it detects a call
// to
// Class.forName() with a static string. So instead we generate a quasi-dynamic string to
// confuse it.
val className =
StringBuilder(DEVSUPPORT_IMPL_PACKAGE)
.append(".")
.append(DEVSUPPORT_IMPL_CLASS)
.toString()
// @IgnoreStringLiterals annotation is used to enable ProGuard to strip out the
// BridgeDevSupportManager class
val className = "com.facebook.react.devsupport.BridgeDevSupportManager"
val devSupportManagerClass = Class.forName(className)
val constructor =
devSupportManagerClass.getConstructor(
Expand Down Expand Up @@ -119,9 +115,4 @@ internal class DefaultDevSupportManagerFactory : DevSupportManagerFactory {
} else {
ReleaseDevSupportManager()
}

private companion object {
private const val DEVSUPPORT_IMPL_PACKAGE = "com.facebook.react.devsupport"
private const val DEVSUPPORT_IMPL_CLASS = "BridgeDevSupportManager"
}
}
Loading