From ccdb292eecc53c1343eaae0f4e0e9342326bad16 Mon Sep 17 00:00:00 2001 From: Adnan Begovic Date: Thu, 24 Mar 2016 17:55:10 -0700 Subject: [PATCH] cmsdk: Mandate themes feature xml's for service implementation. The feature xml plays two roles: 1) To allow sdk interface (constructor) to throw when system service is unavailable. This allows for clearer platform development debugging. 2) To allow for simpler disambiguation of what services to instrument in a modular environment. Change-Id: I67b16a0725ed89d5ddbc973b09337d6227087e4d TICKET: CYNGNOS-2295 --- api/cm_current.txt | 2 +- .../internal/IconCacheManagerService.java | 9 ++++++++- .../platform/internal/ThemeManagerService.java | 7 ++++++- src/java/cyanogenmod/app/CMContextConstants.java | 8 ++++++++ src/java/cyanogenmod/themes/ThemeManager.java | 15 +++++++++++---- system-api/cm_system-current.txt | 2 +- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/api/cm_current.txt b/api/cm_current.txt index 7168d70..e906245 100644 --- a/api/cm_current.txt +++ b/api/cm_current.txt @@ -1073,7 +1073,7 @@ package cyanogenmod.themes { public class ThemeManager { method public deprecated void addClient(cyanogenmod.themes.ThemeManager.ThemeChangeListener); method public void applyDefaultTheme(); - method public static cyanogenmod.themes.ThemeManager getInstance(); + method public static cyanogenmod.themes.ThemeManager getInstance(android.content.Context); method public cyanogenmod.themes.ThemeChangeRequest.RequestType getLastThemeChangeRequestType(); method public long getLastThemeChangeTime(); method public int getProgress(); diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/IconCacheManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/IconCacheManagerService.java index 56be660..de86458 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/IconCacheManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/IconCacheManagerService.java @@ -42,15 +42,22 @@ public class IconCacheManagerService extends SystemService { private static final long PURGED_ICON_CACHE_SIZE = 25165824L; // 24 MB private long mIconCacheSize = 0L; + private Context mContext; public IconCacheManagerService(Context context) { super(context); + mContext = context; } @Override public void onStart() { Log.d(TAG, "registerIconCache cmiconcache: " + this); - publishBinderService(CMContextConstants.CM_ICON_CACHE_SERVICE, mService); + if (mContext.getPackageManager().hasSystemFeature(CMContextConstants.Features.THEMES)) { + publishBinderService(CMContextConstants.CM_ICON_CACHE_SERVICE, mService); + } else { + Log.wtf(TAG, "IconCache service started by system server but feature xml not" + + " declared. Not publishing binder service!"); + } } private void purgeIconCache() { diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/ThemeManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/ThemeManagerService.java index 24a7e26..8c0af4c 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/ThemeManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/ThemeManagerService.java @@ -236,7 +236,12 @@ public class ThemeManagerService extends SystemService { @Override public void onStart() { - publishBinderService(CMContextConstants.CM_THEME_SERVICE, mService); + if (mContext.getPackageManager().hasSystemFeature(CMContextConstants.Features.THEMES)) { + publishBinderService(CMContextConstants.CM_THEME_SERVICE, mService); + } else { + Log.wtf(TAG, "Theme service started by system server but feature xml not" + + " declared. Not publishing binder service!"); + } // listen for wallpaper changes IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED); mContext.registerReceiver(mWallpaperChangeReceiver, filter); diff --git a/src/java/cyanogenmod/app/CMContextConstants.java b/src/java/cyanogenmod/app/CMContextConstants.java index e82c60b..83a7c2d 100644 --- a/src/java/cyanogenmod/app/CMContextConstants.java +++ b/src/java/cyanogenmod/app/CMContextConstants.java @@ -157,5 +157,13 @@ public final class CMContextConstants { */ @SdkConstant(SdkConstant.SdkConstantType.FEATURE) public static final String TELEPHONY = "org.cyanogenmod.telephony"; + + /** + * Feature for {@link PackageManager#getSystemAvailableFeatures} and + * {@link PackageManager#hasSystemFeature}: The device includes the cm theme service + * utilized by the cmsdk. + */ + @SdkConstant(SdkConstant.SdkConstantType.FEATURE) + public static final String THEMES = "org.cyanogenmod.theme"; } } diff --git a/src/java/cyanogenmod/themes/ThemeManager.java b/src/java/cyanogenmod/themes/ThemeManager.java index 4c575ae..b580ccd 100644 --- a/src/java/cyanogenmod/themes/ThemeManager.java +++ b/src/java/cyanogenmod/themes/ThemeManager.java @@ -16,6 +16,7 @@ package cyanogenmod.themes; +import android.content.Context; import android.os.Handler; import android.os.IBinder; import android.os.Looper; @@ -47,14 +48,20 @@ public class ThemeManager { private Set mProcessingListeners = new ArraySet<>(); - private ThemeManager() { - mHandler = new Handler(Looper.getMainLooper()); + private ThemeManager(Context context) { sService = getService(); + if (context.getPackageManager().hasSystemFeature( + CMContextConstants.Features.THEMES) && sService == null) { + throw new RuntimeException("Unable to get ThemeManagerService. The service either" + + " crashed, was not started, or the interface has been called to early in" + + " SystemServer init"); + } + mHandler = new Handler(Looper.getMainLooper()); } - public static ThemeManager getInstance() { + public static ThemeManager getInstance(Context context) { if (sInstance == null) { - sInstance = new ThemeManager(); + sInstance = new ThemeManager(context); } return sInstance; diff --git a/system-api/cm_system-current.txt b/system-api/cm_system-current.txt index 7168d70..e906245 100644 --- a/system-api/cm_system-current.txt +++ b/system-api/cm_system-current.txt @@ -1073,7 +1073,7 @@ package cyanogenmod.themes { public class ThemeManager { method public deprecated void addClient(cyanogenmod.themes.ThemeManager.ThemeChangeListener); method public void applyDefaultTheme(); - method public static cyanogenmod.themes.ThemeManager getInstance(); + method public static cyanogenmod.themes.ThemeManager getInstance(android.content.Context); method public cyanogenmod.themes.ThemeChangeRequest.RequestType getLastThemeChangeRequestType(); method public long getLastThemeChangeTime(); method public int getProgress();