Nice programing

USB 디버깅 중에 화면을 잠금 해제 상태로 유지하려면 어떻게합니까?

nicepro 2020. 12. 8. 19:59
반응형

USB 디버깅 중에 화면을 잠금 해제 상태로 유지하려면 어떻게합니까?


Android OS2.2에는 USB 디버깅 중에 화면 잠금을 비활성화하는 설정 / 애플리케이션 / 개발 옵션이있었습니다. Samsung Galaxy S를 OS2.3.3으로 업그레이드 한 후이 옵션이 사라지고 디버깅하는 동안 휴대 전화 잠금을 계속 해제하는 것이 매우 실망 스럽습니다.

이 옵션이 이동되었거나 다른 방법이 있습니까? (유용한 옵션이 이유없이 제거되는 것이 싫습니다!)

미리 감사드립니다 ...


여러 가지 옵션이 있으며 그 중 대부분은 끔찍한 (주관적) 부작용이 있습니다. 내가 발견 한 것과 내가 생각할 수있는 부작용을 나열하겠습니다.

나는 다른 많은 사람들과 마찬가지로 게으르고 불필요하게 무언가를 주시하는 것을 좋아하지 않습니다. 즉, "오, 작업하는 동안이 기능을 켜고 완료되면 끄겠습니다."옵션이 실행 가능한 옵션이 아님을 의미합니다. 당신 그것을 잊어 버리고 결국 아래 나열된 부작용을 경험 하게 될 것 입니다.

TL; DR

FLAG_KEEP_SCREEN_ONDebug.isDebuggerConnected()가드 FTW 와 함께 ! 충전시 깨어있어 , 화면 시간 제한웨이크 잠금 방금 디버깅 할 경우 비 실행 가능한 옵션입니다.
API 1 및 Wi-Fi 디버깅에서 작동하는이 솔루션의 장점도 있습니다!

설정> 개발자 옵션> 충전시 깨어 있음

번인 :이 기능을 켜는 사람에게는 큰 위험 신호가있을 것입니다. "디버깅 중"이 아니라 "충전 중"이라고 표시됩니다. 즉, 전화기가 전원에 연결되어 있어도 계속 켜져 있습니다. 물건을 태우는 AMOLED 화면 (예 : Galaxy S 시리즈)을 사용하는 경우 특히 나쁩니다.이 옵션을 몇 주 동안 켜두 었는데 이제 영구적 인 초상화 상태 표시 줄이 생겼습니다.

알림 : 낮은 밝기를 사용하고 휴대 전화를 내려 놓을 때마다 화면을 끄는 것을 잊지 않아도 일부 앱은 연결되어있는 동안 대부분의 시간을 유지하도록하는 간단한 알림 만 받으면 화면을 깨 웁니다. 에.

보안 : 충전하는 동안 화면을 켜두고 직장에서 무언가를 빨리해야하는 경우 첫 번째는 "아, 휴대 전화 먼저 잠 그게 해 줘"가 아니라 실수로 떠난 경우 더러운 비밀을 노출 할 수 있습니다. 에. 동료들을 믿을 수없는 환경에서 일하고 있다면 그 고용을 재고 할 것입니다.

설정> 디스플레이> 화면 시간 초과

알림을 제공하는 앱이 많은 경우 매우 위험합니다. 특히 스팸 발송자가있는 경우 (Facebook, Family Guy 또는 메일을 많이받는 경우 GMail).

번인 : 이것도 위험이 높습니다. 이제 "연결 중"으로 제한하지 않으므로 명시 적으로 끄거나 알림을받는 것을 잊을 때마다 계속 켜져 있습니다.

배터리 소모 : 하나를 받으면 지정된 시간 동안 화면이 켜지고 배터리가 소모됩니다. 때로는 끄는 것을 잊거나 알림을 받기 때문에 켜집니다.

핫 포켓 : 휴대 전화가 주머니에있는 동안 알림을 받으면 화면과 밀폐 된 공간의 조명이 주머니를 가열하고 화상을 입을 수도 있습니다.

포켓 다이얼 : 휴대 전화가 주머니에있는 동안 화면이 켜지면 1 초마다 포켓 다이얼이 증가 할 위험이 있습니다. 요즘에는 전화 앱이 일반적으로 잘 숨겨져 있기 때문에 가능성이 적지 만 주머니는 날짜를 자주 변경하거나 이메일을 읽는 것을 좋아합니다.

