John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Daniel Sandler | 777dcde | 2013-09-30 10:21:45 -0400 | [diff] [blame] | 19 | import android.content.res.Configuration; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 20 | import android.provider.Settings; |
| 21 | import android.util.Log; |
| 22 | |
| 23 | import com.android.systemui.R; |
| 24 | import com.android.systemui.SystemUI; |
| 25 | |
John Spurlock | 0ec64c6 | 2013-08-26 15:37:58 -0400 | [diff] [blame] | 26 | import java.io.FileDescriptor; |
| 27 | import java.io.PrintWriter; |
| 28 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 29 | /** |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 30 | * Ensure a single status bar service implementation is running at all times, using the in-process |
| 31 | * implementation according to the product config. |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 32 | */ |
Julia Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 33 | public class SystemBars extends SystemUI { |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 34 | private static final String TAG = "SystemBars"; |
John Spurlock | 342cad7 | 2013-10-08 09:36:50 -0400 | [diff] [blame] | 35 | private static final boolean DEBUG = false; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 36 | private static final int WAIT_FOR_BARS_TO_DIE = 500; |
| 37 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 38 | // 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 Reynolds | bb983d20 | 2017-01-06 09:54:20 -0500 | [diff] [blame] | 44 | createStatusBarFromConfig(); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 45 | } |
| 46 | |
John Spurlock | 0ec64c6 | 2013-08-26 15:37:58 -0400 | [diff] [blame] | 47 | @Override |
Daniel Sandler | 777dcde | 2013-09-30 10:21:45 -0400 | [diff] [blame] | 48 | protected void onConfigurationChanged(Configuration newConfig) { |
| 49 | if (mStatusBar != null) { |
| 50 | mStatusBar.onConfigurationChanged(newConfig); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | @Override |
John Spurlock | 0ec64c6 | 2013-08-26 15:37:58 -0400 | [diff] [blame] | 55 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 56 | if (mStatusBar != null) { |
| 57 | mStatusBar.dump(fd, pw, args); |
| 58 | } |
| 59 | } |
| 60 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 61 | 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 Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 79 | mStatusBar.mComponents = mComponents; |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 80 | 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 | } |