blob: 275fd704271570d30d0713244935bd772edce375 [file] [log] [blame]
John Spurlock5c454122013-06-17 07:35:46 -04001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.statusbar;
18
Daniel Sandler777dcde2013-09-30 10:21:45 -040019import android.content.res.Configuration;
John Spurlock5c454122013-06-17 07:35:46 -040020import android.provider.Settings;
21import android.util.Log;
22
23import com.android.systemui.R;
24import com.android.systemui.SystemUI;
25
John Spurlock0ec64c62013-08-26 15:37:58 -040026import java.io.FileDescriptor;
27import java.io.PrintWriter;
28
John Spurlock5c454122013-06-17 07:35:46 -040029/**
Julia Reynoldsbb983d202017-01-06 09:54:20 -050030 * Ensure a single status bar service implementation is running at all times, using the in-process
31 * implementation according to the product config.
John Spurlock5c454122013-06-17 07:35:46 -040032 */
Julia Reynoldsbb983d202017-01-06 09:54:20 -050033public class SystemBars extends SystemUI {
John Spurlock5c454122013-06-17 07:35:46 -040034 private static final String TAG = "SystemBars";
John Spurlock342cad72013-10-08 09:36:50 -040035 private static final boolean DEBUG = false;
John Spurlock5c454122013-06-17 07:35:46 -040036 private static final int WAIT_FOR_BARS_TO_DIE = 500;
37
John Spurlock5c454122013-06-17 07:35:46 -040038 // in-process fallback implementation, per the product config
39 private BaseStatusBar mStatusBar;
40
41 @Override
42 public void start() {
43 if (DEBUG) Log.d(TAG, "start");
Julia Reynoldsbb983d202017-01-06 09:54:20 -050044 createStatusBarFromConfig();
John Spurlock5c454122013-06-17 07:35:46 -040045 }
46
John Spurlock0ec64c62013-08-26 15:37:58 -040047 @Override
Daniel Sandler777dcde2013-09-30 10:21:45 -040048 protected void onConfigurationChanged(Configuration newConfig) {
49 if (mStatusBar != null) {
50 mStatusBar.onConfigurationChanged(newConfig);
51 }
52 }
53
54 @Override
John Spurlock0ec64c62013-08-26 15:37:58 -040055 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
56 if (mStatusBar != null) {
57 mStatusBar.dump(fd, pw, args);
58 }
59 }
60
John Spurlock5c454122013-06-17 07:35:46 -040061 private void createStatusBarFromConfig() {
62 if (DEBUG) Log.d(TAG, "createStatusBarFromConfig");
63 final String clsName = mContext.getString(R.string.config_statusBarComponent);
64 if (clsName == null || clsName.length() == 0) {
65 throw andLog("No status bar component configured", null);
66 }
67 Class<?> cls = null;
68 try {
69 cls = mContext.getClassLoader().loadClass(clsName);
70 } catch (Throwable t) {
71 throw andLog("Error loading status bar component: " + clsName, t);
72 }
73 try {
74 mStatusBar = (BaseStatusBar) cls.newInstance();
75 } catch (Throwable t) {
76 throw andLog("Error creating status bar component: " + clsName, t);
77 }
78 mStatusBar.mContext = mContext;
John Spurlockd08de372013-06-24 13:06:08 -040079 mStatusBar.mComponents = mComponents;
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}