보안 : 당신이 공공 장소에 있고 당신의 전화가 탁자 위에 있다고 상상 해보면, 당신이 누군가와 대화를하거나 잠깐 휴식을 취할 수있을만큼 충분히 오랫동안 돌아 서면 친구들이 잠금 해제 된 화면을 남용 할 가능성이 높습니다. 특히 그들이 술에 취한 경우. 시간 초과가 짧을수록 이러한 위험이 감소합니다.

wake-lock 사용

권한 : android.permission.WAKE_LOCK앱에 불필요한 권한을 추가해야합니다 (다행히도 Gradle 플러그인의 Manifest Merger 덕분에 디버그 변형에만 쉽게 추가 할 수 있습니다).

코딩 : 잠금 해제를 직접 관리해야하며이를 위해 서비스를 만들어야 할 수도 있습니다. 아직 Android에서이 기능을 사용하지 않았다는 점에 유의하고 싶습니다.

쓸모없는 : 또한 CPU를 깨어있게 유지하기 때문에 화면을 유지하는 데 실제로 도움이되지 않습니다. 설명서를 참조하십시오 .

FLAG_KEEP_SCREEN_ON 디버거가 연결된 동안

이것에 대한 문서읽으면 문제에 매우 가까운 근사치를 찾을 수 있습니다.

코딩 : 제가 생각할 수있는 단점은 일부 코드를 수정해야한다는 것입니다.하지만 매우 간단합니다 ( BaseActivity다른 모든 활동이 확장 된다고 가정하면 ).

@Override protected void onResume() {
    super.onResume();
    if (BuildConfig.DEBUG) { // don't even consider it otherwise
        if (Debug.isDebuggerConnected()) {
            Log.d("SCREEN", "Keeping screen on for debugging, detach debugger and force an onResume to turn it off.");
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        } else {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            Log.d("SCREEN", "Keeping screen on for debugging is now deactivated.");
        }
    }
}

이를 사용하려면 디버거를 연결 한 다음 앱을 종료 (홈 / 작업 버튼 또는 화면 끄기) 한 다음 다시 돌아와 onResume.

일반적으로 디버깅하는 항목에 따라 위의 내용을 입력하여 onCreate더 일찍 등록하고 .NET 이전에 활동 수명주기를 디버깅하는 동안 화면을 깨어있게 유지하는 것이 좋습니다 onResume.

일반적으로 코드를 시도 할 때 Run대신 사용 Debug하고 무언가를 찾은 경우에만 디버거를 연결하는 것이 좋습니다. 이렇게하면 앱이 10 배 더 빨라지고이 옵션이 가장 좋습니다.


일부 기기에서는 작동하지 않는 것 같지만 adb 셸에서 시도해보세요.

svc power stayon usb

Android 버전 2.3.6 이하 settings-> applications-> development충전을 위해 연결되어있는 동안 깨어있는 옵션이 있습니다 (예 : 화면이 잠들지 않음).


Jorge Cevallos가 옳습니다.

Android 4 이상 :

  1. 설정> 휴대 전화 정보로 이동합니다.
  2. "빌드 번호"를 여러 번 (약 10 회) 터치합니다.
  3. 그런 다음 Sttings 메뉴로 돌아 가면 "개발자 옵션"을 찾을 수 있습니다.
  4. "개발자 옵션"아래에 "깨어있는 상태 유지 옵션"이 표시됩니다.

즐기세요.


이 목적으로 만들었습니다 . Google Play "Keep Awake for Debugging"에서 검색 할 수 있습니다. ADB 디버깅을 활성화 한 경우 에만 휴대 전화 잠금 해제 / 화면 켜짐 상태를 유지합니다 . USB에만 국한되지 않고 Wi-Fi에서도 작동합니다.


콘솔에서

 while true; do adb shell input keyevent mouse ; sleep 1 ; done

나는 sampe 문제가 있었다. 전화가 연결되어있을 때 화면을 잠금 해제 상태로 유지하기 위해이 앱을 찾았습니다.

https://play.google.com/store/apps/details?id=com.gmail.developer.runks.enji


