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 | |
Daniel Sandler | 777dcde | 2013-09-30 10:21:45 -0400 | [diff] [blame] | 17 | import android.content.res.Configuration; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 18 | import android.provider.Settings; |
| 19 | import android.util.Log; |
| 20 | |
| 21 | import com.android.systemui.R; |
| 22 | import com.android.systemui.SystemUI; |
| 23 | |
John Spurlock | 0ec64c6 | 2013-08-26 15:37:58 -0400 | [diff] [blame] | 24 | import java.io.FileDescriptor; |
| 25 | import java.io.PrintWriter; |
| 26 | |
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 | * Ensure a single status bar service implementation is running at all times, using the in-process |
| 29 | * implementation according to the product config. |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 30 | */ |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 31 | public class SystemBars extends SystemUI { |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 32 | private static final String TAG = "SystemBars"; |
John Spurlock | 342cad7 | 2013-10-08 09:36:50 -0400 | [diff] [blame] | 33 | private static final boolean DEBUG = false; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 34 | private static final int WAIT_FOR_BARS_TO_DIE = 500; |
| 35 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 36 | // in-process fallback implementation, per the product config |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 37 | private SystemUI mStatusBar; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 38 | |
| 39 | @Override |
| 40 | public void start() { |
| 41 | if (DEBUG) Log.d(TAG, "start"); |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 42 | createStatusBarFromConfig(); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 43 | } |
| 44 | |
John Spurlock | 0ec64c6 | 2013-08-26 15:37:58 -0400 | [diff] [blame] | 45 | @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 Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 52 | 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 Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 65 | mStatusBar = (SystemUI) cls.newInstance(); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 66 | } catch (Throwable t) { |
| 67 | throw andLog("Error creating status bar component: " + clsName, t); |
| 68 | } |
| 69 | mStatusBar.mContext = mContext; |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 70 | mStatusBar.mComponents = mComponents; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 71 | 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 | } |