feature/alarm-wake-screen#2
Merged
Merged
Conversation
…ng permissions
This commit introduces the `triggerx` library, which provides functionalities for scheduling exact alarms and managing necessary permissions (Alarm, Overlay, Battery Optimization) in a Jetpack Compose-friendly way.
Key changes:
- **TriggerX Library Module (`triggerx`)**:
- `TriggerXAlarmScheduler`: Manages scheduling and cancelling of exact alarms using `AlarmManager`.
- `TriggerXAlarmReceiver`: `BroadcastReceiver` to handle alarm intents and launch `TriggerActivity`.
- `TriggerActivity`: Simple activity displayed when an alarm triggers, showing "ALARM!" text.
- `permission/TriggerXPermissionManager.kt`:
- `AlarmPermissionManager`: Provides utility functions to check and request permissions for exact alarms, overlay, and battery optimization.
- `PermissionType` enum: Defines the types of permissions managed.
- `PermissionState`: A state holder class for Compose to manage the lifecycle and UI of permission requests.
- `permission/TriggerXPermissionComposable.kt`:
- `rememberAppPermissionState()`: Composable function to create and remember `PermissionState`.
- `PermissionLifeCycleCheckEffect()`: Composable to handle permission checks on lifecycle events (e.g., `ON_RESUME`).
- `ShowPopup()`: Composable to display a generic rationale/information dialog.
- `AndroidManifest.xml`: Declares necessary permissions (`SCHEDULE_EXACT_ALARM`, `FOREGROUND_SERVICE`, `POST_NOTIFICATIONS`, `SYSTEM_ALERT_WINDOW`, `WAKE_LOCK`, `REQUEST_IGNORE_BATTERY_OPTIMIZATIONS`), `TriggerActivity`, and `TriggerXAlarmReceiver`.
- `build.gradle.kts`: Configured with necessary dependencies including Hilt, Compose, and Kotlin serialization.
- `.gitignore` and Proguard rules added.
- **App Module (`app`)**:
- `MainActivity`: Updated to use `HomeScreen` as its content.
- `HomeScreen.kt`: New Composable screen demonstrating the usage of `rememberAppPermissionState` to request permissions and `TriggerXAlarmScheduler` (via `HomeViewModel`) to schedule an alarm.
- `HomeViewModel.kt`: New ViewModel that uses `TriggerXAlarmScheduler` to schedule and cancel alarms. Injected using Hilt.
- `TriggerXApplication.kt`: New `Application` class annotated with `@HiltAndroidApp` for Hilt integration.
- `AndroidManifest.xml`: Updated to use `TriggerXApplication`.
- `build.gradle.kts`: Added Hilt dependencies and `triggerx` module dependency.
- **Project Level**:
- `settings.gradle.kts`: Includes the new `triggerx` module and enables `TYPESAFE_PROJECT_ACCESSORS`.
- `build.gradle.kts`: Added plugin aliases for `android.library`, `hilt`, and `ksp`.
- `gradle/libs.versions.toml`: Updated Kotlin version and added versions/libraries for Hilt, KSP, and Kotlin Serialization.
- IDE configuration files (`.idea/deploymentTargetSelector.xml`, `.idea/vcs.xml`, updated `.idea/gradle.xml`, `.idea/.name`) added/updated.
This refactoring centralizes alarm and permission logic into a reusable library, making the main application cleaner and promoting better separation of concerns.
This commit introduces support for requesting the "Show on Lock Screen" permission, specifically for Xiaomi devices. This permission is often required for apps that need to display information or trigger actions while the device is locked.
Key changes:
- **TriggerXPermissionManager.kt**:
- Added `isShowOnLockScreenPermissionEnable()`: Checks if the "Show on Lock Screen" permission is granted for Xiaomi devices using `AppOpsManager`.
- Updated `isGranted()`: Now includes a check for `PermissionType.LOCK_SCREEN`.
- Updated `getPermissionIntent()`: Provides the specific intent to navigate users to the permission settings screen for "Show on Lock Screen" on Xiaomi devices.
- Added `LOCK_SCREEN` to the `PermissionType` enum.
- **TriggerXPermissionComposable.kt**:
- Modified `rememberAppPermissionState()`: Conditionally adds `PermissionType.LOCK_SCREEN` to the list of permissions to be checked if the device manufacturer is "Xiaomi".
- Minor formatting adjustments.
This enhancement ensures that applications using the TriggerX library can correctly prompt users for necessary lock screen permissions on Xiaomi devices, improving the reliability of features that depend on this capability.
This commit removes extra whitespace in the `TriggerXPermissionComposable.kt` file.
Key changes:
- **triggerx/src/main/java/com/meticha/triggerx/permission/TriggerXPermissionComposable.kt**:
- Removed extraneous whitespace in an `else` branch of a `when` statement.
This change improves code formatting and readability without affecting functionality.
Feat: Add Lock Screen Permission for Xiaomi Devices
This commit modifies the alarm handling mechanism to launch `TriggerActivity` via a `TriggerXForegroundService`. This approach aims to improve reliability, especially on devices with aggressive background restrictions.
Key changes:
- **TriggerXAlarmReceiver.kt**:
- When an alarm is received with `ALARM_ACTION`, it now starts `TriggerXForegroundService` instead of directly launching `TriggerActivity`.
- Removed direct WakeLock handling as this will be managed by the foreground service.
- **TriggerXForegroundService.kt (New File)**:
- A new `Service` that acquires a `PowerManager.PARTIAL_WAKE_LOCK` upon starting.
- In `onStartCommand`, if the intent action is `ALARM_ACTION`, it launches `TriggerActivity` with `FLAG_ACTIVITY_NEW_TASK` and `FLAG_ACTIVITY_CLEAR_TOP`.
- The service stops itself (`stopSelf()`) after launching the activity or if the intent action is unknown.
- The WakeLock is acquired with a 1-minute timeout and released in a `finally` block to ensure it's always released.
- Returns `START_NOT_STICKY`.
- **TriggerActivity.kt**:
- Updated screen-on and show-when-locked logic:
- For Android O_MR1 (API 27) and above, uses `setShowWhenLocked(true)` and `setTurnScreenOn(true)`.
- For older versions (specifically API 26), uses deprecated window flags: `FLAG_SHOW_WHEN_LOCKED`, `FLAG_TURN_SCREEN_ON`, `FLAG_KEEP_SCREEN_ON`, and `FLAG_DISMISS_KEYGUARD`.
- **triggerx/src/main/AndroidManifest.xml**:
- Added declaration for the new `TriggerXForegroundService` with `foregroundServiceType="shortService"`.
- Removed `android.permission.POST_NOTIFICATIONS` as it's not directly used by the foreground service for this alarm trigger mechanism.
- **IDE Configuration**:
- Added `.idea/git_toolbox_prj.xml` for GitToolBox plugin settings, enabling commit message validation.
This change delegates the responsibility of waking the device and showing the activity over the lock screen to a foreground service, which is generally more resilient to system optimizations.
This commit introduces a configurable logging mechanism for the `triggerx` library, allowing users to provide their own logging implementation. It also updates existing logging calls to use this new system and refines some UI text.
Key changes:
- **Logger Implementation (`triggerx/src/main/java/com/meticha/triggerx/logger`)**:
- `TriggerXLogger.kt`: Defines an interface for logging (d, e, i, w methods).
- `DefaultTriggerXLogger.kt`: Provides a default implementation of `TriggerXLogger` using `android.util.Log`.
- `TriggerXLoggerConfig.kt`:
- Introduces `LoggerConfig` object to hold the current logger instance and a default `TAG`.
- Provides `setLogger()` function to allow users to set a custom `TriggerXLogger` implementation.
- **Integration with Existing Components**:
- `TriggerXAlarmScheduler.kt`: Replaced `android.util.Log` calls with `LoggerConfig.logger`.
- `TriggerXForegroundService.kt`: Replaced `android.util.Log` calls with `LoggerConfig.logger` and removed the local `TAG` constant.
- `TriggerXAlarmReceiver.kt`: Replaced `android.util.Log` calls with `LoggerConfig.logger` and removed the local `TAG` constant.
- `TriggerXPermissionComposable.kt`:
- Replaced `android.util.Log` call in `PermissionLifeCycleCheckEffect` with `LoggerConfig.logger`.
- Updated rationale popup message from "Bhai api do have permission" to "Permissions are required to proceed further".
- Changed the confirm button text in `ShowPopup` from "OK" to "Grant".
- Removed a commented-out line related to `showSettingsPopUp`.
This change enhances the flexibility of the TriggerX library by allowing developers to integrate their preferred logging solutions, improving debuggability and maintainability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the base implementation of TriggerX library.
✨ Features
Activityover the lock-screen & turns the screen on.TriggerX.init { … }— configure notifications, logger, & alarm UI.