John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 1 | /* |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 3 | * |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 4 | * 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 Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 9 | * 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 Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 13 | */ |
| 14 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 15 | package com.android.systemui; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 16 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 17 | import android.util.Log; |
| 18 | |
Selim Cinek | 9d20bed | 2018-12-26 16:02:34 -0800 | [diff] [blame] | 19 | import com.android.systemui.statusbar.phone.StatusBar; |
| 20 | |
John Spurlock | 0ec64c6 | 2013-08-26 15:37:58 -0400 | [diff] [blame] | 21 | import java.io.FileDescriptor; |
| 22 | import java.io.PrintWriter; |
| 23 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 24 | /** |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 25 | * Ensure a single status bar service implementation is running at all times, using the in-process |
| 26 | * implementation according to the product config. |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 27 | */ |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 28 | public class SystemBars extends SystemUI { |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 29 | private static final String TAG = "SystemBars"; |
John Spurlock | 342cad7 | 2013-10-08 09:36:50 -0400 | [diff] [blame] | 30 | private static final boolean DEBUG = false; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 31 | private static final int WAIT_FOR_BARS_TO_DIE = 500; |
| 32 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 33 | // in-process fallback implementation, per the product config |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 34 | private SystemUI mStatusBar; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 35 | |
| 36 | @Override |
| 37 | public void start() { |
| 38 | if (DEBUG) Log.d(TAG, "start"); |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 39 | createStatusBarFromConfig(); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 40 | } |
| 41 | |
John Spurlock | 0ec64c6 | 2013-08-26 15:37:58 -0400 | [diff] [blame] | 42 | @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 Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 49 | 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 Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 62 | mStatusBar = (SystemUI) cls.newInstance(); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 63 | } catch (Throwable t) { |
| 64 | throw andLog("Error creating status bar component: " + clsName, t); |
| 65 | } |
| 66 | mStatusBar.mContext = mContext; |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 67 | mStatusBar.mComponents = mComponents; |
Selim Cinek | 9d20bed | 2018-12-26 16:02:34 -0800 | [diff] [blame] | 68 | if (mStatusBar instanceof StatusBar) { |
| 69 | SystemUIFactory.getInstance().getRootComponent() |
| 70 | .getStatusBarInjector() |
| 71 | .createStatusBar((StatusBar) mStatusBar); |
| 72 | } |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 73 | 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 | } |