From 841843b96afaf3ef2f934967456195fda0c027f0 Mon Sep 17 00:00:00 2001 From: Natthawut Haematulin Date: Thu, 19 Oct 2023 14:37:22 +0700 Subject: [PATCH] chore: enable FLAG_SECURE by default --- README.md | 2 +- .../android/ui/AuthorizingPaymentActivityTest.kt | 10 +++++----- .../android/ui/AuthorizingPaymentActivity.kt | 2 +- .../co/omise/android/ui/CreditCardActivity.kt | 2 +- .../co/omise/android/ui/PaymentCreatorActivity.kt | 4 ++-- .../co/omise/android/ui/CreditCardActivityTest.kt | 15 +++++++-------- .../android/ui/PaymentCreatorActivityTest.kt | 10 +++++----- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 911d087ec..dd411e572 100644 --- a/README.md +++ b/README.md @@ -523,7 +523,7 @@ If you enable ProGuard, then add this rules in your ProGuard file. ## Protecting screenshot and screen recording -To protect **Omise Android SDK** from being screenshot and screen recording, you can pass this `OmiseActivity.EXTRA_IS_SECURE` extra data to `true` when starting these activities `CreditCardActivity`, `PaymentCreatorActivity`, and `AuthorizingPaymentActivity`. By default it is `false`. +By default, **Omise Android SDK** protects the screen from being screenshot and screen recording, if you want to disable this feature you can pass this `OmiseActivity.EXTRA_IS_SECURE` extra data to `false` when starting these activities `CreditCardActivity`, `PaymentCreatorActivity`, and `AuthorizingPaymentActivity`. ```kotlin diff --git a/sdk/src/androidTest/java/co/omise/android/ui/AuthorizingPaymentActivityTest.kt b/sdk/src/androidTest/java/co/omise/android/ui/AuthorizingPaymentActivityTest.kt index 5543058e0..fd4923ff1 100644 --- a/sdk/src/androidTest/java/co/omise/android/ui/AuthorizingPaymentActivityTest.kt +++ b/sdk/src/androidTest/java/co/omise/android/ui/AuthorizingPaymentActivityTest.kt @@ -335,19 +335,19 @@ class AuthorizingPaymentActivityTest { } @Test - fun flagSecure_whenSetParameterThenAttributesMustContainFlagSecure() { - intent.putExtra(OmiseActivity.EXTRA_IS_SECURE, true) + fun flagSecure_whenParameterIsFalseThenAttributesMustNotContainFlagSecure() { + intent.putExtra(OmiseActivity.EXTRA_IS_SECURE, false) val scenario = ActivityScenario.launchActivityForResult(intent) scenario.onActivity { - assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + assertNotEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) } } @Test - fun flagSecure_whenNotSetParameterThenAttributesMustNotContainFlagSecure() { + fun flagSecure_whenParameterNotSetThenAttributesMustContainFlagSecure() { val scenario = ActivityScenario.launchActivityForResult(intent) scenario.onActivity { - assertNotEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) } } } diff --git a/sdk/src/main/java/co/omise/android/ui/AuthorizingPaymentActivity.kt b/sdk/src/main/java/co/omise/android/ui/AuthorizingPaymentActivity.kt index b2a20b0f8..29ef8bf56 100644 --- a/sdk/src/main/java/co/omise/android/ui/AuthorizingPaymentActivity.kt +++ b/sdk/src/main/java/co/omise/android/ui/AuthorizingPaymentActivity.kt @@ -56,7 +56,7 @@ class AuthorizingPaymentActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (intent.getBooleanExtra(OmiseActivity.EXTRA_IS_SECURE, false)) { + if (intent.getBooleanExtra(OmiseActivity.EXTRA_IS_SECURE, true)) { window.addFlags(WindowManager.LayoutParams.FLAG_SECURE) } diff --git a/sdk/src/main/java/co/omise/android/ui/CreditCardActivity.kt b/sdk/src/main/java/co/omise/android/ui/CreditCardActivity.kt index ad5bcdace..b92f7296b 100644 --- a/sdk/src/main/java/co/omise/android/ui/CreditCardActivity.kt +++ b/sdk/src/main/java/co/omise/android/ui/CreditCardActivity.kt @@ -126,7 +126,7 @@ class CreditCardActivity : OmiseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (intent.getBooleanExtra(EXTRA_IS_SECURE, false)) { + if (intent.getBooleanExtra(EXTRA_IS_SECURE, true)) { window.addFlags(WindowManager.LayoutParams.FLAG_SECURE) } diff --git a/sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt b/sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt index 81a7da9b3..45eb421a3 100644 --- a/sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt +++ b/sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt @@ -66,7 +66,7 @@ class PaymentCreatorActivity : OmiseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (intent.getBooleanExtra(EXTRA_IS_SECURE, false)) { + if (intent.getBooleanExtra(EXTRA_IS_SECURE, true)) { window.addFlags(WindowManager.LayoutParams.FLAG_SECURE) } @@ -207,7 +207,7 @@ private class PaymentCreatorNavigationImpl( override fun navigateToCreditCardForm() { val intent = Intent(activity, CreditCardActivity::class.java).apply { putExtra(EXTRA_PKEY, pkey) - putExtra(EXTRA_IS_SECURE, activity.intent.getBooleanExtra(EXTRA_IS_SECURE, false)) + putExtra(EXTRA_IS_SECURE, activity.intent.getBooleanExtra(EXTRA_IS_SECURE, true)) } activity.startActivityForResult(intent, requestCode) } diff --git a/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt b/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt index 9ea3dfde1..21f40a3af 100644 --- a/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt +++ b/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt @@ -384,21 +384,20 @@ class CreditCardActivityTest { assertEquals(RESULT_CANCELED, result.resultCode) } - @Test - fun flagSecure_whenSetParameterThenAttributesMustContainFlagSecure() { - intent.putExtra(OmiseActivity.EXTRA_IS_SECURE, true) - val scenario = launchActivityForResult(intent) + fun flagSecure_whenParameterIsFalseThenAttributesMustNotContainFlagSecure() { + intent.putExtra(OmiseActivity.EXTRA_IS_SECURE, false) + val scenario = ActivityScenario.launchActivityForResult(intent) scenario.onActivity { - assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + assertNotEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) } } @Test - fun flagSecure_whenNotSetParameterThenAttributesMustNotContainFlagSecure() { - val scenario = launchActivityForResult(intent) + fun flagSecure_whenParameterNotSetThenAttributesMustContainFlagSecure() { + val scenario = ActivityScenario.launchActivityForResult(intent) scenario.onActivity { - assertNotEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) } } } diff --git a/sdk/src/sharedTest/java/co/omise/android/ui/PaymentCreatorActivityTest.kt b/sdk/src/sharedTest/java/co/omise/android/ui/PaymentCreatorActivityTest.kt index 7adee4fa5..930dd8d7f 100644 --- a/sdk/src/sharedTest/java/co/omise/android/ui/PaymentCreatorActivityTest.kt +++ b/sdk/src/sharedTest/java/co/omise/android/ui/PaymentCreatorActivityTest.kt @@ -74,19 +74,19 @@ class PaymentCreatorActivityTest { } @Test - fun flagSecure_whenSetParameterThenAttributesMustContainFlagSecure() { - intent.putExtra(OmiseActivity.EXTRA_IS_SECURE, true) + fun flagSecure_whenParameterIsFalseThenAttributesMustNotContainFlagSecure() { + intent.putExtra(OmiseActivity.EXTRA_IS_SECURE, false) val scenario = ActivityScenario.launchActivityForResult(intent) scenario.onActivity { - assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + assertNotEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) } } @Test - fun flagSecure_whenNotSetParameterThenAttributesMustNotContainFlagSecure() { + fun flagSecure_whenParameterNotSetThenAttributesMustContainFlagSecure() { val scenario = ActivityScenario.launchActivityForResult(intent) scenario.onActivity { - assertNotEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) } } }