blob: b5093b3ce52ae0cb4d729c8a45324ea9bd8f072f [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
Daniel Sandler777dcde2013-09-30 10:21:45 -040017import android.content.res.Configuration;
John Spurlock5c454122013-06-17 07:35:46 -040018import android.provider.Settings;
19import android.util.Log;
20
21import com.android.systemui.R;
22import com.android.systemui.SystemUI;
23
John Spurlock0ec64c62013-08-26 15:37:58 -040024import java.io.FileDescriptor;
25import java.io.PrintWriter;
26
John Spurlock5c454122013-06-17 07:35:46 -040027/**
Julia Reynoldsbb983d202017-01-06 09:54:20 -050028 * Ensure a single status bar service implementation is running at all times, using the in-process
29 * implementation according to the product config.
John Spurlock5c454122013-06-17 07:35:46 -040030 */
Julia Reynoldsbb983d202017-01-06 09:54:20 -050031public class SystemBars extends SystemUI {
John Spurlock5c454122013-06-17 07:35:46 -040032 private static final String TAG = "SystemBars";
John Spurlock342cad72013-10-08 09:36:50 -040033 private static final boolean DEBUG = false;
John Spurlock5c454122013-06-17 07:35:46 -040034 private static final int WAIT_FOR_BARS_TO_DIE = 500;
35
John Spurlock5c454122013-06-17 07:35:46 -040036 // in-process fallback implementation, per the product config
Jason Monk2a6ea9c2017-01-26 11:14:51 -050037 private SystemUI mStatusBar;
John Spurlock5c454122013-06-17 07:35:46 -040038
39 @Override
40 public void start() {
41 if (DEBUG) Log.d(TAG, "start");
Julia Reynoldsbb983d202017-01-06 09:54:20 -050042 createStatusBarFromConfig();
John Spurlock5c454122013-06-17 07:35:46 -040043 }
44
John Spurlock0ec64c62013-08-26 15:37:58 -040045 @Override
46 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
47 if (mStatusBar != null) {
48 mStatusBar.dump(fd, pw, args);
49 }
50 }
51
John Spurlock5c454122013-06-17 07:35:46 -040052 private void createStatusBarFromConfig() {
53 if (DEBUG) Log.d(TAG, "createStatusBarFromConfig");
54 final String clsName = mContext.getString(R.string.config_statusBarComponent);
55 if (clsName == null || clsName.length() == 0) {
56 throw andLog("No status bar component configured", null);
57 }
58 Class<?> cls = null;
59 try {
60 cls = mContext.getClassLoader().loadClass(clsName);
61 } catch (Throwable t) {
62 throw andLog("Error loading status bar component: " + clsName, t);
63 }
64 try {
Jason Monk2a6ea9c2017-01-26 11:14:51 -050065 mStatusBar = (SystemUI) cls.newInstance();
John Spurlock5c454122013-06-17 07:35:46 -040066 } catch (Throwable t) {
67 throw andLog("Error creating status bar component: " + clsName, t);
68 }
69 mStatusBar.mContext = mContext;
John Spurlockd08de372013-06-24 13:06:08 -040070 mStatusBar.mComponents = mComponents;
John Spurlock5c454122013-06-17 07:35:46 -040071 mStatusBar.start();
72 if (DEBUG) Log.d(TAG, "started " + mStatusBar.getClass().getSimpleName());
73 }
74
75 private RuntimeException andLog(String msg, Throwable t) {
76 Log.w(TAG, msg, t);
77 throw new RuntimeException(msg, t);
78 }
79}