View and edit Android on-device preferences: NO ROOT required! 🥳
Both legacy shared preferences and Preference Datastore are supported! 😎
Install the package:
npm i @charlesmuchene/pref-editorYou can override ADB connection settings with environment variables:
export PREF_EDITOR_ADB_HOST=localhost
export PREF_EDITOR_ADB_PORT=5037
export PREF_EDITOR_WATCHER_INTERVAL_MS=3000 # Max 180000 (3 minutes)import {
Preference,
TypeTag,
changePreference,
watchPreference,
} from "@charlesmuchene/pref-editor";
const connection = {
deviceId: "emulator-5554",
appId: "com.charlesmuchene.datastore",
filename: "settings.preferences_pb",
};
// Change a preference
const pref: Preference = {
key: "isVisited",
value: "false",
type: TypeTag.BOOLEAN,
};
await changePreference(pref, connection);
// Watch for preference changes (NEW: EventEmitter pattern)
const watch = await watchPreference({ key: "isVisited" }, connection);
watch.emitter.on("change", (newValue, preference) => {
console.log(`Preference changed: ${preference.key} = ${newValue}`);
});
watch.emitter.on("error", (error) => {
console.error("Watch error:", error);
});
// Clean up when done
watch.close();| Function | Description |
|---|---|
addPreference(preference, connection) |
Add a new preference |
changePreference(preference, connection) |
Modify existing preference |
deletePreference(key, connection) |
Remove a preference |
watchPreference(key, connection) |
Watch for preference changes |
readPreferences(connection) |
Read all preferences |
See the Android Preferences Editor MCP server project for comprehensive usage examples.
- string-set key-value preference type operations are partially supported
# Clone the repository
git clone https://github.com/charlesmuchene/pref-editor-js.git
cd pref-editor-js
# Install dependencies
npm install
# Run verification (lint, build, test, coverage)
npm run verifyFor detailed development setup and workflow, see DEV.md.
We welcome contributions! Please see:
- CONTRIBUTING.md - Contribution guidelines
- DEV.md - Development setup and workflow
- Fork the repository
- Create a feature branch:
git checkout -b feat/your-feature - Make your changes and add tests
- Run verification:
npm run verify - Submit a pull request with title format:
feat:,fix:, orBREAKING:
See LICENSE
- 📖 Documentation: DEV.md for development setup
- 🐛 Bug Reports: GitHub Issues
- 💡 Feature Requests: GitHub Issues
- 🤝 Contributing: CONTRIBUTING.md
- BREAKING:
watchPreferencenow uses EventEmitter pattern instead of streams - NEW: Added 3-minute maximum limit for watch intervals
- IMPROVED: Better error handling and event management
See releases for full changelog.