结合其他博客的介绍的方法,对android5.1系统源码进行修改实现隐藏底部状态栏、隐藏通知栏、隐藏上方状态栏、永不熄屏等功能。亲测可用
1.隐藏底部状态栏
到android/frameworks/base/policy/src/com/android/internal/policy/impl目录下修改PhoneWindowManager.java文件.
修改方法: 定位到setInitialDisplaySize函数,找到注释
// Height of thenavigation bar when presented horizontally at bottom
将注解下的源代码修改为
mNavigationBarHeightForRotation[mPortraitRotation]=
mNavigationBarHeightForRotation[mUpsideDownRotation]=
//res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
0;
mNavigationBarHeightForRotation[mLandscapeRotation]=
mNavigationBarHeightForRotation[mSeascapeRotation]=
//res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height_landscape);
0;
2.隐藏通知栏
到android/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone目录下打开PhoneStatusBarView.java文件.
找到onTouchEvent()和onInterceptTouchEvent()两个方法,将方法里面的代码注释掉(如下所示),即可实现效果
@Override
public boolean onTouchEvent(MotionEventevent) {
return false;
}
@Override
public booleanonInterceptTouchEvent(MotionEvent event) {
return false;
}
3.隐藏上方的状态栏
到android/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone的目录下打开PhoneStatusBar.java文件.
找到addStatusBarWindow()方法,在方法最后加一行代码mStatusBarView.setVisibility(View.GONE);
变为:
private void addStatusBarWindow() {
makeStatusBarView();
mStatusBarWindowManager = newStatusBarWindowManager(mContext);
mStatusBarWindowManager.add(mStatusBarWindow,getStatusBarHeight());
mStatusBarView.setVisibility(View.GONE);
}
到android/frameworks/base/core/res/res/values目录下,打开dimens.xml文件.修改
4 永不熄屏
到android/frameworks/base/packages/SettingsProvider/res/values目录下,打开defaults.xml文件
修改.
到android/frameworks/base/services/core/java/com/android/server/power目录下,打开PowerManagerService.java文件.修改getScreenOffTimeoutLocked()函数为:
private int getScreenOffTimeoutLocked(intsleepTimeout) {
int nosleep;
int timeout = mScreenOffTimeoutSetting;
if(isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
timeout = Math.min(timeout,mMaximumScreenOffTimeoutFromDeviceAdmin);
}
if(mUserActivityTimeoutOverrideFromWindowManager >= 0) {
timeout = (int)Math.min(timeout,mUserActivityTimeoutOverrideFromWindowManager);
}
if (sleepTimeout >= 0) {
timeout = Math.min(timeout,sleepTimeout);
}
nosleep = mScreenOffTimeoutSetting;
if(nosleep <0)
{
nosleep = mMaximumScreenOffTimeoutFromDeviceAdmin;
return Math.max(nosleep,mMaximumScreenOffTimeoutFromDeviceAdmin);
}
return Math.max(timeout,mMinimumScreenOffTimeoutConfig);
}