Enable ADB Wifi Access on OnePlus Phones 3.1

Enable ADB Wifi without necessity of enabling it with adb command from the computer.

Tags:
  1. autormali
    Normally every time you reboot your device you need to give ADB Wifi Permission via the adb command to have access to ADB Wifi and use of Tasker ADB Wifi action. But if you have OnePlus phone, there is no PC, Mac or other device, or hardware needed to give that permission. You can enable ADB Wifi Access directly from your phone after each reboot.

    To successfully run the profile the requirements are:
    • "Wireless ADB debugging" setting/toggle avialable in Developer Options - see image. Only OnePlus devices (running Oxygen OS and Android 10 and above) have this option for now.
    • Write Secure Settings Permission granted to Tasker.
    • Update: For Oxygen 11.0 and above - a new option "Disable adb authorization timeout" set to on. This will ensure reliable execution of the profile.


    How does it work? After each reboot the profile ADB Wifi Access Enable On Boot is active and run the main task, which is navigating to the Developer Options and do click sequence to enable Wireless ADB.
    Updated in version 3.0: In some cases when the user decided to keep display off and/or locked after reboot, it was observed that above described profile (with reboot context) was not executing the main task due to screen is off and AutoInput action time out. Added the second profile ADB WiFi Access Enable When Display Unlocked, which is activated at the first and only the first unlock of the phone. That profile will make the second attempt to run the main task but only if ADB Wifi has not been enabled on boot.



    Descriptions:
    Code (Text):

     
    Profile: ADB Wifi Access Enable When Display Unlocked (6)
                Restore: no
                Event: Display Unlocked
            Enter: ADB Wifi Access Enable AI (2)
                <!? Set this variable to <b>no</b>  if you want to keep "Wireless ADB debugging" option disabled, set it to anything to keep it enabled.<br>You should set it to <b>no</b> if in your setup you are using "ADB Wifi" actions with "Enable Debugging" option set to on>
                A1: Variable Set [ Name:%wifi_debugging_enabled To:read label for info Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
                A2: Tasker Function [  Function:CheckADBWifi() ]
                A3: Flash [ Text:ADB Wifi Access already enabled Long:Off ] If [ %has_adb_wifi ~ true ]
                <?? <b>Stop task</b> ADB WiFi Access must do not be accessible before proceeding this task otherwise you mess up with AutoInput clicks sequence and task final result.<br><br>For testing purpose of this task without rebooting your device, go to Developer Options and disable both "USB debugging" and "Wireless ADB debugging" options then run this task.>
                A4: Stop [ With Error:Off Task: ] If [ %has_adb_wifi ~ true ]
                <Disable USB debugging.>
                A5: Custom Setting [ Type:Global Name:adb_enabled Value:0 Use Root:Off Read Setting To: ]
                A6: Status Bar [ Set:Collapsed ]
                <Open Developer Settings>
                A7: Developer Settings
                A8: Wait [ MS:500 Seconds:0 Minutes:0 Hours:0 Days:0 ]
                <Set variable to scroll to "ADB" word. It is set to mach regex to fit different placement of word in Latin languages.>
                A9: Variable Set [ Name:%scrollto To:~RADB\s|\sADB\s|\sADB Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]
                <Scroll to debugging options>
                A10: Perform Task [ Name:AutoInput Scroll To Word Priority:%priority Parameter 1 (%par1):%scrollto Parameter 2 (%par2): Return Value Variable: Stop:Off Local Variable Passthrough:Off Limit Passthrough To: Reset Return Variable:Off Allow Overwrite Variables:Off ]
                <Enable Wireless ADB debugging>
                A11: AutoInput Action [ Configuration:Type: Id
            Value: android:id/switch_widget
            Nearby Text: ADB
            Action : Click Timeout (Seconds):25 ]
                <Enable USB debugging>
                A12: Custom Setting [ Type:Global Name:adb_enabled Value:1 Use Root:Off Read Setting To: ]
                A13: Wait [ MS:500 Seconds:0 Minutes:0 Hours:0 Days:0 ]
                A14: If [ %wifi_debugging_enabled ~ no ]
                <Disable Wireless ADB debugging>
                A15: AutoInput Action [ Configuration:Type: Id
            Value: android:id/switch_widget
            Nearby Text: ADB
            Action : Click Timeout (Seconds):23 ]
                A16: Wait [ MS:500 Seconds:0 Minutes:0 Hours:0 Days:0 ]
                A17: End If
                A18: AutoInput Global Action [ Configuration:Action: Back Timeout (Seconds):20 ]
                A19: Tasker Function [  Function:CheckADBWifi() ]
                A20: Flash [ Text:ADB Wifi Access enabled Long:Off ] If [ %has_adb_wifi ~ true ]
                A21: Flash [ Text:Wireless ADB debugging enabled Long:Off ] If [ %wifi_debugging_enabled !~ no ]
                A22: Flash [ Text:Wireless ADB debugging disabled Long:Off ] If [ %wifi_debugging_enabled ~ no ]
         
            Exit: Anon (3)
                <Profile Status set to off.>
                A1: Profile Status [ Name:ADB Wifi Access Enable When Display Unlocked Set:Off ]
         
     
            Profile: ADB Wifi Access Enable On Boot (7)
                Priority: 50 Restore: no
                Event: Device Boot
            Enter: Anon (4)
                <Is screen locked?>
                A1: Java Function [ Return:kgm Class Or Object:CONTEXT Function:getSystemService
            {KeyguardManager} (String) Param:keyguard Param: Param: Param: Param: Param: Param: ]
                <%locked returns true/false>
                A2: Java Function [ Return:%locked Class Or Object:kgm Function:inKeyguardRestrictedInputMode
            {boolean} () Param: Param: Param: Param: Param: Param: Param: ]
                A3: Perform Task [ Name:ADB Wifi Access Enable AI Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off Local Variable Passthrough:Off Limit Passthrough To: Reset Return Variable:Off Allow Overwrite Variables:Off ] If [ %SCREEN ~ on & %locked ~ false ]
                A4: Tasker Function [  Function:CheckADBWifi() ]
                <Fallback to enable ADB Wifi on the first unlock and only the first unlock of the display if attempt on boot unsuccessful.>
                A5: Profile Status [ Name:ADB Wifi Access Enable When Display Unlocked Set:On ] If [ %has_adb_wifi ~ false ]
         
       Tasks
     
            ADB Wifi Access Enable AI
            <!? Set this variable to <b>no</b>  if you want to keep "Wireless ADB debugging" option disabled, set it to anything to keep it enabled.<br>You should set it to <b>no</b> if in your setup you are using "ADB Wifi" actions with "Enable Debugging" option set to on>
            A1: Variable Set [ Name:%wifi_debugging_enabled To:read label for info Recurse Variables: Do Maths: Append: Max Rounding Digits: ]
            A2: Tasker Function [  Function:CheckADBWifi() ]
            A3: Flash [ Text:ADB Wifi Access already enabled Long: ] If [ %has_adb_wifi ~ true ]
            <?? <b>Stop task</b> ADB WiFi Access must do not be accessible before proceeding this task otherwise you mess up with AutoInput clicks sequence and task final result.<br><br>For testing purpose of this task without rebooting your device, go to Developer Options and disable both "USB debugging" and "Wireless ADB debugging" options then run this task.>
            A4: Stop [ With Error: Task: ] If [ %has_adb_wifi ~ true ]
            <Disable USB debugging.>
            A5: Custom Setting [ Type:Global Name:adb_enabled Value:0 Use Root: Read Setting To: ]
            A6: Status Bar [ Set:Collapsed ]
            <Open Developer Settings>
            A7: Developer Settings
            A8: Wait [ MS:500 Seconds:0 Minutes:0 Hours:0 Days:0 ]
            <Set variable to scroll to "ADB" word. It is set to mach regex to fit different placement of word in Latin languages.>
            A9: Variable Set [ Name:%scrollto To:~RADB\s|\sADB\s|\sADB Recurse Variables: Do Maths: Append: Max Rounding Digits: ]
            <Scroll to debugging options>
            A10: Perform Task [ Name:AutoInput Scroll To Word Priority: Parameter 1 (%par1):%scrollto Parameter 2 (%par2): Return Value Variable: Stop: Local Variable Passthrough: Limit Passthrough To: Reset Return Variable: Allow Overwrite Variables: ]
            <Enable Wireless ADB debugging>
            A11: AutoInput Action [ Configuration:Type: Id
        Value: android:id/switch_widget
        Nearby Text: ADB
        Action : Click Timeout (Seconds): ]
            <Enable USB debugging>
            A12: Custom Setting [ Type:Global Name:adb_enabled Value:1 Use Root: Read Setting To: ]
            A13: Wait [ MS:500 Seconds:0 Minutes:0 Hours:0 Days:0 ]
            A14: If [ %wifi_debugging_enabled ~ no ]
            <Disable Wireless ADB debugging>
            A15: AutoInput Action [ Configuration:Type: Id
        Value: android:id/switch_widget
        Nearby Text: ADB
        Action : Click Timeout (Seconds): ]
            A16: Wait [ MS:500 Seconds:0 Minutes:0 Hours:0 Days:0 ]
            A17: End If
            A18: AutoInput Global Action [ Configuration:Action: Back Timeout (Seconds): ]
            A19: Tasker Function [  Function:CheckADBWifi() ]
            A20: Flash [ Text:ADB Wifi Access enabled Long: ] If [ %has_adb_wifi ~ true ]
            A21: Flash [ Text:Wireless ADB debugging enabled Long: ] If [ %wifi_debugging_enabled !~ no ]
            A22: Flash [ Text:Wireless ADB debugging disabled Long: ] If [ %wifi_debugging_enabled ~ no ]
     
     
        AutoInput Scroll To Word
            <<b><font color="red"> INPUTS:
        <br>
        <br>
        WORD TO SCROLL TO IN %par1
        <br>
        <br> TIME DELAY EACH SCROLL IN MS IN %par2>
            A1: Anchor
            <BEGIN ??>
            A2: Anchor
            <? DEFAULT MS BETWEEN SCROLLS IF NOT SPECIFIED ON %par2>
            A3: Variable Set [ Name:%par2 To:500 Recurse Variables: Do Maths: Append: Max Rounding Digits: ] If [ %par2 !Set ]
            A4: Test Display [ Type:Available Resolution Data: Store Result In:%res ]
            A5: Variable Split [ Name:%res Splitter:x Delete Base: ]
            A6: Variable Set [ Name:%res(1) To:ceil(%res(1)/2) Recurse Variables: Do Maths: Append: Max Rounding Digits: ]
            A7: Variable Set [ Name:%res(2) To:ceil(%res(2)*0.95) Recurse Variables: Do Maths: Append: Max Rounding Digits: ]
            <Loop Start>
            A8: Anchor
            <LOOK AT ALL WORDS ON SCREEN>
            A9: AutoInput UI Query [ Configuration: Timeout (Seconds): ]
            <RETURN false IF END OF PAGE HAS BEEN REACHED>
            A10: Return [ Value:false Stop:On Local Variable Passthrough:Off Replace On Passthrough:Off Limit Passthrough To: ] If [ %previous_list eq %aitext() ]
            <IF WORD ISN'T ON SCREEN, SCROLL DOWN>
            A11: If [ %aitext(#?%par1) = 0 ]
            A12: Variable Set [ Name:%previous_list To:%aitext() Recurse Variables: Do Maths: Append: Max Rounding Digits: ]
            A13: AutoInput Action [ Configuration:Type: Point
        Value: %res(1),%res(2)
        Action : Scroll Forward Timeout (Seconds): ]
            A14: Array Clear [ Variable Array:%aitext ]
            A15: Wait [ MS:%par2 Seconds:0 Minutes:0 Hours:0 Days:0 ] If [ %par2 > 0 ]
            A16: Goto [ Type:Action Label Number:1 Label:Loop Start ]
            A17: End If
            <IF TASK MAKES IT HERE, WORD HAS BEEN FOUND ON DISPLAY, RETURNS TRUE.>
            A18: Return [ Value:true Stop:On Local Variable Passthrough:Off Replace On Passthrough:Off Limit Passthrough To: ]