Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. /*
  2. Briefly, when the app is pushed into background mode (user presses the Home button)
  3. Android phone will create screenshot of the current Activity for displaying it in recent apps menu
  4. The recent's app screenshots will be stored at:
  5. - /data/system_ce/0/recent_images/
  6. - /data/system_ce/0/snapshots/
  7. Only root/system user can access these folders, however, it exposes (a very small) risk of insecure data storage
  8. as the malicious apps in rooted device could have access to them and gain access to sensitive info
  9. in the background screenshots.
  10. */
  11. package com.secureapp.app
  12.  
  13. import android.support.v7.app.AppCompatActivity
  14. import android.os.Bundle
  15. import android.view.WindowManager
  16.  
  17. class MainActivity : AppCompatActivity() {
  18.  
  19. override fun onCreate(savedInstanceState: Bundle?) {
  20. super.onCreate(savedInstanceState)
  21. // The line below is the solution can be found on 99% of Google search results
  22. // it prevents background screenshot in almost all Android versions but the normal screenshot is also blocked
  23. // and this behavior brutally damages UX in the sense that if a user wants to take screenshot of payment result
  24. // in an Internet Banking app, he will not able to do it.. LoL
  25. // window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
  26. setContentView(R.layout.activity_main)
  27. }
  28. /*
  29. The real solution is to use FLAG_SECURE during onPause() and recover the state in onResume()
  30. Important note: Only works with Android API version >= 26 (Android 8.0 Oreo and up, 20% of users)
  31. You have 2 choices, hurts UX with onCreate() FLAG_SECURE, or securing 20% of users with this trick !
  32. Don't believe in comments at:
  33. https://stackoverflow.com/questions/43274289/android-customizing-recent-apps-thumbnail-screenshot-by-default
  34. as they didn't test it in the right Android API versions :|
  35. */
  36. override fun onPause() {
  37. super.onPause()
  38. // Note: WindowManager.LayoutParams.FLAG_SECURE = 8192
  39. this.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
  40. }
  41. override fun onResume() {
  42. super.onResume()
  43. this.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement