• android 11.0 获取当前界面的APP ,在APP的界面禁止灭屏


    客户要求在升级界面不能灭屏,三方APP 不愿意修改,自己在Framework修改的内容,

    超时的时候,设置不灭屏。

    1. diff --git a/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java b/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
    2. index 8ea3b0b7fa..d20a0cd132 100755
    3. --- a/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
    4. +++ b/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
    5. @@ -117,6 +117,11 @@ import java.util.ArrayList;
    6. import java.util.Arrays;
    7. import java.util.List;
    8. import java.util.Objects;
    9. +import android.app.ActivityThread;
    10. +import android.app.usage.UsageStatsManager;
    11. +import java.util.Calendar;
    12. +import android.app.usage.UsageEvents;
    13. +import android.content.ComponentName;
    14. /**
    15. * The power manager service is responsible for coordinating power management
    16. @@ -1958,6 +1963,24 @@ public final class PowerManagerService extends SystemService
    17. Trace.traceEnd(Trace.TRACE_TAG_POWER);
    18. }
    19. }
    20. + // get current app
    21. + public static String getForegroundPackageName(Context context) {
    22. + Calendar calendar = Calendar.getInstance();
    23. + final long end = calendar.getTimeInMillis();
    24. + calendar.add(Calendar.MONTH, -1);
    25. + final long start = calendar.getTimeInMillis();
    26. + UsageStatsManager usageStatsManager = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
    27. + UsageEvents usageEvents = usageStatsManager.queryEvents(start, end);
    28. + UsageEvents.Event event = new UsageEvents.Event();
    29. + String packageName = null;
    30. + while (usageEvents.hasNextEvent()) {
    31. + usageEvents.getNextEvent(event);
    32. + if (event.getEventType() == UsageEvents.Event.ACTIVITY_RESUMED) {
    33. + packageName = event.getPackageName();
    34. + }
    35. + }
    36. + return packageName;
    37. + }
    38. /**
    39. * Check profile timeouts and notify profiles that should be locked.
    40. @@ -2294,6 +2317,12 @@ public final class PowerManagerService extends SystemService
    41. if (now < nextTimeout) {
    42. mUserActivitySummary = USER_ACTIVITY_SCREEN_DIM;
    43. }
    44. + // com.cw.update
    45. + String packageName2 = getForegroundPackageName(mContext);
    46. + if( "com.cw.update".equals(packageName2)){
    47. + android.util.Log.d(TAG, "if ture ,so Timeout not work com.cw.update.......");
    48. + mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT;
    49. + }
    50. }
    51. }
    52. if (mUserActivitySummary == 0

  • 相关阅读:
    一把王者的时间,我就学会了 Nginx!
    Java中的final和常量以及枚举
    【C++】开启C++学习之路 — 入门篇(1)
    WebGPT VS WebGPU
    Springboot 一行代码实现文件上传 20个平台!少写代码到极致
    纳科星融资逾2亿美元用于电池材料生产
    HttpClientUtils
    【深度学习100例】—— 使用PyTorch实现验证码识别 | 第4例
    较多业步骤场景通用框架
    SCT52240STDR,SCT52240MTER,SCT52240QSTDR,SCT52240QMTER,栅极驱动器
  • 原文地址:https://blog.csdn.net/wed110/article/details/126037249