Giter Site home page Giter Site logo

alihaider78222 / lock-unlock-detection-poc Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 99 KB

An Android Kotlin POC for monitoring lock/unlock events, logging failed PIN attempts, and enabling device administrator functionality.

Kotlin 100.00%
admin android kotlin lock-unlock kiosk

lock-unlock-detection-poc's Introduction

Android Lock/Unlock Detection POC

This Android Kotlin application is designed to detect lock and unlock events on a mobile device. Whenever the user enters the wrong PIN, a callback is triggered, and a log message is printed along with a toast message displayed on the screen. This app also allows the user to enable it as a device administrator.

Introduction

Modern Android devices come with a range of security features, including device administrator capabilities. This app utilizes the Device Administrator API to monitor lock and unlock events on the device. When an incorrect PIN is entered, it logs the event and displays a toast message.


1. Permissions

The poc app requires the following permissions to function properly:

android.permission.BIND_DEVICE_ADMIN: This permission allows the app to become a device administrator, enabling it to monitor device events and perform actions like locking the device. android.permission.RECEIVE_BOOT_COMPLETED: This permission allows the app to receive a notification when the device boots up, ensuring that the monitoring functionality remains active.

<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".SimChangeReceivers"
    android:name=".MyDeviceAdminReceiver"
    android:label="DeviceAdminReceiver"
    android:permission="android.permission.BIND_DEVICE_ADMIN"
    android:exported="true">
    <meta-data
        android:name="android.app.device_admin"
        android:resource="@xml/device_admin_policies" />
    <intent-filter>
        <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
    </intent-filter>
</receiver>

2. MyDeviceAdminReceiver.kt

This Kotlin class extends DeviceAdminReceiver and handles various device administration events. It logs these events and displays toast messages.

class MyDeviceAdminReceiver : DeviceAdminReceiver() {

    private val TAG = "MyDeviceAdminReceivers"

    private fun showToast(context: Context, msg: String) {
            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
    }

    override fun onEnabled(context: Context, intent: Intent) {
        Log.i(TAG, "onEnabled")
        showToast(context, "onEnabled")
    }

    override fun onDisableRequested(context: Context, intent: Intent): CharSequence =
        "onDisableRequested"

    override fun onDisabled(context: Context, intent: Intent) {
        Log.i(TAG, "onDisabled")
        showToast(context, "onDisabled")
    }

    override fun onPasswordChanged(context: Context, intent: Intent, userHandle: UserHandle) =
        showToast(context, "onPasswordChanged")

    override fun onPasswordFailed(context: Context, intent: Intent, userHandle: UserHandle) {
        Log.i(TAG, "onPasswordFailed")
        showToast(context, "onPasswordFailed")
    }

    override fun onPasswordSucceeded(context: Context, intent: Intent, userHandle: UserHandle) {
        Log.i(TAG, "onPasswordSucceeded")
        showToast(context, "onPasswordSucceeded")
    }

}

3. res/xml/device_admin_policies.xml

This XML file specifies the policies that can be enforced by the device administrator. In this case, various password-related policies are defined.

4. MainActivity.kt

The MainActivity.kt class contains a button that allows the user to enable the app as a device administrator..


How to Use

  1. Enable Device Administrator:
  • Launch the app.
  • Click the "Enable Device Administrator" button.
  • Follow the prompts to enable the app as a device administrator. This step is necessary for the app to monitor device events.
  1. Lock/Unlock Detection:
  • Once the app is enabled as a device administrator, it will monitor lock and unlock events. *If the user enters an incorrect PIN, the app will log the event and display a toast message on the screen.

Contributing

Contributions are welcome! If you have any improvements or bug fixes, please submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Special thanks to the Android developer community for their support and contributions.


Contact

If you have any questions or need further assistance, feel free to contact the project owner:

Ali Haider

[email protected]

https://github.com/alihaider78222

lock-unlock-detection-poc's People

Contributors

alihaider78222 avatar

Stargazers

 avatar Umair Adil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.