summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorDan Sandler <dsandler@android.com>2014-04-22 11:51:42 -0400
committerDan Sandler <dsandler@android.com>2014-04-22 11:51:42 -0400
commitdc5f16bf096796d2f822bce8a720fc26e898da5e (patch)
tree019bcbd02acf378e34f41dc85f60d76dc1dc7124 /packages
parent06661993037c28d2e189bfe809304a5d0e3ba5d8 (diff)
downloadframeworks_base-dc5f16bf096796d2f822bce8a720fc26e898da5e.zip
frameworks_base-dc5f16bf096796d2f822bce8a720fc26e898da5e.tar.gz
frameworks_base-dc5f16bf096796d2f822bce8a720fc26e898da5e.tar.bz2
Avoid sending broadcasts before BOOT_COMPLETED.
SystemUI instances can now take advantage of a new lifecycle callback, onBootCompleted(), to avoid jumping the gun. Bug: 14092537 Change-Id: I3f7db7a4753f874c4d75235f263c2bd374debec4
Diffstat (limited to 'packages')
-rw-r--r--packages/SystemUI/src/com/android/systemui/SystemUI.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/SystemUIApplication.java38
-rw-r--r--packages/SystemUI/src/com/android/systemui/recent/Recents.java35
3 files changed, 69 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUI.java b/packages/SystemUI/src/com/android/systemui/SystemUI.java
index cb624ad..85befff 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUI.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUI.java
@@ -35,6 +35,9 @@ public abstract class SystemUI {
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
}
+ protected void onBootCompleted() {
+ }
+
@SuppressWarnings("unchecked")
public <T> T getComponent(Class<T> interfaceType) {
return (T) (mComponents != null ? mComponents.get(interfaceType) : null);
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
index 0f55683..103991a 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -17,7 +17,12 @@
package com.android.systemui;
import android.app.Application;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.res.Configuration;
+import android.os.SystemProperties;
import android.util.Log;
import java.util.HashMap;
@@ -49,6 +54,7 @@ public class SystemUIApplication extends Application {
*/
private final SystemUI[] mServices = new SystemUI[SERVICES.length];
private boolean mServicesStarted;
+ private boolean mBootCompleted;
private final Map<Class<?>, Object> mComponents = new HashMap<Class<?>, Object>();
@Override
@@ -58,6 +64,23 @@ public class SystemUIApplication extends Application {
// application theme in the manifest does only work for activities. Keep this in sync with
// the theme set there.
setTheme(R.style.systemui_theme);
+
+ registerReceiver(new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (mBootCompleted) return;
+
+ if (DEBUG) Log.v(TAG, "BOOT_COMPLETED received");
+ unregisterReceiver(this);
+ mBootCompleted = true;
+ if (mServicesStarted) {
+ final int N = mServices.length;
+ for (int i = 0; i < N; i++) {
+ mServices[i].onBootCompleted();
+ }
+ }
+ }
+ }, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
}
/**
@@ -71,6 +94,17 @@ public class SystemUIApplication extends Application {
if (mServicesStarted) {
return;
}
+
+ if (!mBootCompleted) {
+ // check to see if maybe it was already completed long before we began
+ // see ActivityManagerService.finishBooting()
+ if ("1".equals(SystemProperties.get("sys.boot_completed"))) {
+ mBootCompleted = true;
+ if (DEBUG) Log.v(TAG, "BOOT_COMPLETED was already sent");
+ }
+ }
+
+ Log.v(TAG, "Starting SystemUI services.");
final int N = SERVICES.length;
for (int i=0; i<N; i++) {
Class<?> cl = SERVICES[i];
@@ -86,6 +120,10 @@ public class SystemUIApplication extends Application {
mServices[i].mComponents = mComponents;
if (DEBUG) Log.d(TAG, "running: " + mServices[i]);
mServices[i].start();
+
+ if (mBootCompleted) {
+ mServices[i].onBootCompleted();
+ }
}
mServicesStarted = true;
}
diff --git a/packages/SystemUI/src/com/android/systemui/recent/Recents.java b/packages/SystemUI/src/com/android/systemui/recent/Recents.java
index 10b6d49..21c2926 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/Recents.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/Recents.java
@@ -26,6 +26,7 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.os.Bundle;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.util.DisplayMetrics;
@@ -45,6 +46,7 @@ public class Recents extends SystemUI implements RecentsComponent {
// Which recents to use
boolean mUseAlternateRecents;
AlternateRecentsComponent mAlternateRecents;
+ boolean mBootCompleted = false;
@Override
public void start() {
@@ -60,6 +62,11 @@ public class Recents extends SystemUI implements RecentsComponent {
}
@Override
+ protected void onBootCompleted() {
+ mBootCompleted = true;
+ }
+
+ @Override
public void toggleRecents(Display display, int layoutDirection, View statusBarView) {
if (mUseAlternateRecents) {
// Launch the alternate recents if required
@@ -197,13 +204,11 @@ public class Recents extends SystemUI implements RecentsComponent {
Intent intent =
new Intent(RecentsActivity.WINDOW_ANIMATION_START_INTENT);
intent.setPackage("com.android.systemui");
- mContext.sendBroadcastAsUser(intent,
- new UserHandle(UserHandle.USER_CURRENT));
+ sendBroadcastSafely(intent);
}
});
intent.putExtra(RecentsActivity.WAITING_FOR_WINDOW_ANIMATION_PARAM, true);
- mContext.startActivityAsUser(intent, opts.toBundle(), new UserHandle(
- UserHandle.USER_CURRENT));
+ startActivitySafely(intent, opts.toBundle());
}
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Failed to launch RecentAppsIntent", e);
@@ -225,7 +230,7 @@ public class Recents extends SystemUI implements RecentsComponent {
Intent intent = new Intent(RecentsActivity.PRELOAD_INTENT);
intent.setClassName("com.android.systemui",
"com.android.systemui.recent.RecentsPreloadReceiver");
- mContext.sendBroadcastAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
+ sendBroadcastSafely(intent);
RecentTasksLoader.getInstance(mContext).preloadFirstTask();
}
@@ -239,7 +244,7 @@ public class Recents extends SystemUI implements RecentsComponent {
Intent intent = new Intent(RecentsActivity.CANCEL_PRELOAD_INTENT);
intent.setClassName("com.android.systemui",
"com.android.systemui.recent.RecentsPreloadReceiver");
- mContext.sendBroadcastAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
+ sendBroadcastSafely(intent);
RecentTasksLoader.getInstance(mContext).cancelPreloadingFirstTask();
}
@@ -252,9 +257,25 @@ public class Recents extends SystemUI implements RecentsComponent {
} else {
Intent intent = new Intent(RecentsActivity.CLOSE_RECENTS_INTENT);
intent.setPackage("com.android.systemui");
- mContext.sendBroadcastAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
+ sendBroadcastSafely(intent);
RecentTasksLoader.getInstance(mContext).cancelPreloadingFirstTask();
}
}
+
+ /**
+ * Send broadcast only if BOOT_COMPLETED
+ */
+ private void sendBroadcastSafely(Intent intent) {
+ if (!mBootCompleted) return;
+ mContext.sendBroadcastAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
+ }
+
+ /**
+ * Start activity only if BOOT_COMPLETED
+ */
+ private void startActivitySafely(Intent intent, Bundle opts) {
+ if (!mBootCompleted) return;
+ mContext.startActivityAsUser(intent, opts, new UserHandle(UserHandle.USER_CURRENT));
+ }
}