当前位置: 首页 > news >正文

Android12 Toast连续多次点击后不显示

开启固定应用功能后,固定某个应用,连续多次点击返回键后不显示如何退出固定模式的提示。

退出固定模式的提示文字

<string name="screen_pinning_toast" msgid="8177286912533744328">"如需取消固定此应用,请轻触并按住“返回”按钮和“概览”按钮"</string>
  • 位置: vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/ScreenPinningNotify.java
	/** Show a toast that describes the gesture the user should use to escape pinned mode. */public void showEscapeToast(boolean isGestureNavEnabled, boolean isRecentsButtonVisible) {long showToastTime = SystemClock.elapsedRealtime();if ((showToastTime - mLastShowToastTime) < SHOW_TOAST_MINIMUM_INTERVAL) {Slog.i(TAG, "Ignore toast since it is requested in very short interval.");return;}if (mLastToast != null) {mLastToast.cancel();}mLastToast = makeAllUserToastAndShow(isGestureNavEnabled? R.string.screen_pinning_toast_gesture_nav: isRecentsButtonVisible? R.string.screen_pinning_toast: R.string.screen_pinning_toast_recents_invisible);mLastShowToastTime = showToastTime;}private Toast makeAllUserToastAndShow(int resId) {Toast toast = SysUIToast.makeText(mContext, resId, Toast.LENGTH_LONG);toast.show();return toast;}

从代码中看就是正常的显示toast,也只有一个1s内点击不响应的限制,不是这里的问题。

抓取log分析有看到toast被丢弃的信息

	NotificationService: Package com.android.systemui is above allowed toast quota, the following toast was blocked and discarded: TextToastRecord{516da7 1237:com.android.systemui/u0a44 isSystemToast=false token=android.os.BinderProxy@83ec254 text=To unpin this app, touch & hold Back and Overview buttons duration=1}
  • 位置:frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
	@GuardedBy("mToastQueue")void showNextToastLocked(boolean lastToastWasTextRecord) {if (mIsCurrentToastShown) {return; // Don't show the same toast twice.}ToastRecord record = mToastQueue.get(0);while (record != null) {int userId = UserHandle.getUserId(record.uid);boolean rateLimitingEnabled =!mToastRateLimitingDisabledUids.contains(record.uid);boolean isWithinQuota =mToastRateLimiter.isWithinQuota(userId, record.pkg, TOAST_QUOTA_TAG)|| isExemptFromRateLimiting(record.pkg, userId);boolean isPackageInForeground = isPackageInForegroundForToast(record.uid);if (tryShowToast(record, rateLimitingEnabled, isWithinQuota, isPackageInForeground)) {scheduleDurationReachedLocked(record, lastToastWasTextRecord);mIsCurrentToastShown = true;if (rateLimitingEnabled && !isPackageInForeground) {mToastRateLimiter.noteEvent(userId, record.pkg, TOAST_QUOTA_TAG);}return;}int index = mToastQueue.indexOf(record);if (index >= 0) {ToastRecord mFailedToast = mToastQueue.remove(index);mWindowManagerInternal.removeWindowToken(mFailedToast.windowToken, false /* removeWindows */,mFailedToast.displayId);scheduleKillTokenTimeout(mFailedToast);}record = (mToastQueue.size() > 0) ? mToastQueue.get(0) : null;}}/** Returns true if it successfully showed the toast. */private boolean tryShowToast(ToastRecord record, boolean rateLimitingEnabled,boolean isWithinQuota, boolean isPackageInForeground) {// 如果同时满足速率限制已启用、应用受利率限制并且不是前台应用,相关toast就会被丢弃掉if (rateLimitingEnabled && !isWithinQuota && !isPackageInForeground) {reportCompatRateLimitingToastsChange(record.uid);Slog.w(TAG, "Package " + record.pkg + " is above allowed toast quota, the "+ "following toast was blocked and discarded: " + record);return false;}if (blockToast(record.uid, record.isSystemToast, record.isAppRendered(),isPackageInForeground)) {Slog.w(TAG, "Blocking custom toast from package " + record.pkg+ " due to package not in the foreground at the time of showing the toast");return false;}return record.show();}// 返回true 不受速率限制private boolean isExemptFromRateLimiting(String pkg, int userId) {boolean isExemptFromRateLimiting = false;try {isExemptFromRateLimiting = mPackageManager.checkPermission(android.Manifest.permission.UNLIMITED_TOASTS, pkg, userId)== PackageManager.PERMISSION_GRANTED;} catch (RemoteException e) {Slog.e(TAG, "Failed to connect with package manager");}return isExemptFromRateLimiting;}

可以看到如果同时满足速率限制已启用、应用受利率限制并且不是前台应用,相关toast就会被丢弃掉。
其中一个条件有判断应用是否不受速率限制isExemptFromRateLimiting,如果当前应用具有android.Manifest.permission.UNLIMITED_TOASTS权限并且已授权就不会被限制。

最终修改就是给SystemUI添加上UNLIMITED_TOASTS的权限,解决问题。


http://www.mrgr.cn/news/13420.html

相关文章:

  • 使用kafka完成数据的实时同步,同步到es中。(使用kafka实现自动上下架 upper、lower)
  • 大白话【8】WindowsServer2016搭建DNS服务
  • python基础(11文件读取)
  • 【mybatis系列】spring是如何整合mybatis将Mapper接口注册为Bean的
  • 数据结构(6.4_2)——最短路径问题_BFS算法
  • 2024了,Neo4j能显示节点图片吗?
  • 【Linux —— POSIX信号量 - 基于环形队列的生产消费模型】
  • 【云原生kubernetes系列之SkyWalking篇】
  • 每天一个数据分析题(五百零五)- 提升方法
  • k8s POD控制器
  • 网络安全威胁2024年中报告
  • 代码随想录 刷题记录-19 动态规划(3)完全背包理论、习题
  • 《教育学报》
  • 界面交互体验测试的工具
  • 【多线程】volatile关键字探究和System.out.println()隐式地插入内存屏障问题
  • 快速搭建和运行Spring Boot项目的简易指南
  • Kafka线上问题优化
  • qemu 跨架构
  • js导出方式及引入方式
  • 深圳保障房、商品房、小产权房子类型对比