From 99d2780b5212fdd8963b825b2948bdf854c04e61 Mon Sep 17 00:00:00 2001 From: Ahmad Vazirna Date: Mon, 17 Jul 2023 14:42:51 +0200 Subject: [PATCH 1/4] Add FLAG_SECURE custom property --- app/src/org/commcare/preferences/HiddenPreferences.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/org/commcare/preferences/HiddenPreferences.java b/app/src/org/commcare/preferences/HiddenPreferences.java index e190aa9b11..cb6bd5a66d 100644 --- a/app/src/org/commcare/preferences/HiddenPreferences.java +++ b/app/src/org/commcare/preferences/HiddenPreferences.java @@ -96,6 +96,7 @@ public class HiddenPreferences { private static final long NO_OF_HOURS_TO_WAIT_TO_RESUME_BACKGROUND_WORK = 36; + private static final String ENABLE_SECURE_FLAG = "cc-enable-secure-flag"; /** @@ -551,4 +552,9 @@ public static void markRawMediaCleanUpComplete() { CommCareApplication.instance().getCurrentApp().getAppPreferences() .edit().putBoolean(RAW_MEDIA_CLEANUP_COMPLETE, true).apply(); } + + public static boolean isFlagSecureEnabled() { + SharedPreferences properties = CommCareApplication.instance().getCurrentApp().getAppPreferences(); + return PrefValues.YES.equals(properties.getString(ENABLE_SECURE_FLAG, PrefValues.NO)); + } } From 260d0106005eb69bcaa15b1d84e743b5334094de Mon Sep 17 00:00:00 2001 From: Ahmad Vazirna Date: Mon, 17 Jul 2023 14:43:54 +0200 Subject: [PATCH 2/4] Enable FLAG_SECURE according to the custom property --- app/src/org/commcare/activities/CommCareActivity.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/org/commcare/activities/CommCareActivity.java b/app/src/org/commcare/activities/CommCareActivity.java index bd38fccdf7..f6de4e1c34 100755 --- a/app/src/org/commcare/activities/CommCareActivity.java +++ b/app/src/org/commcare/activities/CommCareActivity.java @@ -1,5 +1,7 @@ package org.commcare.activities; +import static org.commcare.preferences.HiddenPreferences.isFlagSecureEnabled; + import android.annotation.TargetApi; import android.content.Context; import android.content.DialogInterface; @@ -18,6 +20,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewTreeObserver; +import android.view.WindowManager; import android.widget.TextView; import android.widget.Toast; @@ -127,6 +130,10 @@ public abstract class CommCareActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (isFlagSecureEnabled()) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + FragmentManager fm = this.getSupportFragmentManager(); stateHolder = (TaskConnectorFragment)fm.findFragmentByTag("state"); From baea0b0778de61fd5c2c4149a416ada1385b0404 Mon Sep 17 00:00:00 2001 From: Ahmad Vazirna Date: Tue, 18 Jul 2023 17:15:16 +0200 Subject: [PATCH 3/4] Check preference in a safer way --- app/src/org/commcare/preferences/HiddenPreferences.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/org/commcare/preferences/HiddenPreferences.java b/app/src/org/commcare/preferences/HiddenPreferences.java index cb6bd5a66d..57bd81ec13 100644 --- a/app/src/org/commcare/preferences/HiddenPreferences.java +++ b/app/src/org/commcare/preferences/HiddenPreferences.java @@ -554,7 +554,6 @@ public static void markRawMediaCleanUpComplete() { } public static boolean isFlagSecureEnabled() { - SharedPreferences properties = CommCareApplication.instance().getCurrentApp().getAppPreferences(); - return PrefValues.YES.equals(properties.getString(ENABLE_SECURE_FLAG, PrefValues.NO)); + return DeveloperPreferences.doesPropertyMatch(ENABLE_SECURE_FLAG, PrefValues.NO, PrefValues.YES); } } From a0dcbb1f0206201ab8ff2d6d6a33ef5a778e0790 Mon Sep 17 00:00:00 2001 From: Ahmad Vazirna Date: Tue, 18 Jul 2023 19:22:22 +0200 Subject: [PATCH 4/4] Rename flag custom property --- app/src/org/commcare/preferences/HiddenPreferences.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/org/commcare/preferences/HiddenPreferences.java b/app/src/org/commcare/preferences/HiddenPreferences.java index 57bd81ec13..1d3f108711 100644 --- a/app/src/org/commcare/preferences/HiddenPreferences.java +++ b/app/src/org/commcare/preferences/HiddenPreferences.java @@ -2,7 +2,6 @@ import android.content.SharedPreferences; -import org.commcare.AppUtils; import org.commcare.CommCareApp; import org.commcare.CommCareApplication; import org.commcare.activities.GeoPointActivity; @@ -96,7 +95,7 @@ public class HiddenPreferences { private static final long NO_OF_HOURS_TO_WAIT_TO_RESUME_BACKGROUND_WORK = 36; - private static final String ENABLE_SECURE_FLAG = "cc-enable-secure-flag"; + private static final String ENABLE_ANDROID_WINDOW_SECURE_FLAG = "cc-enable-android-window-secure-flag"; /** @@ -554,6 +553,6 @@ public static void markRawMediaCleanUpComplete() { } public static boolean isFlagSecureEnabled() { - return DeveloperPreferences.doesPropertyMatch(ENABLE_SECURE_FLAG, PrefValues.NO, PrefValues.YES); + return DeveloperPreferences.doesPropertyMatch(ENABLE_ANDROID_WINDOW_SECURE_FLAG, PrefValues.NO, PrefValues.YES); } }