Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Task: Action to Modify System Settings

Implementation updated per review feedback:

  • Use single ActionId with SettingType enum (SYSTEM/SECURE/GLOBAL)
  • Default to SYSTEM (doesn't require PRO mode)
  • Move to APPS category
  • Use SettingsUtils instead of SystemBridge
  • Add WRITE_SECURE_SETTINGS permission requirement for Secure/Global
  • Create AndroidSettingsAdapter interface
  • Create ChooseSettingScreen to select from existing settings
  • Remove fully qualified names, use proper imports throughout
  • Use KeyMapperDropdownMenu component throughout
  • Consolidate all SettingsAdapter methods to use SettingType parameter
  • Add navigation button to ChooseSettingScreen
  • Refactor getKeys to getAll returning Map instead of List
  • Wire up navigation result handling
  • Manual verification and screenshots

Latest Changes (Interface Simplification)

SettingsAdapter Complete Refactoring

  • getAll method: Renamed from getKeys, now returns Map<String, String?> with both keys and values in one call
  • getValue method: Consolidated three separate methods into one with SettingType parameter
  • Simplified interface: Now only 3 methods total - getAll, getValue, modifySetting
  • More efficient: getAll returns both keys and current values, eliminating need for separate getValue calls

ActionErrorSnapshot

  • Imported SettingType: Using proper import instead of fully qualified name

ChooseSettingViewModel

  • Optimized: Now uses single getAll call to get both keys and values
  • Cleaner code: Simplified from nested when statements to single map operation

All review feedback addressed. The API is now consistent with all methods taking SettingType as a parameter.

Original prompt

This section details on the original issue you should resolve

<issue_title>Action to modify system settings</issue_title>
<issue_description>TODO

  • Select global, system, secure.
  • Use system bridge for global and secure. Use MODIFY_SYSTEM_SETTINGS permission for system settings.
  • Let the user select a value from a dropdown with the current values, and also write their own value in a text field.

Have you checked if an issue already exists for this feature request?

  • Nobody else has requested this feature before

What feature would you like added?

You need either "Shizuku" or "Change System Settings" permission.

What I want to do
screen_off_timeout=2147483647
I want to change it to

What I want to do
I want to change it to screen_off_timeout=2147483647 by pressing a physical key.

KeepScreenOn can actually be changed using the "Change System Settings" permission.

In SetEdit, you can change it using Shizuku.

App version

3.2.1-foss

Device model and manufacturer

Xperia5iv

Extra info

  • My device is rooted</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@sds100
Copy link
Collaborator

sds100 commented Oct 31, 2025

@copilot

  • Use the same ActionId for all actions, and use an enum to specify whether it is global, system, or secure.
  • Default to "system" because this doesn't require PRO mode.
  • The dropdown should be populated with all the setting keys on the device. Use contentresolver or Settings class to list all the current keys.

Copilot AI changed the title [WIP] Add action to modify system settings Add actions to modify Android system settings via key mappings Oct 31, 2025
Copilot AI requested a review from sds100 October 31, 2025 13:49
Copilot finished work on behalf of sds100 October 31, 2025 13:49
@sds100 sds100 added this to the 4.0 milestone Oct 31, 2025
- Replace 3 separate ActionIds with single MODIFY_SETTING
- Add SettingType enum (SYSTEM, SECURE, GLOBAL)
- Update ActionData.ModifySetting to use enum instead of sealed class
- Add dropdown for setting type in UI
- Default to SYSTEM type (no PRO mode required)
- Update all mappers and handlers accordingly

Co-authored-by: sds100 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot

  • Use the same ActionId for all actions, and use an enum to specify whether it is global, system, or secure.
    ...

Done in commit 927a3d6:

  • ✅ Using single MODIFY_SETTING ActionId with SettingType enum (SYSTEM/SECURE/GLOBAL)
  • ✅ Defaults to SYSTEM (no PRO mode required)
  • ✅ Added dropdown for setting type selection

Note: I've created SettingsAdapter.kt to query device settings via ContentResolver, but haven't integrated it into the UI dropdown yet. The current implementation allows manual text entry for setting keys. Would you like me to add the setting key dropdown populated from the device in a follow-up commit?

Copilot AI changed the title Add actions to modify Android system settings via key mappings Add action to modify Android system settings via key mappings Oct 31, 2025
Copilot finished work on behalf of sds100 October 31, 2025 14:00
Copy link
Collaborator

@sds100 sds100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

implement my changes

open val settingKey: String,
open val value: String,
) {
data class System(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

use enum instead

audioService.setRingerModeInternal(ringerMode, processPackageName)
}

override fun putSystemSetting(key: String?, value: String?): Boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. Do not need to use the system bridge at all for writing settings. The system bridge will grant Key Mapper WRITE_SECURE_SETTINGS permission when its started. So for secure and global settings, ask for Permission.WRITE_SECURE_SETTINGS in ActionErrorSnapshot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 51b18eb. Removed all SystemBridge methods for writing settings. Now using SettingsUtils directly with permission checks in ActionErrorSnapshot:

  • System settings: requires WRITE_SETTINGS permission
  • Secure/Global settings: requires WRITE_SECURE_SETTINGS permission (granted by SystemBridge on start)

return SettingsUtils.getSecureSetting<Int>(ctx, "doze_always_on") == 1
}

