Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3be4506 authored by Dan Sandler's avatar Dan Sandler Committed by Android (Google) Code Review
Browse files

Merge "Avoid sending broadcasts before BOOT_COMPLETED."

parents f74de0b6 dc5f16bf
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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);
+38 −0
Original line number Diff line number Diff line
@@ -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;
    }
+28 −7
Original line number Diff line number Diff line
@@ -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() {
@@ -59,6 +61,11 @@ public class Recents extends SystemUI implements RecentsComponent {
        putComponent(RecentsComponent.class, this);
    }

    @Override
    protected void onBootCompleted() {
        mBootCompleted = true;
    }

    @Override
    public void toggleRecents(Display display, int layoutDirection, View statusBarView) {
        if (mUseAlternateRecents) {
@@ -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));
    }
}