Skip to content

Commit

Permalink
chore: enable FLAG_SECURE by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxzero committed Oct 19, 2023
1 parent 5223164 commit 841843b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthorizingPaymentActivity>(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<AuthorizingPaymentActivity>(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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CreditCardActivity>(intent)
fun flagSecure_whenParameterIsFalseThenAttributesMustNotContainFlagSecure() {
intent.putExtra(OmiseActivity.EXTRA_IS_SECURE, false)
val scenario = ActivityScenario.launchActivityForResult<CreditCardActivity>(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<CreditCardActivity>(intent)
fun flagSecure_whenParameterNotSetThenAttributesMustContainFlagSecure() {
val scenario = ActivityScenario.launchActivityForResult<CreditCardActivity>(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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PaymentCreatorActivity>(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<PaymentCreatorActivity>(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)
}
}
}

0 comments on commit 841843b

Please sign in to comment.