涉及状态栏、导航栏

SystemBars

  • 涉及文件
    • frameworks/base/packages/SystemUI/src/com/android/systemui/SystemBars.java
    • frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

SystemBars.start()

SystemUI 启动时会调用 SystemBarsstart() 方法来加载状态栏、导航栏等。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
     public void start() {
         createStatusBarFromConfig();
     }

     private void createStatusBarFromConfig() {
    // 默认值:com.android.systemui.statusbar.phone.StatusBar
         final String clsName = mContext.getString(R.string.config_statusBarComponent);
         if (clsName == null || clsName.length() == 0) {
             throw andLog("No status bar component configured", null);
         }
    // 通过反射获取该对象
         Class<?> cls = null;
         try {
             cls = mContext.getClassLoader().loadClass(clsName);
         } catch (Throwable t) {
             throw andLog("Error loading status bar component: " + clsName, t);
         }
         try {
             mStatusBar = (SystemUI) cls.newInstance();
         } catch (Throwable t) {
             throw andLog("Error creating status bar component: " + clsName, t);
         }
// 填充信息并启动  start() 方法
         mStatusBar.mContext = mContext;
         mStatusBar.mComponents = mComponents;
         mStatusBar.start();
     }

config_statusBarComponent 的值有 3 个,默认是 phone 布局;另外两个是 tvcar ;主要是由于屏幕大小及屏幕显示方向不同,而采用不同的布局;其显示流程大致相同,我们这里采用默认的手机布局分析。

