summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2012-12-10 18:15:07 -0500
committerJohn Spurlock <jspurlock@google.com>2012-12-10 18:15:07 -0500
commitbbdb062d98275f6833ebc2f0998b9e2a6534cecb (patch)
tree5494e85d5cdee6ed398bf90ec1f4c081a088893b /services
parent8642f406dcfa23836903540c7ecb0895e1e7ac4d (diff)
downloadframeworks_base-bbdb062d98275f6833ebc2f0998b9e2a6534cecb.zip
frameworks_base-bbdb062d98275f6833ebc2f0998b9e2a6534cecb.tar.gz
frameworks_base-bbdb062d98275f6833ebc2f0998b9e2a6534cecb.tar.bz2
Fallback to default dream if the current dream is removed.
To minimize fix size, return only valid dreams from the service api. Settings will "just work" with no changes. Bug:7699398 Change-Id: I3eb88237a8ccc421fdb68d1de19820614b13d7b8
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/dreams/DreamManagerService.java35
1 files changed, 34 insertions, 1 deletions
diff --git a/services/java/com/android/server/dreams/DreamManagerService.java b/services/java/com/android/server/dreams/DreamManagerService.java
index 7e4a554..dd0b5b3 100644
--- a/services/java/com/android/server/dreams/DreamManagerService.java
+++ b/services/java/com/android/server/dreams/DreamManagerService.java
@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -38,6 +39,8 @@ import android.util.Slog;
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
import libcore.util.Objects;
@@ -279,7 +282,37 @@ public final class DreamManagerService extends IDreamManager.Stub {
String names = Settings.Secure.getStringForUser(mContext.getContentResolver(),
Settings.Secure.SCREENSAVER_COMPONENTS,
userId);
- return names == null ? null : componentsFromString(names);
+ ComponentName[] components = componentsFromString(names);
+
+ // first, ensure components point to valid services
+ List<ComponentName> validComponents = new ArrayList<ComponentName>();
+ if (components != null) {
+ for (ComponentName component : components) {
+ if (serviceExists(component)) {
+ validComponents.add(component);
+ } else {
+ Slog.w(TAG, "Dream " + component + " does not exist");
+ }
+ }
+ }
+
+ // fallback to the default dream component if necessary
+ if (validComponents.isEmpty()) {
+ ComponentName defaultDream = getDefaultDreamComponent();
+ if (defaultDream != null) {
+ Slog.w(TAG, "Falling back to default dream " + defaultDream);
+ validComponents.add(defaultDream);
+ }
+ }
+ return validComponents.toArray(new ComponentName[validComponents.size()]);
+ }
+
+ private boolean serviceExists(ComponentName name) {
+ try {
+ return name != null && mContext.getPackageManager().getServiceInfo(name, 0) != null;
+ } catch (NameNotFoundException e) {
+ return false;
+ }
}
private void startDreamLocked(final ComponentName name,