blob: 4285af08e7340d221b999d839c53072c312adec3 [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
John Spurlock5c454122013-06-17 07:35:46 -040049 private void createStatusBarFromConfig() {
50 if (DEBUG) Log.d(TAG, "createStatusBarFromConfig");
51 final String clsName = mContext.getString(R.string.config_statusBarComponent);
52 if (clsName == null || clsName.length() == 0) {
53 throw andLog("No status bar component configured", null);
54 }
55 Class<?> cls = null;
56 try {
57 cls = mContext.getClassLoader().loadClass(clsName);
58 } catch (Throwable t) {
59 throw andLog("Error loading status bar component: " + clsName, t);
60 }
61 try {
Jason Monk2a6ea9c2017-01-26 11:14:51 -050062 mStatusBar = (SystemUI) cls.newInstance();
John Spurlock5c454122013-06-17 07:35:46 -040063 } catch (Throwable t) {
64 throw andLog("Error creating status bar component: " + clsName, t);
65 }
66 mStatusBar.mContext = mContext;
John Spurlockd08de372013-06-24 13:06:08 -040067 mStatusBar.mComponents = mComponents;
Selim Cinek9d20bed2018-12-26 16:02:34 -080068 if (mStatusBar instanceof StatusBar) {
69 SystemUIFactory.getInstance().getRootComponent()
70 .getStatusBarInjector()
71 .createStatusBar((StatusBar) mStatusBar);
72 }
John Spurlock5c454122013-06-17 07:35:46 -040073 mStatusBar.start();
74 if (DEBUG) Log.d(TAG, "started " + mStatusBar.getClass().getSimpleName());
75 }
76
77 private RuntimeException andLog(String msg, Throwable t) {
78 Log.w(TAG, msg, t);
79 throw new RuntimeException(msg, t);
80 }
81}