StatusBar.start()

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
public void start() {
    mGroupManager = Dependency.get(NotificationGroupManager.class);
    mVisualStabilityManager = Dependency.get(VisualStabilityManager.class);
    mNotificationLogger = Dependency.get(NotificationLogger.class);
    mRemoteInputManager = Dependency.get(NotificationRemoteInputManager.class);
    mNotificationListener =  Dependency.get(NotificationListener.class);
    mGroupManager = Dependency.get(NotificationGroupManager.class);
    mNetworkController = Dependency.get(NetworkController.class);
    mUserSwitcherController = Dependency.get(UserSwitcherController.class);
    mScreenLifecycle = Dependency.get(ScreenLifecycle.class);
    mScreenLifecycle.addObserver(mScreenObserver);
    mWakefulnessLifecycle = Dependency.get(WakefulnessLifecycle.class);
    mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
    mBatteryController = Dependency.get(BatteryController.class);
    mAssistManager = Dependency.get(AssistManager.class);
    mOverlayManager = IOverlayManager.Stub
        .asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE));
    mLockscreenUserManager = Dependency.get(NotificationLockscreenUserManager.class);
    mGutsManager = Dependency.get(NotificationGutsManager.class);
    mMediaManager = Dependency.get(NotificationMediaManager.class);
    mEntryManager = Dependency.get(NotificationEntryManager.class);
    mViewHierarchyManager = Dependency.get(NotificationViewHierarchyManager.class);
    mAppOpsListener = Dependency.get(AppOpsListener.class);
    mAppOpsListener.setUpWithPresenter(this, mEntryManager);
    mZenController = Dependency.get(ZenModeController.class);
    mKeyguardViewMediator = getComponent(KeyguardViewMediator.class);

    mColorExtractor = Dependency.get(SysuiColorExtractor.class);
    mColorExtractor.addOnColorsChangedListener(this);

    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);

    mDisplay = mWindowManager.getDefaultDisplay();
    updateDisplaySize();

    Resources res = mContext.getResources();
    mVibrateOnOpening = mContext.getResources().getBoolean(R.bool.config_vibrateOnIconAnimation);
    mVibratorHelper = Dependency.get(VibratorHelper.class);
    mScrimSrcModeEnabled = res.getBoolean(R.bool.config_status_bar_scrim_behind_use_src);
    mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll);

    DateTimeView.setReceiverHandler(Dependency.get(Dependency.TIME_TICK_HANDLER));
    putComponent(StatusBar.class, this);

    // start old BaseStatusBar.start().
    mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
    mDevicePolicyManager = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);

    mAccessibilityManager = (AccessibilityManager)
        mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);

    mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);

    mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class);

    mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));

    mRecents = getComponent(Recents.class);

    mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
    mLockPatternUtils = new LockPatternUtils(mContext);

    mMediaManager.setUpWithPresenter(this, mEntryManager);

    // Connect in to the status bar manager service
    mCommandQueue = getComponent(CommandQueue.class);
    mCommandQueue.addCallbacks(this);

    int[] switches = new int[9];
    ArrayList<IBinder> binders = new ArrayList<>();
    ArrayList<String> iconSlots = new ArrayList<>();
    ArrayList<StatusBarIcon> icons = new ArrayList<>();
    Rect fullscreenStackBounds = new Rect();
    Rect dockedStackBounds = new Rect();
    try {
        mBarService.registerStatusBar(mCommandQueue, iconSlots, icons, switches, binders,
                                      fullscreenStackBounds, dockedStackBounds);
    } catch (RemoteException ex) {
        // If the system process isn't there we're doomed anyway.
    }

    createAndAddWindows();

    // Make sure we always have the most current wallpaper info.
    IntentFilter wallpaperChangedFilter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
    mContext.registerReceiver(mWallpaperChangedReceiver, wallpaperChangedFilter);
    mWallpaperChangedReceiver.onReceive(mContext, null);

    mLockscreenUserManager.setUpWithPresenter(this, mEntryManager);
    mCommandQueue.disable(switches[0], switches[6], false /* animate */);
    setSystemUiVisibility(switches[1], switches[7], switches[8], 0xffffffff,
                          fullscreenStackBounds, dockedStackBounds);
    topAppWindowChanged(switches[2] != 0);
    // StatusBarManagerService has a back up of IME token and it's restored here.
    setImeWindowStatus(binders.get(0), switches[3], switches[4], switches[5] != 0);

    // Set up the initial icon state
    int N = iconSlots.size();
    for (int i=0; i < N; i++) {
        mCommandQueue.setIcon(iconSlots.get(i), icons.get(i));
    }

    // Set up the initial notification state.
    mNotificationListener.setUpWithPresenter(this, mEntryManager);

    setHeadsUpUser(mLockscreenUserManager.getCurrentUserId());

    IntentFilter internalFilter = new IntentFilter();
    internalFilter.addAction(BANNER_ACTION_CANCEL);
    internalFilter.addAction(BANNER_ACTION_SETUP);
    mContext.registerReceiver(mBannerActionBroadcastReceiver, internalFilter, PERMISSION_SELF,
                              null);

    IVrManager vrManager = IVrManager.Stub.asInterface(ServiceManager.getService(Context.VR_SERVICE));
    try {
        vrManager.registerListener(mVrStateCallbacks);
    } catch (RemoteException e) {
        Slog.e(TAG, "Failed to register VR mode state listener: " + e);
    }

    IWallpaperManager wallpaperManager = IWallpaperManager.Stub
        .asInterface(ServiceManager.getService(Context.WALLPAPER_SERVICE));
    try {
        wallpaperManager.setInAmbientMode(false /* ambientMode */, false /* animated */);
    } catch (RemoteException e) {
        // Just pass, nothing critical.
    }

    // end old BaseStatusBar.start().

    // Lastly, call to the icon policy to install/update all the icons.
    mIconPolicy = new PhoneStatusBarPolicy(mContext, mIconController);
    mSignalPolicy = new StatusBarSignalPolicy(mContext, mIconController);

    mUnlockMethodCache = UnlockMethodCache.getInstance(mContext);
    mUnlockMethodCache.addListener(this);
    startKeyguard();

    KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateCallback);
    putComponent(DozeHost.class, mDozeServiceHost);

    mScreenPinningRequest = new ScreenPinningRequest(mContext);
    mFalsingManager = FalsingManager.getInstance(mContext);

    Dependency.get(ActivityStarterDelegate.class).setActivityStarterImpl(this);

    Dependency.get(ConfigurationController.class).addCallback(this);
}