LockGuardX — Lock, Security & Utility Extension

LockGuardX — Device Lock, Security, Gesture & Battery Utility Extension

Hey everyone! Sharing an extension I’ve been building called LockGuardX.

What is LockGuardX?

LockGuardX is a non-visible extension that gives your App Inventor / Niotron / Rush CLI project a complete toolkit for device lock control, keyguard state, screen/wake management, proximity sensing, in-app swipe gestures, battery monitoring, an in-app PIN lock, and vibration — all in one component. No AccessibilityService, no root, and no system lock-screen bypass anywhere — everything is done through standard, documented Android APIs (DevicePolicyManager, KeyguardManager, PowerManager, SensorManager, BatteryManager).

The App Lock feature is a fully self-contained in-app PIN gate — it never draws its own UI, never overlays other apps, and never touches the real Android keyguard. It just tracks a locked/unlocked flag and stores a salted, hashed PIN; you build the PIN screen yourself in the designer and react to the events.

:sparkles: Key Features

  • :locked_with_key: Device Admin lock — lock the screen on command via user-consented Device Admin

  • :shield: Keyguard state (read-only) — check if the device has a secure lock, is currently locked, and get live locked/unlocked events

  • :desktop_computer: Screen / wake control — check screen-on state, briefly wake the screen, keep this app’s window awake

  • :stopwatch: Auto-lock — lock the device automatically after an idle timeout, with a resettable timer

  • :satellite_antenna: Proximity sensor — near/far detection with live events

  • :backhand_index_pointing_up: Swipe gesture detection — scoped strictly to this app’s own window, never system-wide

  • :battery: Battery & charging — level, charging state, charging type (AC/USB/Wireless), live change events

  • :key: App Lock (in-app PIN) — set/change/clear a salted SHA-256 PIN, lock/unlock events, no system keyguard involved

  • :vibration_mode: Vibration — simple vibrate control with hardware-availability check

:package: Installation

  1. Download the .aix file attached below.

  2. Import it into your project (App Inventor / Niotron: Extensions → Import extension).

  3. Drag the LockGuardX non-visible component onto your Screen.

  4. For LockDevice() to work, call RequestAdmin() first and have the user grant Device Administrator access.

  5. If you use App Lock, handle the AppLockTriggered event on every screen where the lock should apply — the extension never draws a PIN UI for you, so add it to each Screen where you want the lock enforced.

:locked_with_key: Permissions Used

  • BIND_DEVICE_ADMIN — required for LockDevice(); requested at runtime via RequestAdmin(), never silent

  • VIBRATE — for the Vibrate block (normal, auto-granted)

  • No AccessibilityService, no root, no system lock-screen bypass, no overlay permission anywhere in this extension

:books: Full Block Reference

Device Admin

Block Description
RequestAdmin() Prompts the user with the system dialog to grant Device Administrator access. Required before LockDevice() works.
IsAdminActive() Returns true if Device Administrator access is currently active.
RemoveAdmin() Revokes Device Administrator access.
LockDevice() Immediately locks the device screen (requires Device Admin).

Keyguard / Security State (read-only)

Block Description
IsDeviceSecure() Returns true if the device has a secure lock screen (PIN/Pattern/Password/Biometric) configured.
IsKeyguardLocked() Returns true if the lock screen is currently shown.
IsKeyguardSecure() Returns true if the lock mechanism itself is set up (secure/enabled), regardless of current lock state.
DeviceLocked()event Fired when the device becomes locked.
DeviceUnlocked()event Fired when the device becomes unlocked.

Screen / Wake

Block Description
IsScreenOn() Returns true if the screen is currently powered on.
IsInteractive() Returns true if the device is interactive (screen on, not dozing).
WakeScreen() Briefly wakes the screen if it’s off (auto-releases after 3s, no lingering wakelock).
KeepScreenOn(keepOn) Keeps this app’s own window screen on (true) or restores normal timeout (false).
ScreenOn()event Fired when the screen turns on.
ScreenOff()event Fired when the screen turns off.

