Loading packages/SystemUI/src/com/android/systemui/BootCompleteCache.kt 0 → 100644 +27 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui interface BootCompleteCache { fun isBootComplete(): Boolean fun addListener(listener: BootCompleteListener): Boolean fun removeListener(listener: BootCompleteListener) interface BootCompleteListener { fun onBootComplete() } } No newline at end of file packages/SystemUI/src/com/android/systemui/BootCompleteCacheImpl.kt 0 → 100644 +116 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui import android.util.Log import com.android.internal.annotations.GuardedBy import java.io.FileDescriptor import java.io.PrintWriter import java.lang.ref.WeakReference import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject import javax.inject.Singleton /** * Caches whether the device has reached [SystemService.PHASE_BOOT_COMPLETED]. * * This class is constructed and set by [SystemUIApplication] and will notify all listeners when * boot is completed. */ @Singleton class BootCompleteCacheImpl @Inject constructor(private val dumpController: DumpController) : BootCompleteCache, Dumpable { companion object { private const val TAG = "BootCompleteCacheImpl" private const val DEBUG = false } init { dumpController.registerDumpable(TAG, this) } @GuardedBy("listeners") private val listeners = mutableListOf<WeakReference<BootCompleteCache.BootCompleteListener>>() private val bootComplete = AtomicBoolean(false) /** * Provides the current boot state of the system as determined by [SystemUIApplication]. * @return `true` if the system has reached [SystemService.PHASE_BOOT_COMPLETED] */ override fun isBootComplete(): Boolean = bootComplete.get() /** * Indicates to this object that boot is complete. Subsequent calls to this function will have * no effect. */ fun setBootComplete() { if (bootComplete.compareAndSet(false, true)) { if (DEBUG) Log.d(TAG, "Boot complete set") synchronized(listeners) { listeners.forEach { it.get()?.onBootComplete() } listeners.clear() } } } /** * Add a listener for boot complete event. It will immediately return the current boot complete * state. If this value is true, [BootCompleteCache.BootCompleteListener.onBootComplete] will * never be called. * * @param listener a listener for boot complete state. * @return `true` if boot has been completed. */ override fun addListener(listener: BootCompleteCache.BootCompleteListener): Boolean { if (bootComplete.get()) return true synchronized(listeners) { if (bootComplete.get()) return true listeners.add(WeakReference(listener)) if (DEBUG) Log.d(TAG, "Adding listener: $listener") return false } } /** * Removes a listener for boot complete event. * * @param listener a listener to removed. */ override fun removeListener(listener: BootCompleteCache.BootCompleteListener) { if (bootComplete.get()) return synchronized(listeners) { listeners.removeIf { it.get() == null || it.get() === listener } if (DEBUG) Log.d(TAG, "Removing listener: $listener") } } override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) { pw.println("BootCompleteCache state:") pw.println(" boot complete: ${isBootComplete()}") if (!isBootComplete()) { pw.println(" listeners:") synchronized(listeners) { listeners.forEach { pw.println(" $it") } } } } } No newline at end of file packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +11 −11 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.util.Log; import android.util.TimingsTraceLog; import com.android.systemui.dagger.ContextComponentHelper; import com.android.systemui.dagger.SystemUIRootComponent; import com.android.systemui.util.NotificationChannels; import java.lang.reflect.Constructor; Loading @@ -47,13 +48,13 @@ public class SystemUIApplication extends Application implements private static final boolean DEBUG = false; private ContextComponentHelper mComponentHelper; private BootCompleteCacheImpl mBootCompleteCache; /** * Hold a reference on the stuff we start. */ private SystemUI[] mServices; private boolean mServicesStarted; private boolean mBootCompleted; private SystemUIAppComponentFactory.ContextAvailableCallback mContextAvailableCallback; public SystemUIApplication() { Loading @@ -71,8 +72,9 @@ public class SystemUIApplication extends Application implements Trace.TRACE_TAG_APP); log.traceBegin("DependencyInjection"); mContextAvailableCallback.onContextAvailable(this); mComponentHelper = SystemUIFactory .getInstance().getRootComponent().getContextComponentHelper(); SystemUIRootComponent root = SystemUIFactory.getInstance().getRootComponent(); mComponentHelper = root.getContextComponentHelper(); mBootCompleteCache = root.provideBootCacheImpl(); log.traceEnd(); // Set the application theme that is inherited by all services. Note that setting the Loading @@ -86,19 +88,17 @@ public class SystemUIApplication extends Application implements registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (mBootCompleted) return; if (mBootCompleteCache.isBootComplete()) return; if (DEBUG) Log.v(TAG, "BOOT_COMPLETED received"); unregisterReceiver(this); mBootCompleted = true; mBootCompleteCache.setBootComplete(); if (mServicesStarted) { final int N = mServices.length; for (int i = 0; i < N; i++) { mServices[i].onBootCompleted(); } } } }, bootCompletedFilter); Loading @@ -107,7 +107,7 @@ public class SystemUIApplication extends Application implements @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) { if (!mBootCompleted) return; if (!mBootCompleteCache.isBootComplete()) return; // Update names of SystemUi notification channels NotificationChannels.createAll(context); } Loading Loading @@ -159,11 +159,11 @@ public class SystemUIApplication extends Application implements } mServices = new SystemUI[services.length]; if (!mBootCompleted) { if (!mBootCompleteCache.isBootComplete()) { // 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; mBootCompleteCache.setBootComplete(); if (DEBUG) { Log.v(TAG, "BOOT_COMPLETED was already sent"); } Loading Loading @@ -205,7 +205,7 @@ public class SystemUIApplication extends Application implements if (ti > 1000) { Log.w(TAG, "Initialization of " + clsName + " took " + ti + " ms"); } if (mBootCompleted) { if (mBootCompleteCache.isBootComplete()) { mServices[i].onBootCompleted(); } } Loading packages/SystemUI/src/com/android/systemui/SystemUIFactory.java +1 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ public class SystemUIFactory { private static final String TAG = "SystemUIFactory"; static SystemUIFactory mFactory; protected SystemUIRootComponent mRootComponent; private SystemUIRootComponent mRootComponent; public static <T extends SystemUIFactory> T getInstance() { return (T) mFactory; Loading packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +7 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.content.Context; import android.content.pm.PackageManager; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.systemui.BootCompleteCache; import com.android.systemui.BootCompleteCacheImpl; import com.android.systemui.DumpController; import com.android.systemui.assist.AssistModule; import com.android.systemui.model.SysUiState; Loading Loading @@ -52,6 +54,10 @@ import dagger.Provides; @Module(includes = {AssistModule.class, PeopleHubModule.class}) public abstract class SystemUIModule { @Binds abstract BootCompleteCache bindBootCompleteCache(BootCompleteCacheImpl bootCompleteCache); /** */ @Binds public abstract ContextComponentHelper bindComponentHelper( Loading Loading @@ -100,4 +106,5 @@ public abstract class SystemUIModule { @Singleton @Binds abstract NotifListBuilder bindNotifListBuilder(NotifListBuilderImpl impl); } Loading
packages/SystemUI/src/com/android/systemui/BootCompleteCache.kt 0 → 100644 +27 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui interface BootCompleteCache { fun isBootComplete(): Boolean fun addListener(listener: BootCompleteListener): Boolean fun removeListener(listener: BootCompleteListener) interface BootCompleteListener { fun onBootComplete() } } No newline at end of file
packages/SystemUI/src/com/android/systemui/BootCompleteCacheImpl.kt 0 → 100644 +116 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui import android.util.Log import com.android.internal.annotations.GuardedBy import java.io.FileDescriptor import java.io.PrintWriter import java.lang.ref.WeakReference import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject import javax.inject.Singleton /** * Caches whether the device has reached [SystemService.PHASE_BOOT_COMPLETED]. * * This class is constructed and set by [SystemUIApplication] and will notify all listeners when * boot is completed. */ @Singleton class BootCompleteCacheImpl @Inject constructor(private val dumpController: DumpController) : BootCompleteCache, Dumpable { companion object { private const val TAG = "BootCompleteCacheImpl" private const val DEBUG = false } init { dumpController.registerDumpable(TAG, this) } @GuardedBy("listeners") private val listeners = mutableListOf<WeakReference<BootCompleteCache.BootCompleteListener>>() private val bootComplete = AtomicBoolean(false) /** * Provides the current boot state of the system as determined by [SystemUIApplication]. * @return `true` if the system has reached [SystemService.PHASE_BOOT_COMPLETED] */ override fun isBootComplete(): Boolean = bootComplete.get() /** * Indicates to this object that boot is complete. Subsequent calls to this function will have * no effect. */ fun setBootComplete() { if (bootComplete.compareAndSet(false, true)) { if (DEBUG) Log.d(TAG, "Boot complete set") synchronized(listeners) { listeners.forEach { it.get()?.onBootComplete() } listeners.clear() } } } /** * Add a listener for boot complete event. It will immediately return the current boot complete * state. If this value is true, [BootCompleteCache.BootCompleteListener.onBootComplete] will * never be called. * * @param listener a listener for boot complete state. * @return `true` if boot has been completed. */ override fun addListener(listener: BootCompleteCache.BootCompleteListener): Boolean { if (bootComplete.get()) return true synchronized(listeners) { if (bootComplete.get()) return true listeners.add(WeakReference(listener)) if (DEBUG) Log.d(TAG, "Adding listener: $listener") return false } } /** * Removes a listener for boot complete event. * * @param listener a listener to removed. */ override fun removeListener(listener: BootCompleteCache.BootCompleteListener) { if (bootComplete.get()) return synchronized(listeners) { listeners.removeIf { it.get() == null || it.get() === listener } if (DEBUG) Log.d(TAG, "Removing listener: $listener") } } override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) { pw.println("BootCompleteCache state:") pw.println(" boot complete: ${isBootComplete()}") if (!isBootComplete()) { pw.println(" listeners:") synchronized(listeners) { listeners.forEach { pw.println(" $it") } } } } } No newline at end of file
packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +11 −11 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.util.Log; import android.util.TimingsTraceLog; import com.android.systemui.dagger.ContextComponentHelper; import com.android.systemui.dagger.SystemUIRootComponent; import com.android.systemui.util.NotificationChannels; import java.lang.reflect.Constructor; Loading @@ -47,13 +48,13 @@ public class SystemUIApplication extends Application implements private static final boolean DEBUG = false; private ContextComponentHelper mComponentHelper; private BootCompleteCacheImpl mBootCompleteCache; /** * Hold a reference on the stuff we start. */ private SystemUI[] mServices; private boolean mServicesStarted; private boolean mBootCompleted; private SystemUIAppComponentFactory.ContextAvailableCallback mContextAvailableCallback; public SystemUIApplication() { Loading @@ -71,8 +72,9 @@ public class SystemUIApplication extends Application implements Trace.TRACE_TAG_APP); log.traceBegin("DependencyInjection"); mContextAvailableCallback.onContextAvailable(this); mComponentHelper = SystemUIFactory .getInstance().getRootComponent().getContextComponentHelper(); SystemUIRootComponent root = SystemUIFactory.getInstance().getRootComponent(); mComponentHelper = root.getContextComponentHelper(); mBootCompleteCache = root.provideBootCacheImpl(); log.traceEnd(); // Set the application theme that is inherited by all services. Note that setting the Loading @@ -86,19 +88,17 @@ public class SystemUIApplication extends Application implements registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (mBootCompleted) return; if (mBootCompleteCache.isBootComplete()) return; if (DEBUG) Log.v(TAG, "BOOT_COMPLETED received"); unregisterReceiver(this); mBootCompleted = true; mBootCompleteCache.setBootComplete(); if (mServicesStarted) { final int N = mServices.length; for (int i = 0; i < N; i++) { mServices[i].onBootCompleted(); } } } }, bootCompletedFilter); Loading @@ -107,7 +107,7 @@ public class SystemUIApplication extends Application implements @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) { if (!mBootCompleted) return; if (!mBootCompleteCache.isBootComplete()) return; // Update names of SystemUi notification channels NotificationChannels.createAll(context); } Loading Loading @@ -159,11 +159,11 @@ public class SystemUIApplication extends Application implements } mServices = new SystemUI[services.length]; if (!mBootCompleted) { if (!mBootCompleteCache.isBootComplete()) { // 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; mBootCompleteCache.setBootComplete(); if (DEBUG) { Log.v(TAG, "BOOT_COMPLETED was already sent"); } Loading Loading @@ -205,7 +205,7 @@ public class SystemUIApplication extends Application implements if (ti > 1000) { Log.w(TAG, "Initialization of " + clsName + " took " + ti + " ms"); } if (mBootCompleted) { if (mBootCompleteCache.isBootComplete()) { mServices[i].onBootCompleted(); } } Loading
packages/SystemUI/src/com/android/systemui/SystemUIFactory.java +1 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ public class SystemUIFactory { private static final String TAG = "SystemUIFactory"; static SystemUIFactory mFactory; protected SystemUIRootComponent mRootComponent; private SystemUIRootComponent mRootComponent; public static <T extends SystemUIFactory> T getInstance() { return (T) mFactory; Loading
packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +7 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.content.Context; import android.content.pm.PackageManager; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.systemui.BootCompleteCache; import com.android.systemui.BootCompleteCacheImpl; import com.android.systemui.DumpController; import com.android.systemui.assist.AssistModule; import com.android.systemui.model.SysUiState; Loading Loading @@ -52,6 +54,10 @@ import dagger.Provides; @Module(includes = {AssistModule.class, PeopleHubModule.class}) public abstract class SystemUIModule { @Binds abstract BootCompleteCache bindBootCompleteCache(BootCompleteCacheImpl bootCompleteCache); /** */ @Binds public abstract ContextComponentHelper bindComponentHelper( Loading Loading @@ -100,4 +106,5 @@ public abstract class SystemUIModule { @Singleton @Binds abstract NotifListBuilder bindNotifListBuilder(NotifListBuilderImpl impl); }