Initial implementation of ThemeService
This CL introduces the initial API for the Theme Service, providing a structured and robust way for system services to manage user-specific theme settings.This new API is intended to replace the existing, error-prone method of direct JSON manipulation of the theme_customization_overlay_packages secure setting.
This new approach ensures a clean and type-safe method of managing themes. The service also listens for changes to this setting, ensuring compatibility with any existing code that modifies it directly.
The public API in ThemeManager includes:
- `registerThemeSettingsCallback(callback)`
- `unregisterThemeSettingsCallback(callback)`
- `updateThemeSettings(settings)`
- `getThemeSettings()`
Here's how to interact with the service:
```
// Get the ThemeManager instance
ThemeManager manager = context.getSystemService(ThemeManager.class);
// To update the theme, create a new ThemeSettings object using the
// builder. This example creates a theme from a preset color.
ThemeSettings newSettings = ThemeSettings.builder(
/* colorIndex */ 0,
/* themeStyle */ ThemeStyle.TONAL_SPOT
).buildFromPreset(
Color.valueOf(0xFF1A73E8), // systemPalette
Color.valueOf(0xFF1A73E8) // accentColor
);
// Pass the complete settings object to update the theme.
manager.updateThemeSettings(newSettings);
// To get the current settings:
ThemeSettings currentSettings = manager.getThemeSettings();
if (currentSettings != null) {
if (currentSettings instanceof ThemeSettingsPreset) {
// Handle preset-based theme
ThemeSettingsPreset preset = (ThemeSettingsPreset) currentSettings;
Color palette = preset.systemPalette();
Color accent = preset.accentColor();
} else if (currentSettings instanceof ThemeSettingsWallpaper) {
// Handle wallpaper-based theme
ThemeSettingsWallpaper wallpaper = (ThemeSettingsWallpaper) currentSettings;
boolean useForLockscreen = wallpaper.colorBoth();
}
}
```
This new API provides a solid foundation for more advanced theme customization features in the future.
Bug: 333694176
Test: atest FrameworksServicesTests_theme
Flag: android.server.enable_theme_service
Change-Id: I114b3ba1f63ceb5429c63e18a9a4a00a0b62df09
Loading
Please register or sign in to comment