锁屏界面禁止下拉快捷面板,屏蔽通知消息
实现一个功能,在锁屏界面中屏蔽快捷面板下拉,屏蔽通知消息,基于Android14来讲,网上的博客什么的大部分用不了,很多文件都找不到了,这里将修改文件做个简单记录
1、屏蔽通知
// frameworks\base\services\core\java\com\android\server\notification\NotificationManagerService.java
void enqueueNotificationInternal(final String pkg, final String opPkg, final int callingUid,
final int callingPid, final String tag, final int id, final Notification notification,
int incomingUserId, boolean byForegroundService) {
// add block,添加具体判断逻辑
if(...){
android.util.Log.d("tag","NotificationManagerService#enqueueNotificationInternal block ------");
return;
}
// add block end
enqueueNotificationInternal(pkg, opPkg, callingUid, callingPid, tag, id, notification,
incomingUserId, false /* postSilently */, byForegroundService);
}
void enqueueNotificationInternal(final String pkg, final String opPkg, final int callingUid,
final int callingPid, final String tag, final int id, final Notification notification,
int incomingUserId, boolean postSilently, boolean byForegroundService) {
// add block
if(...){
android.util.Log.d("tag","NotificationManagerService#enqueueNotificationInternal block --------- 222222222");
return;
}
// add block end
PostNotificationTracker tracker = acquireWakeLockForPost(pkg, callingUid);
boolean enqueued = false;
try {
enqueued = enqueueNotificationInternal(pkg, opPkg, callingUid, callingPid, tag, id,
notification, incomingUserId, postSilently, tracker, byForegroundService);
} finally {
if (!enqueued) {
tracker.cancel();
}
}
}
2、屏蔽快捷面板下拉
2.1
// frameworks\base\services\core\java\com\android\server\statusbar\StatusBarManagerService.java
private void enforceExpandStatusBar() {
// add block
if(...){
android.util.Log.d("tag","StatusBarManagerService#enforceExpandStatusBar block ---------");
return;
}
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
"StatusBarManagerService");
}
2.2
//frameworks\base\packages\SystemUI\src\com\android\systemui\shade\QuickSettingsController.java
/** update Qs height state */
public void setExpansionHeight(float height) {
// TODO(b/277909752): remove below log when bug is fixed
if (mSplitShadeEnabled && mShadeExpandedFraction == 1.0f && height == 0) {
Log.wtf(TAG,
"setting QS height to 0 in split shade while shade is open(ing). "
+ "Value of mExpandImmediate = " + mExpandImmediate);
}
// add block
if(...){
android.util.Log.d("tag","QuickSettingsController#setExpansionHeight" block ---------");
return;
}
... ...
}
2.3
// frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\CommandQueue.java
// TODO(b/118592525): add multi-display support if needed.
public boolean panelsEnabled() {
if(...){
android.util.Log.d("tag","CommandQueue#panelsEnabled block ---------");
return false;
}
final int disabled1 = getDisabled1(mDisplayTracker.getDefaultDisplayId());
final int disabled2 = getDisabled2(mDisplayTracker.getDefaultDisplayId());
return (disabled1 & StatusBarManager.DISABLE_EXPAND) == 0
&& (disabled2 & StatusBarManager.DISABLE2_NOTIFICATION_SHADE) == 0;
}
功能可用,后续Android其他版本,可能对应源码有调整,对应的修改位置也就需要做对应修改,这种修改在Android14 源码中有效
本文来自博客园,作者:阿丟啊,转载请注明原文链接:https://www.cnblogs.com/qiyuexiaxun/p/19033187