1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 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 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 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. 13 */ 14 15 package com.android.systemui; 16 17 import android.util.Log; 18 19 import com.android.systemui.statusbar.phone.StatusBar; 20 21 import java.io.FileDescriptor; 22 import java.io.PrintWriter; 23 24 /** 25 * Ensure a single status bar service implementation is running at all times, using the in-process 26 * implementation according to the product config. 27 */ 28 public class SystemBars extends SystemUI { 29 private static final String TAG = "SystemBars"; 30 private static final boolean DEBUG = false; 31 private static final int WAIT_FOR_BARS_TO_DIE = 500; 32 33 // in-process fallback implementation, per the product config 34 private SystemUI mStatusBar; 35 36 @Override start()37 public void start() { 38 if (DEBUG) Log.d(TAG, "start"); 39 createStatusBarFromConfig(); 40 } 41 42 @Override dump(FileDescriptor fd, PrintWriter pw, String[] args)43 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 44 if (mStatusBar != null) { 45 mStatusBar.dump(fd, pw, args); 46 } 47 } 48 createStatusBarFromConfig()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 { 62 mStatusBar = (SystemUI) cls.newInstance(); 63 } catch (Throwable t) { 64 throw andLog("Error creating status bar component: " + clsName, t); 65 } 66 mStatusBar.mContext = mContext; 67 mStatusBar.mComponents = mComponents; 68 if (mStatusBar instanceof StatusBar) { 69 SystemUIFactory.getInstance().getRootComponent() 70 .getStatusBarInjector() 71 .createStatusBar((StatusBar) mStatusBar); 72 } 73 mStatusBar.start(); 74 if (DEBUG) Log.d(TAG, "started " + mStatusBar.getClass().getSimpleName()); 75 } 76 andLog(String msg, Throwable t)77 private RuntimeException andLog(String msg, Throwable t) { 78 Log.w(TAG, msg, t); 79 throw new RuntimeException(msg, t); 80 } 81 } 82