override fun modifySystemSetting(key: String, value: String): KMResult<*> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the existing methods in SettingsUtils. And create an AndroidSettingsAdapter interface for it so PerformActionsUseCase can use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 51b18eb. Created AndroidSettingsAdapter interface that uses SettingsUtils methods for modifying settings. PerformActionsUseCase now uses SettingsAdapter instead of DisplayAdapter.

ActionId.FORCE_STOP_APP -> R.string.action_force_stop_app
ActionId.CLEAR_RECENT_APP -> R.string.action_clear_recent_app

ActionId.MODIFY_SYSTEM_SETTING -> R.string.action_modify_system_setting
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a single ActionId and put it in the APPS category

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 51b18eb. Moved MODIFY_SETTING to APPS category.

}

@Composable
private fun ModifySettingActionBottomSheetContent(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a dropdown. Create another screen that lets the user select an existing setting and add a button to link to it. Each list item should have the key and current value. This screen should have a search box.

Look at ChooseActionsScreen for how this is done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commits 51b18eb and b57cdf8. Created ChooseSettingScreen similar to ChooseActionsScreen:

  • Searchable list of all available settings
  • Shows current value for each setting
  • Dropdown to select setting type (System/Secure/Global)
  • Each list item displays key and current value
  • Returns selected setting to populate bottom sheet

Next commit will wire up the navigation to open this screen from the bottom sheet.

Copilot AI and others added 2 commits October 31, 2025 14:11
- Move MODIFY_SETTING to APPS category
- Create AndroidSettingsAdapter interface implementing SettingsAdapter
- Use SettingsUtils for all setting modifications (no SystemBridge needed)
- Remove SystemBridge methods for settings (putSystemSetting, etc)
- Add permission checks: WRITE_SETTINGS for System, WRITE_SECURE_SETTINGS for Secure/Global
- Remove setting methods from DisplayAdapter

Co-authored-by: sds100 <[email protected]>
- Created ChooseSettingViewModel with setting type selection and search
- Created ChooseSettingScreen with dropdown for type and searchable list
- Added ChooseSetting nav destination
- Added string resources for choosesetting screen
- Screen shows all available settings with current values
- User can select from existing settings or enter custom key

Next: Wire up navigation in CreateActionDelegate

Co-authored-by: sds100 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot

implement my changes

Changes implemented in commits 51b18eb and b57cdf8. Summary:

  • ✅ Single ActionId with SettingType enum
  • ✅ Moved to APPS category
  • ✅ Using SettingsUtils (no SystemBridge)
  • ✅ WRITE_SECURE_SETTINGS permission for Secure/Global
  • ✅ Created ChooseSettingScreen with search

Still completing navigation wiring to connect the Choose Setting button to the screen.

Copilot AI requested a review from sds100 October 31, 2025 14:18
Copilot finished work on behalf of sds100 October 31, 2025 14:18
Copy link
Collaborator

@sds100 sds100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

implement my review

fun onSettingClick(key: String, currentValue: String?) {
viewModelScope.launch {
popBackStackWithResult(
kotlinx.serialization.json.Json.encodeToString(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use fully qualified names, import them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c1f999f. Now importing SettingType, Json, and Serializable instead of using fully qualified names.


@kotlinx.serialization.Serializable
data class ChooseSettingResult(
val settingType: io.github.sds100.keymapper.system.settings.SettingType,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c1f999f. Removed all fully qualified names throughout the file.

modifier = Modifier.fillMaxWidth().menuAnchor(),
singleLine = true,
)
ExposedDropdownMenu(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use KeyMapperDropdownMenu

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c1f999f. Replaced custom ExposedDropdownMenuBox implementation with KeyMapperDropdownMenu component. Also cleaned up unused imports.

…perDropdownMenu

- Import SettingType instead of using fully qualified names
- Import Json and Serializable for cleaner code
- Replace custom dropdown with KeyMapperDropdownMenu in ChooseSettingScreen
- Remove unused imports
- Update NavDestination to use imported SettingType

Co-authored-by: sds100 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot

implement my review

All review feedback implemented in c1f999f:

  • ✅ Removed fully qualified names, using proper imports
  • ✅ Using KeyMapperDropdownMenu component
  • ✅ Cleaned up unused imports

The code is now cleaner and follows the project conventions.

- Consolidate modify methods into single modifySetting(settingType, key, value) method
- Import SettingType instead of using fully qualified name
- Replace custom dropdown with KeyMapperDropdownMenu
- Add onChooseSetting callback and Button to navigate to ChooseSettingScreen
- Update PerformActionsUseCase to use new unified method
- Add onChooseSettingClick method to CreateActionDelegate for navigation

Co-authored-by: sds100 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot

more review items

All review items implemented in c351c61:

  • ✅ Using KeyMapperDropdownMenu
  • ✅ Importing SettingType
  • ✅ Added navigation callback and button to ChooseSettingScreen
  • ✅ Consolidated modify methods into single method with SettingType parameter
  • ✅ Using existing SettingsUtils methods

Code is now cleaner and follows project conventions.

Copilot AI requested a review from sds100 October 31, 2025 14:40
Copilot finished work on behalf of sds100 October 31, 2025 14:40
Copy link
Collaborator

@sds100 sds100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

more changes

}

interface SettingsAdapter {
fun getSystemSettingKeys(): List<String>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do the same for getValue and getKeys methods. Can you refactor the getKeys methods to be called "getAll" and return a Map<String, String> with the keys and values of all settings.


is ActionData.ModifySetting -> {
return when (action.settingType) {
io.github.sds100.keymapper.system.settings.SettingType.SYSTEM -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import SettingType

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b149abf. Now importing SettingType and using it throughout the file instead of fully qualified name.

…rrorSnapshot

- Refactored getKeys methods into single getAll(settingType) returning Map<String, String?>
- Consolidated getValue methods into single getValue(settingType, key) method
- Updated ChooseSettingViewModel to use new unified methods
- Imported SettingType in ActionErrorSnapshot instead of using fully qualified name
- Simplified interface with only 3 methods: getAll, getValue, modifySetting

Co-authored-by: sds100 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot

more changes

All changes implemented in b149abf:

  • ✅ Consolidated getValue and getKeys methods
  • ✅ Renamed getKeys to getAll returning Map<String, String?>
  • ✅ Imported SettingType in ActionErrorSnapshot
  • ✅ Simplified SettingsAdapter interface to 3 methods

The interface is now fully consistent with all methods taking SettingType as a parameter.

Copilot AI requested a review from sds100 November 2, 2025 00:24
Copilot finished work on behalf of sds100 November 2, 2025 00:24
@sds100 sds100 moved this to In progress in Key Mapper Nov 7, 2025
@sds100 sds100 marked this pull request as ready for review November 9, 2025 18:43
@sds100 sds100 merged commit 7475f2c into develop Nov 9, 2025
1 of 3 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Key Mapper Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Action to modify system settings

2 participants