nimblehq / recent-apps-thumbnail-hiding

Hide app thumbnail in Android Recent Apps
MIT License
19 stars 6 forks source link

recent-apps-thumbnail-hiding

Hide app thumbnail in Android Recent Apps

Since our privacy is always in question, there are some applications - especially digital banking and wallet applications - that show some sensitive information that must NOT be shown on the "Recent Tasks" screen when stopping the app by pressing the home button. Instead, they will try to show a custom app logo as an app thumbnail in Recents Screen.

20201014_171755

There is no clear support from Android at the official API level, only a FLAG_SECURE that was initially introduced to prevent DRM-protected content from appearing in screenshots, video screencaps, or from being viewed on “non-secure displays” such as Recents Screen; and this flag does not support to show custom app UI in Recents Screen, only blank.

There is an approach to archive this requirement besides using that flag is HardwareKeyWatcher but it can not cover all of the cases due to fragmented device configurations and custom ROMs, then we have to fulfill missing cases with other approaches. To ease the way of implementation, we had built a lib for Recent Apps thumbnail hiding mechanism, which supports implement a custom layout to show an empty screen with the app's logo when the app is going to Recents Screen.

Installation

Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.nimblehq:recent-apps-thumbnail-hiding:[LATEST_VERSION]'
}

Usage

Checkout the custom thumbnail layout sample to see more detail here

Exceptions handling

The core approach HardwareKeyWatcher in this lib does not work on all devices. There are some failed cases listed as below:

More testing insight could be found here. In order to provide an option to cover the hiding app thumbnail on more and more devices, this lib adds support to apply FLAG_SECURE.

This support is provided as an option and disabled by default, to enable it:

  1. extend your activity to RecentAppsThumbnailHidingActivity.
  2. override enableSecureFlagOnLowApiDevices = true, enableSecureFlagOnCustomGestureNavigationDevices = true, or both.

    class MainActivity : RecentAppsThumbnailHidingActivity() {
    
        // On devices with API 25 and lower: use FLAG_SECURE
        override val enableSecureFlagOnLowApiDevices: Boolean = true
    
        // On some Huawei/Xiaomi devices with custom gesture navigation: use FLAG_SECURE
        override val enableSecureFlagOnCustomGestureNavigationDevices = true
    
        // The rest: show custom app logo
        override fun onRecentAppsTriggered(activity: Activity, inRecentAppsMode: Boolean) {
            ivRecentAppThumbnail.visibleOrGone(inRecentAppsMode)
        }
    
    }

⚠️ Note that, besides supporting to hide app thumbnail, this flag will not support to show a custom Recent Apps thumbnail layout, also blocks the user to capture app screenshot.

License

This project is Copyright (c) 2014-2021 Nimble. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Nimble

This project is maintained and funded by Nimble.

We love open source and do our part in sharing our work with the community! See our other projects or hire our team to help build your product.