summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2012-12-11 11:51:41 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-12-11 11:51:41 -0800
commit5def50da0de624abeafafe71dc72b4baf423b985 (patch)
treede1156e498ce724e573674afa294efff6609f5e3 /services
parentd39a0d8041cec16429331937ec81d55f18b0db72 (diff)
parentbbdb062d98275f6833ebc2f0998b9e2a6534cecb (diff)
downloadframeworks_base-5def50da0de624abeafafe71dc72b4baf423b985.zip
frameworks_base-5def50da0de624abeafafe71dc72b4baf423b985.tar.gz
frameworks_base-5def50da0de624abeafafe71dc72b4baf423b985.tar.bz2
Merge "Fallback to default dream if the current dream is removed." into jb-mr1.1-dev
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,