Auto-Lock

Block Description
StartAutoLock(timeoutMs) Starts a countdown that calls LockDevice() automatically after the given timeout.
StopAutoLock() Cancels the auto-lock timer.
ResetAutoLockTimer() Resets the countdown back to the full timeout — call this on user interaction to avoid premature locking.

Proximity Sensor

Block Description
StartProximityDetection() Starts listening to the proximity sensor.
StopProximityDetection() Stops listening to the proximity sensor.
IsProximityNear() Returns true if an object is currently detected near the sensor (only valid while detection is running).
ProximitySensorAvailable Returns true if a proximity sensor is available on this device.
ProximityNear()event Fired when the proximity sensor detects a nearby object.
ProximityFar()event Fired when the proximity sensor no longer detects a nearby object.

Gesture Detection (this app’s window only)

Block Description
GestureSensitivity Get/set the swipe sensitivity multiplier (default 1.0; higher = shorter swipe needed).
EnableGestureDetection() Enables swipe detection on the current screen — scoped strictly to this app’s own window.
DisableGestureDetection() Disables swipe detection.
Swipe(direction, distance, velocity)event Fired on a detected swipe; direction is “up”/“down”/“left”/“right”, distance in dp, velocity in dp/s.

Battery / Charging

Block Description
GetBatteryLevel() Returns battery percentage (0-100), or -1 if unavailable.
IsCharging() Returns true if the device is currently charging or full while plugged in.
GetChargingType() Returns “AC”, “USB”, “Wireless”, or “None”.
BatteryChanged(level)event Fired when the battery level changes.
ChargingStarted()event Fired when charging begins.
ChargingStopped()event Fired when charging stops.

App Lock (in-app PIN — not a system lock)

Block Description
SetAppLockPin(pin) Sets/replaces the in-app PIN (stored only as a salted SHA-256 hash) and enables app lock.
ChangeAppLockPin(oldPin, newPin) Changes the PIN, only if oldPin matches the currently stored PIN.
ClearAppLockPin() Removes the stored PIN and disables app lock entirely.
HasAppLockPin() Returns true if a PIN has been set.
AppLockEnabled Get/set whether app lock is enabled.
IsAppLocked() Returns true if the app is currently in a locked state — show your own PIN UI while this is true.
UnlockApp(pin) Checks the entered PIN; unlocks and fires AppUnlocked on match, otherwise fires AppLockFailed.
AppLockTriggered()event Fired when the app returns to the foreground while locked — show your PIN screen here.
AppUnlocked()event Fired when UnlockApp() is called with the correct PIN.
AppLockFailed()event Fired when UnlockApp() is called with an incorrect PIN.

Vibration

Block Description
Vibrate(milliseconds) Vibrates the device for the given duration.
HasVibrator() Returns true if the device has vibrator hardware.

:warning: Notes / Limitations

  • App Lock is per-Screen, not global — the locked/unlocked flag lives on whichever Screen the extension instance is attached to. If your app has multiple screens, add the component and wire AppLockTriggered/UnlockApp on every screen you want protected, or a screen reachable via direct intent/deep-link could open without a PIN prompt.

  • LockDevice() silently no-ops if Device Admin hasn’t been granted or is restricted by device policy — always gate it behind IsAdminActive() in your blocks.

  • App Lock never draws any UI itself — you’re responsible for building the PIN/pattern entry screen and calling UnlockApp() with what the user types.

  • KeepScreenOn() and gesture detection only affect this app’s own window — nothing system-wide, nothing persists after the app closes.

:folded_hands: Feedback

Bug reports and feature requests welcome in this thread — especially around Device Admin behavior on different OEM skins (MIUI, ColorOS, etc. are known to add extra prompts/restrictions).

Version 1.0

com.zebdroid.lockguardx.aix (31.0 KB)

Please follow the community guidelines.

Sorry . i will update soon