[置顶] 屏蔽Android4.0.3状态栏

Android4.0 状态栏启动

android4.0系统可以运行于平板电脑和手机上面,这样对于状态栏来说,也是有不同风格的,从SystemUi的代码分类我就可以看出来,google考虑了不同情况下状态栏的显示等,

在源代码里面有这么两个文件夹需要注意:

com.android.systemui.statusbar.phone  这个是针对手机而需要的status bar

com.android.systemui.statusbar.tablet   这个是针对平板电脑而需要的status barsystem bar

首先状态栏是如何启动起来的呢?

我们都知道系统刚启动,在SystemServer会加载系统的各种服务,状态栏也不例外,就是在这个时候创建的,代码如下:

路径:androidx86/framework/base/services/java/com/android/server/SystemServer.java

 

 

SystemServer.java

 ActivityManagerService.self().systemReady(new Runnable() {
            public void run() {
                Slog.i(TAG, "Making services ready");

                startSystemUi(contextF);
                try {
                    if (batteryF != null) batteryF.systemReady();
                } catch (Throwable e) {
                    reportWtf("making Battery Service ready", e);
                }

 

static final void startSystemUi(Context context) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName("com.android.systemui",
                    "com.android.systemui.SystemUIService"));
        Slog.d(TAG, "Starting service: " + intent);
        context.startService(intent);
    }

 

通过上面的代码我就看到系统启动了com.android.systemui.SystemUIService 这个服务,在这个服务里面就会启动状态栏,

但是这里就会有个选择,是启动status bar 还是启动 system bar呢,android是这么决定的:

路径:androidx86/framework/base/packages/SystemUI/SystemUI.java

public void onCreate() {
        // Pick status bar or system bar.
        IWindowManager wm = IWindowManager.Stub.asInterface(
                ServiceManager.getService(Context.WINDOW_SERVICE));
        try {
           
SERVICES[0] = wm.canStatusBarHide()  1
                    ? R.string.config_statusBarComponent
2
                    : R.string.config_systemBarComponent;
3
        } catch (RemoteException e) {
            Slog.w(TAG, "Failing checking whether status bar can hide", e);
        }

        final int N = SERVICES.length;
        mServices = new SystemUI[N];
        for (int i=0; i<N; i++) {
            Class cl = chooseClass(SERVICES[i]);
            Slog.d(TAG, "loading: " + cl);
            try {
                mServices[i] = (SystemUI)cl.newInstance();
            } catch (IllegalAccessException ex) {
                throw new RuntimeException(ex);
            } catch (InstantiationException ex) {
                throw new RuntimeException(ex);
            }
            mServices[i].mContext = this;
            Slog.d(TAG, "running: " + mServices[i]);
           
mServices[i].start();
        }
    }

 

start方法在androidx86/framework/base/packages/SystemUI/statusbar/StatusBar.java

start方法里面就会创建状态栏那些界面对应的各种view,包括下拉状态栏后的view等,把这些view都创建好以后,就把这个view加载windowmanager里面就可以了,这样状态栏就可以显示出来了,代码如下:

final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                height,
               
WindowManager.LayoutParams.TYPE_STATUS_BAR,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
                PixelFormat.OPAQUE);
       
        // the status bar should be in an overlay if possible
        final Display defaultDisplay
            = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        if (ActivityManager.isHighEndGfx(defaultDisplay)) {
            lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
        }

        lp.gravity = getStatusBarGravity();
        lp.setTitle("StatusBar");
        lp.packageName = mContext.getPackageName();
        lp.windowAnimations = R.style.Animation_StatusBar;
      
  WindowManagerImpl.getDefault().addView(sb, lp);  //这里的sb就是状态栏view

因为我们要屏蔽状态栏,所以也就把这句话屏蔽了就可以了。

OK!!!问题解决!

你可能感兴趣的:(android,Google,service,System,Class,手机)