openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.18k stars 1.35k forks source link

app_current()方法在android13以上版本的适配问题 #952

Open Zeros2619 opened 3 months ago

Zeros2619 commented 3 months ago

只在android13和android14中进行了测试,app_current()目前提供的三条指令测试结果如下

adb shell dumpsys window windows 返回结果的格式可能已经修改了,找不到mCurrentFocus=Window关键字了,Window #\d+ Window可能适用 相关格式如下

    ....
  Window #25 Window{c838dbe u0 tv.danmaku.bili/tv.danmaku.bili.MainActivityV2}:
    mDisplayId=0 rootTaskId=57 mSession=Session{8e5857d 8821:u0a10178} mClient=android.os.BinderProxy@1c9fc79
    mOwnerUid=10178 showForAllUsers=false package=tv.danmaku.bili appop=NONE
    mAttrs={(0,0)(fillxfill) sim={adjust=nothing forwardNavigation} ty=BASE_APPLICATION wanim=0x10302fd
      fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
      pfl=NO_MOVE_ANIMATION FORCE_DRAW_STATUS_BAR_BACKGROUND USE_BLAST FIT_INSETS_CONTROLLED
      vsysui=LAYOUT_STABLE LAYOUT_FULLSCREEN LIGHT_STATUS_BAR LIGHT_NAVIGATION_BAR
      apr=LIGHT_STATUS_BARS LIGHT_NAVIGATION_BARS
      bhv=DEFAULT
      fitSides=}
    Requested w=1440 h=3200 mLayoutSeq=471
    mBaseLayer=21000 mSubLayer=0    mToken=ActivityRecord{d9b8281 u0 tv.danmaku.bili/.MainActivityV2} t57}
    mActivityRecord=ActivityRecord{d9b8281 u0 tv.danmaku.bili/.MainActivityV2} t57}
    mAppDied=false    drawnStateEvaluated=true    mightAffectAllDrawn=true
    mViewVisibility=0x8 mHaveFrame=true mObscured=false
    mGivenContentInsets=[0,0][0,0] mGivenVisibleInsets=[0,0][0,0]
    ....

adb shell dumpsys activity activities 返回结果的格式可能已经修改了,找不到mResumedActivity: ActivityRecord关键字了,mLastPausedActivity: ActivityRecord可能适用 相关格式如下

    ....
  * Task{4949d17 #68 type=standard A=10187:com.ss.android.article.lite U=0 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1}
    mLastPausedActivity: ActivityRecord{1de5aed u0 com.ss.android.article.lite/.activity.SplashActivity} t68}
    mLastNonFullscreenBounds=Rect(386, 932 - 1055, 2372)
    isSleeping=false
    * Hist  #0: ActivityRecord{1de5aed u0 com.ss.android.article.lite/.activity.SplashActivity} t68}
      packageName=com.ss.android.article.lite processName=com.ss.android.article.lite
      launchedFromUid=10148 launchedFromPackage=com.skyui.launcher launchedFromFeature=null userId=0
      app=ProcessRecord{61522ff 12268:com.ss.android.article.lite/u0a187}
      Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.ss.android.article.lite/.activity.SplashActivity bnds=[728,1350][1043,1710] }
      rootOfTask=true task=Task{4949d17 #68 type=standard A=10187:com.ss.android.article.lite}
      taskAffinity=10187:com.ss.android.article.lite
      mActivityComponent=com.ss.android.article.lite/.activity.SplashActivity
      baseDir=/data/app/~~2lWWkwjGqfrOXGlF4jyHAA==/com.ss.android.article.lite-vNQX-8D8RhknWjdu_Kmx6Q==/base.apk
      dataDir=/data/user/0/com.ss.android.article.lite
    ....

adb shell dumpsys activity top 在android13中正常, 在android14中如果后台存在较多应用,将会出现 SERVICE 'activity' DUMP TIMEOUT (10000ms) EXPIRED ,超时的原因导致最终找到的ACTIVITY也不是当前前台的应用

adb shell dumpsys window 是否可以加上去,提高适配性

android13
adb shell dumpsys window | findstr mCurrentFocus
  mCurrentFocus=Window{4397ca7 u0 com.ss.android.article.lite/com.ss.android.article.lite.activity.SplashActivity}

android14
adb shell dumpsys window | findstr mCurrentFocus
  mCurrentFocus=null
  mCurrentFocus=Window{30d1a54 u0 com.android.settings/com.android.settings.Settings}
codeskyblue commented 3 months ago

可以pr提到 adbutils中的shell.py里面