feat: move beta access control into c++
Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
19fcf26d69
commit
91788740a6
|
|
@ -65,6 +65,11 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceConfigurations += ["en", "de", "fr", "id", "b+es+419", "bn", "ca", "es", "gl", "in", "pt-rBR", "pt", "ru", "tr", "uk", "zh-rCN"]
|
resourceConfigurations += ["en", "de", "fr", "id", "b+es+419", "bn", "ca", "es", "gl", "in", "pt-rBR", "pt", "ru", "tr", "uk", "zh-rCN"]
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
cppFlags ''
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|
@ -114,6 +119,12 @@ android {
|
||||||
disable 'MissingTranslation'
|
disable 'MissingTranslation'
|
||||||
}
|
}
|
||||||
namespace 'chat.revolt'
|
namespace 'chat.revolt'
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
path file('src/main/cpp/CMakeLists.txt')
|
||||||
|
version '3.22.1'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sentry {
|
sentry {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
# For more information about using CMake with Android Studio, read the
|
||||||
|
# documentation: https://d.android.com/studio/projects/add-native-code.html.
|
||||||
|
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
|
||||||
|
|
||||||
|
# Sets the minimum CMake version required for this project.
|
||||||
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
|
|
||||||
|
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
|
||||||
|
# Since this is the top level CMakeLists.txt, the project name is also accessible
|
||||||
|
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
|
||||||
|
# build script scope).
|
||||||
|
project("revolt")
|
||||||
|
|
||||||
|
set(LIB_NAME_ACCESS_CONTROL "pipebomb")
|
||||||
|
|
||||||
|
# Creates and names a library, sets it as either STATIC
|
||||||
|
# or SHARED, and provides the relative paths to its source code.
|
||||||
|
# You can define multiple libraries, and CMake builds them for you.
|
||||||
|
# Gradle automatically packages shared libraries with your APK.
|
||||||
|
#
|
||||||
|
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
|
||||||
|
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
|
||||||
|
# is preferred for the same purpose.
|
||||||
|
#
|
||||||
|
# In order to load a library into your app from Java/Kotlin, you must call
|
||||||
|
# System.loadLibrary() and pass the name of the library defined here;
|
||||||
|
# for GameActivity/NativeActivity derived applications, the same library name must be
|
||||||
|
# used in the AndroidManifest.xml file.
|
||||||
|
add_library(${LIB_NAME_ACCESS_CONTROL} SHARED
|
||||||
|
# List C/C++ source files with relative paths to this CMakeLists.txt.
|
||||||
|
lib${LIB_NAME_ACCESS_CONTROL}/${LIB_NAME_ACCESS_CONTROL}.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Specifies libraries CMake should link to your target library. You
|
||||||
|
# can link libraries from various origins, such as libraries defined in this
|
||||||
|
# build script, prebuilt third-party libraries, or Android system libraries.
|
||||||
|
target_link_libraries(${LIB_NAME_ACCESS_CONTROL}
|
||||||
|
# List libraries link to the target library
|
||||||
|
android
|
||||||
|
log)
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include <android/log.h>
|
||||||
|
#include <jni.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int hardCrashCounter = 0;
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_chat_revolt_ndk_Pipebomb_incrementHardCrashCounter(JNIEnv *env, jobject thiz) {
|
||||||
|
hardCrashCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_chat_revolt_ndk_Pipebomb_doHardCrash(JNIEnv *env,
|
||||||
|
jobject thiz) {
|
||||||
|
int *p = nullptr;
|
||||||
|
*p = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT jboolean JNICALL
|
||||||
|
Java_chat_revolt_ndk_Pipebomb_checkHardCrash(JNIEnv *env, jobject thiz) {
|
||||||
|
return hardCrashCounter > 3;
|
||||||
|
}
|
||||||
|
|
@ -26,6 +26,7 @@ import androidx.navigation.compose.dialog
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import chat.revolt.BuildConfig
|
import chat.revolt.BuildConfig
|
||||||
import chat.revolt.api.settings.GlobalState
|
import chat.revolt.api.settings.GlobalState
|
||||||
|
import chat.revolt.ndk.NativeLibraries
|
||||||
import chat.revolt.screens.SplashScreen
|
import chat.revolt.screens.SplashScreen
|
||||||
import chat.revolt.screens.about.AboutScreen
|
import chat.revolt.screens.about.AboutScreen
|
||||||
import chat.revolt.screens.about.AttributionScreen
|
import chat.revolt.screens.about.AttributionScreen
|
||||||
|
|
@ -65,6 +66,12 @@ class MainActivity : FragmentActivity() {
|
||||||
AppEntrypoint(windowSizeClass)
|
AppEntrypoint(windowSizeClass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
NativeLibraries.init()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val RevoltTweenInt: FiniteAnimationSpec<IntOffset> = tween(400, easing = EaseInOutExpo)
|
val RevoltTweenInt: FiniteAnimationSpec<IntOffset> = tween(400, easing = EaseInOutExpo)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package chat.revolt.ndk
|
||||||
|
|
||||||
|
annotation class NativeLibrary(val name: String) {
|
||||||
|
companion object {
|
||||||
|
const val LIB_NAME_ACCESS_CONTROL = "pipebomb"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object NativeLibraries {
|
||||||
|
fun init() {
|
||||||
|
System.loadLibrary(NativeLibrary.LIB_NAME_ACCESS_CONTROL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package chat.revolt.ndk
|
||||||
|
|
||||||
|
@NativeLibrary(NativeLibrary.LIB_NAME_ACCESS_CONTROL)
|
||||||
|
object Pipebomb {
|
||||||
|
init {
|
||||||
|
System.loadLibrary(NativeLibrary.LIB_NAME_ACCESS_CONTROL)
|
||||||
|
}
|
||||||
|
|
||||||
|
external fun incrementHardCrashCounter()
|
||||||
|
external fun checkHardCrash(): Boolean
|
||||||
|
external fun doHardCrash()
|
||||||
|
}
|
||||||
|
|
@ -81,6 +81,7 @@ import chat.revolt.components.screens.chat.drawer.server.DrawerServer
|
||||||
import chat.revolt.components.screens.chat.drawer.server.DrawerServerlikeIcon
|
import chat.revolt.components.screens.chat.drawer.server.DrawerServerlikeIcon
|
||||||
import chat.revolt.components.screens.chat.drawer.server.ServerDrawerSeparator
|
import chat.revolt.components.screens.chat.drawer.server.ServerDrawerSeparator
|
||||||
import chat.revolt.internals.Changelogs
|
import chat.revolt.internals.Changelogs
|
||||||
|
import chat.revolt.ndk.Pipebomb
|
||||||
import chat.revolt.persistence.KVStorage
|
import chat.revolt.persistence.KVStorage
|
||||||
import chat.revolt.screens.chat.dialogs.safety.ReportMessageDialog
|
import chat.revolt.screens.chat.dialogs.safety.ReportMessageDialog
|
||||||
import chat.revolt.screens.chat.views.HomeScreen
|
import chat.revolt.screens.chat.views.HomeScreen
|
||||||
|
|
@ -188,16 +189,13 @@ class ChatRouterViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FeatureFlag("ClosedBetaAccessControl")
|
|
||||||
private var hardCrashCounter = 0
|
|
||||||
|
|
||||||
fun navigateToChannel(channelId: String, navController: NavController, pure: Boolean = false) {
|
fun navigateToChannel(channelId: String, navController: NavController, pure: Boolean = false) {
|
||||||
if (!pure) setSaveCurrentChannel(channelId)
|
if (!pure) setSaveCurrentChannel(channelId)
|
||||||
|
|
||||||
// Only allow access to closed beta users, currently "has access to #beta-chat in Jenvolt"
|
// Only allow access to closed beta users, currently "has access to #beta-chat in Jenvolt"
|
||||||
@FeatureFlag("ClosedBetaAccessControl")
|
@FeatureFlag("ClosedBetaAccessControl")
|
||||||
if (RevoltAPI.channelCache.size > 0 && !RevoltAPI.channelCache.containsKey("01H7X2KRB0CA4QDSMB4N7WGERF")) {
|
if (RevoltAPI.channelCache.size > 0 && !RevoltAPI.channelCache.containsKey("01H7X2KRB0CA4QDSMB4N7WGERF")) {
|
||||||
hardCrashCounter++
|
Pipebomb.incrementHardCrashCounter()
|
||||||
|
|
||||||
navController.navigate("no_current_channel") {
|
navController.navigate("no_current_channel") {
|
||||||
navController.graph.startDestinationRoute?.let { route ->
|
navController.graph.startDestinationRoute?.let { route ->
|
||||||
|
|
@ -205,7 +203,7 @@ class ChatRouterViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hardCrashCounter > 2) {
|
if (Pipebomb.checkHardCrash()) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context,
|
||||||
"You do not have access to the closed beta.",
|
"You do not have access to the closed beta.",
|
||||||
|
|
@ -220,7 +218,7 @@ class ChatRouterViewModel @Inject constructor(
|
||||||
)
|
)
|
||||||
context.startActivity(intent) // i'm just messing with the user at this point, they know what they did
|
context.startActivity(intent) // i'm just messing with the user at this point, they know what they did
|
||||||
|
|
||||||
throw IllegalStateException()
|
Pipebomb.doHardCrash()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Navigate as normal
|
// Navigate as normal
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue