blob: c4c0fd6da1241cb13d565fd0d1882b4061b49e0a [file] [log] [blame]
John Spurlock5c454122013-06-17 07:35:46 -04001/*
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002 * Copyright (C) 2017 The Android Open Source Project
John Spurlock5c454122013-06-17 07:35:46 -04003 *
Jason Monk2a6ea9c2017-01-26 11:14:51 -05004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
John Spurlock5c454122013-06-17 07:35:46 -04006 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
Jason Monk2a6ea9c2017-01-26 11:14:51 -05009 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
John Spurlock5c454122013-06-17 07:35:46 -040013 */
14
Jason Monk2a6ea9c2017-01-26 11:14:51 -050015package com.android.systemui;
John Spurlock5c454122013-06-17 07:35:46 -040016
John Spurlock5c454122013-06-17 07:35:46 -040017import android.util.Log;
18
Selim Cinek9d20bed2018-12-26 16:02:34 -080019import com.android.systemui.statusbar.phone.StatusBar;
20
John Spurlock0ec64c62013-08-26 15:37:58 -040021import java.io.FileDescriptor;
22import java.io.PrintWriter;
23
John Spurlock5c454122013-06-17 07:35:46 -040024/**
Julia Reynoldsbb983d202017-01-06 09:54:20 -050025 * Ensure a single status bar service implementation is running at all times, using the in-process
26 * implementation according to the product config.
John Spurlock5c454122013-06-17 07:35:46 -040027 */
Julia Reynoldsbb983d202017-01-06 09:54:20 -050028public class SystemBars extends SystemUI {
John Spurlock5c454122013-06-17 07:35:46 -040029 private static final String TAG = "SystemBars";
John Spurlock342cad72013-10-08 09:36:50 -040030 private static final boolean DEBUG = false;
John Spurlock5c454122013-06-17 07:35:46 -040031 private static final int WAIT_FOR_BARS_TO_DIE = 500;
32
John Spurlock5c454122013-06-17 07:35:46 -040033 // in-process fallback implementation, per the product config
Jason Monk2a6ea9c2017-01-26 11:14:51 -050034 private SystemUI mStatusBar;
John Spurlock5c454122013-06-17 07:35:46 -040035
36 @Override
37 public void start() {
38 if (DEBUG) Log.d(TAG, "start");
Julia Reynoldsbb983d202017-01-06 09:54:20 -050039 createStatusBarFromConfig();
John Spurlock5c454122013-06-17 07:35:46 -040040 }
41
John Spurlock0ec64c62013-08-26 15:37:58 -040042 @Override
43 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
44 if (mStatusBar != null) {
45 mStatusBar.dump(fd, pw, args);
46 }
47 }
48
yoshiki iguchif5ff4c62019-02-26 14:00:40 +090049 @Override
50 public void onBootCompleted() {
51 if (mStatusBar != null) {
52 mStatusBar.onBootCompleted();
53 }
54 }
55
John Spurlock5c454122013-06-17 07:35:46 -040056 private void createStatusBarFromConfig() {
57 if (DEBUG) Log.d(TAG, "createStatusBarFromConfig");
58 final String clsName = mContext.getString(R.string.config_statusBarComponent);
59 if (clsName == null || clsName.length() == 0) {
60 throw andLog("No status bar component configured", null);
61 }
62 Class<?> cls = null;
63 try {
64 cls = mContext.getClassLoader().loadClass(clsName);
65 } catch (Throwable t) {
66 throw andLog("Error loading status bar component: " + clsName, t);
67 }
68 try {
Jason Monk2a6ea9c2017-01-26 11:14:51 -050069 mStatusBar = (SystemUI) cls.newInstance();
John Spurlock5c454122013-06-17 07:35:46 -040070 } catch (Throwable t) {
71 throw andLog("Error creating status bar component: " + clsName, t);
72 }
73 mStatusBar.mContext = mContext;
John Spurlockd08de372013-06-24 13:06:08 -040074 mStatusBar.mComponents = mComponents;
Selim Cinek9d20bed2018-12-26 16:02:34 -080075 if (mStatusBar instanceof StatusBar) {
76 SystemUIFactory.getInstance().getRootComponent()
77 .getStatusBarInjector()
78 .createStatusBar((StatusBar) mStatusBar);
79 }
John Spurlock5c454122013-06-17 07:35:46 -040080 mStatusBar.start();
81 if (DEBUG) Log.d(TAG, "started " + mStatusBar.getClass().getSimpleName());
82 }
83
84 private RuntimeException andLog(String msg, Throwable t) {
85 Log.w(TAG, msg, t);
86 throw new RuntimeException(msg, t);
87 }
88}