File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
kotlin/com/opacitylabs/opacitycore Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,13 @@ extern "C" const char *get_ip_address() {
186186 return result; // Caller must free this memory
187187}
188188
189+ extern " C" bool android_is_app_foregrounded () {
190+ JNIEnv *env = GetJniEnv ();
191+ jclass jOpacityCore = env->GetObjectClass (java_object);
192+ jmethodID method = env->GetMethodID (jOpacityCore, " isAppForegrounded" , " ()Z" );
193+ return env->CallBooleanMethod (java_object, method);
194+ }
195+
189196extern " C" void android_close_webview () {
190197 JNIEnv *env = GetJniEnv ();
191198 // Get the Kotlin class
Original file line number Diff line number Diff line change @@ -59,6 +59,23 @@ object OpacityCore {
5959 return sRuntime
6060 }
6161
62+ fun isAppForegrounded (): Boolean {
63+ return try {
64+ val activityManager = appContext.getSystemService(Context .ACTIVITY_SERVICE ) as android.app.ActivityManager
65+ val runningProcesses = activityManager.runningAppProcesses
66+ if (runningProcesses != null ) {
67+ for (processInfo in runningProcesses) {
68+ if (processInfo.processName == appContext.packageName) {
69+ return processInfo.importance == android.app.ActivityManager .RunningAppProcessInfo .IMPORTANCE_FOREGROUND
70+ }
71+ }
72+ }
73+ false
74+ } catch (e: Exception ) {
75+ false
76+ }
77+ }
78+
6279 fun securelySet (key : String , value : String ) {
6380 cryptoManager.set(key, value)
6481 }
You can’t perform that action at this time.
0 commit comments