단순한. 활동에 다음 코드를 추가하기 만하면 디버그 할 때만 화면이 켜집니다.

@Override
protected void onResume()
{
    Log.d( tag, "onResume()" );
    try
    {
        super.onResume();
        if( BuildConfig.DEBUG && Debug.isDebuggerConnected() )
        {
            Log.d("SCREEN", "Keeping screen on for debugging, detach debugger and force an onResume to turn it off.");
            getWindow().addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                                  WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                                  WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                                  WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                                  WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON );
        }
        else
        {
            getWindow().clearFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                                    WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                                    WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                                    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                                    WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON );
            Log.d( "SCREEN", "Keeping screen on for debugging is now deactivated.");
        }

    }
    catch( Throwable t )
    {
        Log.e( tag, "onResume() - Exception: " + t.getMessage(), t );
    }
}

12345를 잠금 해제 코드로 바꿉니다. 그런 다음이 쉘 스크립트는 휴대 전화를 잠금 해제합니다.

adb shell input keyevent KEYCODE_WAKEUP # activate 
adb shell input touchscreen swipe 530 1420 530 1120 # swipe up
adb shell input text 12345 # input password
adb shell input keyevent 66 # press enter

You should never disable security features on your phone (as pointed out above). Make sure nobody can read that script file either.


# find out if screen is on works on android 5.0+
screenOn=`adb shell dumpsys power | grep "Display Power" | grep ON`
if [ -z "$screenOn" ]; then
    echo "turning screen on"
    adb shell input keyevent KEYCODE_POWER
    # unlock by emulating slide up
    adb shell input touchscreen swipe 930 880 930 380
fi

Tell PowerManager to keep the screen on (it will still dim):

adb shell settings put global stay_on_while_plugged_in 3

The value 3 is the following two types OR'd together:

BatteryManager#BATTERY_PLUGGED_AC and BatteryManager#BATTERY_PLUGGED_USB.

Use adb shell dumpsys power | grep mStayOnWhilePluggedInSetting to see the current value.

To revert to normal behavior set the value to zero like so:

adb shell settings put global stay_on_while_plugged_in 0

Verified working on Android 4.4 through 9.0.


Improving best answer:

Debug.isDebuggerConnected() is not enough if you are not debugging right now, but still working with an app while device is connected via ADB to Android studio. Then we have to add ADB Enabled check.

Settings.Global.getInt(contentResolver, Settings.Global.ADB_ENABLED, 0) == 1 where 1 is when ADB is enabled

@Override protected void onResume() {
    super.onResume();
    if (BuildConfig.DEBUG) { // don't even consider it otherwise
        if (Debug.isDebuggerConnected() ||
            Settings.Global.getInt(getContentResolver(), Settings.Global.ADB_ENABLED, 0) == 1) {
            Log.d("SCREEN", "Keeping screen on for debugging, detach debugger and force an onResume to turn it off.");
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        } else {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            Log.d("SCREEN", "Keeping screen on for debugging is now deactivated.");
        }
    }
}

You can just set the Screen Timeout to 30 minutes or turn it off. This option is under : Settings/Display/Screen Timeout

Hope it helps.


Two options come into my mind:

  1. write an app which will force screen timeout to be very high. Use SCREEN_OFF_TIMEOUT or STAY_ON_WHILE_PLUGGED_IN.

  2. If your phone is rooted and you are connected to wifi in the same network as the computer you're developing on, you can enjoy this wonderful app which comes with an option for screen timeout too: wifi adb.


I have 2 devices with Android 2.3.3 and they are both having this option in Settings/Applications/Development and its called Stay Awake (Screen will never sleep while charging). And one of them is Samsung Galaxy S.

Also I have a device with Android 2.2 (HTC Desire) an it has also the same functionality in the same location.

It is weird that your doesn't , do you use a custom ROM?


You can re-enable Developer options, which configurations are now hidden:

1 - Go to Settings > About > Software information > More...

2 - Then touch Build number 7 times, which will give you a count down, and then say “you’re now a developer”.

And Developer Options are back!


Use this in your Manifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />

and your screen won't turn off!

참고URL : https://stackoverflow.com/questions/8840954/how-do-i-keep-my-screen-unlocked-during-usb-debugging

반응형