From 2c8d67c9b0574f229809d99b3d55aa411fad0c84 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Wed, 23 Apr 2014 13:46:21 -0700 Subject: [PATCH] Various CTS fixes WallpaperManager should always do a null check on the service object. SystemServer should always bring up the DevicePolicyManagerService, and let the service do appropriate default no-ops if the feature is not supported. Change-Id: Iaaf12b60ed375fe2e341ec11faa10c9344d7d9da --- core/java/android/app/WallpaperManager.java | 39 ++++++++----------- .../java/com/android/server/SystemServer.java | 9 ++--- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index f291e8298bc1f..e16ae7ae2c345 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -283,13 +283,15 @@ public class WallpaperManager { } private Bitmap getCurrentWallpaperLocked(Context context) { + if (mService == null) { + Log.w(TAG, "WallpaperService not running"); + return null; + } + try { Bundle params = new Bundle(); ParcelFileDescriptor fd = mService.getWallpaper(this, params); if (fd != null) { - int width = params.getInt("width", 0); - int height = params.getInt("height", 0); - try { BitmapFactory.Options options = new BitmapFactory.Options(); return BitmapFactory.decodeFileDescriptor( @@ -311,28 +313,21 @@ public class WallpaperManager { } private Bitmap getDefaultWallpaperLocked(Context context) { - try { - InputStream is = context.getResources().openRawResource( - com.android.internal.R.drawable.default_wallpaper); - if (is != null) { - int width = mService.getWidthHint(); - int height = mService.getHeightHint(); - + InputStream is = context.getResources().openRawResource( + com.android.internal.R.drawable.default_wallpaper); + if (is != null) { + try { + BitmapFactory.Options options = new BitmapFactory.Options(); + return BitmapFactory.decodeStream(is, null, options); + } catch (OutOfMemoryError e) { + Log.w(TAG, "Can't decode stream", e); + } finally { try { - BitmapFactory.Options options = new BitmapFactory.Options(); - return BitmapFactory.decodeStream(is, null, options); - } catch (OutOfMemoryError e) { - Log.w(TAG, "Can't decode stream", e); - } finally { - try { - is.close(); - } catch (IOException e) { - // Ignore - } + is.close(); + } catch (IOException e) { + // Ignore } } - } catch (RemoteException e) { - // Ignore } return null; } diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index d5e49a05cfc60..896872546f5fe 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -58,6 +58,7 @@ import com.android.server.am.ActivityManagerService; import com.android.server.am.BatteryStatsService; import com.android.server.clipboard.ClipboardService; import com.android.server.content.ContentService; +import com.android.server.devicepolicy.DevicePolicyManagerService; import com.android.server.display.DisplayManagerService; import com.android.server.dreams.DreamManagerService; import com.android.server.input.InputManagerService; @@ -107,8 +108,6 @@ public final class SystemServer { */ private static final String BACKUP_MANAGER_SERVICE_CLASS = "com.android.server.backup.BackupManagerService$Lifecycle"; - private static final String DEVICE_POLICY_MANAGER_SERVICE_CLASS = - "com.android.server.devicepolicy.DevicePolicyManagerService$Lifecycle"; private static final String APPWIDGET_SERVICE_CLASS = "com.android.server.appwidget.AppWidgetService"; private static final String PRINT_MANAGER_SERVICE_CLASS = @@ -538,9 +537,9 @@ public final class SystemServer { } try { - if (pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) { - mSystemServiceManager.startService(DEVICE_POLICY_MANAGER_SERVICE_CLASS); - } + // Always start the Device Policy Manager, so that the API is compatible with + // API8. + mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); } catch (Throwable e) { reportWtf("starting DevicePolicyService", e); }