adb: get adb working and cleanup pixelflinger

- update recovery init.rc
- add libdl bootstrap
- cleanup libpixelflinger import
- logd and adbd permissive for now
diff --git a/Android.bp b/Android.bp
index 250ef9d..a31ec86 100755
--- a/Android.bp
+++ b/Android.bp
@@ -85,6 +85,17 @@
         "libhidl-gen-utils",
         "librecovery_utils",
         "libc++fs"
+    ],
+    required: [
+        "init_recovery.rc",
+        "libdl_android.bootstrap",
     ]
 }
 
+prebuilt_etc {
+    name: "init_recovery.rc",
+    filename: "init.rc",
+    src: "etc/init.rc",
+    sub_dir: "init/hw",
+    recovery: true,
+}
diff --git a/Android.mk b/Android.mk
index f81d023..6fff19b 100755
--- a/Android.mk
+++ b/Android.mk
@@ -109,7 +109,6 @@
     system/core/adb \
     system/core/libsparse \
     external/zlib \
-    system/core/libpixelflinger/include \
     system/core/libziparchive/include \
     external/freetype/include \
     external/boringssl/include \
@@ -121,12 +120,13 @@
     $(LOCAL_PATH)/fuse_sideload/include \
     $(LOCAL_PATH)/install/include \
     $(LOCAL_PATH)/twrpinstall/include \
-    $(LOCAL_PATH)/recovery_utils/include
+    $(LOCAL_PATH)/recovery_utils/include \
+    $(LOCAL_PATH)/libpixelflinger/include
 
 LOCAL_STATIC_LIBRARIES += libguitwrp
 LOCAL_SHARED_LIBRARIES += libz libc libcutils libstdc++ libtar libblkid libminuitwrp libmtdutils libtwadbbu 
 LOCAL_SHARED_LIBRARIES += libbootloader_message libcrecovery libtwrpdigest libc++ libaosprecovery libcrypto libbase 
-LOCAL_SHARED_LIBRARIES += libziparchive libselinux
+LOCAL_SHARED_LIBRARIES += libziparchive libselinux libdl_android.bootstrap
 
 ifneq ($(wildcard system/core/libsparse/Android.mk),)
 LOCAL_SHARED_LIBRARIES += libsparse
@@ -402,7 +402,8 @@
     plat_hwservice_contexts \
     vendor_hwservice_contexts \
     minadbd \
-    twrpbu
+    twrpbu \
+    adbd_system_api_recovery
 
 ifneq ($(TW_INCLUDE_CRYPTO),)
 TWRP_REQUIRED_MODULES += \
diff --git a/etc/init.rc b/etc/init.rc
index e63c74c..ae18452 100644
--- a/etc/init.rc
+++ b/etc/init.rc
@@ -19,6 +19,8 @@
 
     start ueventd
 
+    setprop sys.usb.configfs 0
+
 on init
     export PATH /sbin:/system/bin
     export LD_LIBRARY_PATH /system/lib64
@@ -73,9 +75,6 @@
     trigger early-boot
     trigger boot
 
-on property:sys.powerctl=*
-   powerctl ${sys.powerctl}
-
 service ueventd /system/bin/ueventd
     critical
     seclabel u:r:ueventd:s0
@@ -91,6 +90,10 @@
     #start adbd
     setprop service.adb.root 1
 
+# Always start adbd on userdebug and eng builds
+on fs && property:ro.debuggable=1
+    setprop sys.usb.config adb
+
 service fastbootd /system/bin/fastbootd
     disabled
     group system
diff --git a/etc/init.recovery.logd.rc b/etc/init.recovery.logd.rc
index 29db6be..ed41391 100644
--- a/etc/init.recovery.logd.rc
+++ b/etc/init.recovery.logd.rc
@@ -1,4 +1,4 @@
-on late-init
+on init
     start logd
 
 service logd /system/bin/logd
diff --git a/etc/init.recovery.service22.rc b/etc/init.recovery.service22.rc
index 410efff..7ba997a 100755
--- a/etc/init.recovery.service22.rc
+++ b/etc/init.recovery.service22.rc
@@ -4,6 +4,3 @@
 service recovery /system/bin/recovery
     socket recovery stream 422 system system
     seclabel u:r:recovery:s0
-
-on early-init
-    write /sys/fs/selinux/enforce 0
diff --git a/gui/Android.bp b/gui/Android.bp
index 94d429b..aa2bbc4 100644
--- a/gui/Android.bp
+++ b/gui/Android.bp
@@ -1,83 +1,83 @@
-bootstrap_go_package {

-    name: "soong-libguitwrp_defaults",

-    pkgPath: "bootable/recovery/gui",

-    deps: [

-        "soong",

-        "soong-android",

-        "soong-cc"

-    ],

-    srcs: [

-        "libguitwrp_defaults.go"

-    ],

-    pluginFor: ["soong_build"]

-}

-

-libguitwrp_defaults {

-    name: "libguitwrp_defaults"

-}

-

-cc_library_static {

-    name: "libguitwrp",

-    defaults: ["libguitwrp_defaults"],

-    cflags: [

-        "-fno-strict-aliasing", 

-        "-Wno-implicit-fallthrough",

-        "-D_USE_SYSTEM_ZIPARCHIVE"

-    ],

-    include_dirs: [

-        "bootable/recovery/crypto/scrypt/lib/util",

-        "bootable/recovery/otautil/include",

-        "bootable/recovery/install/include",

-        "system/core/libziparchive/include",

-        "bootable/recovery/recovery_ui/include",

-        "bootable/recovery/fuse_sideload/include",

-        "bootable/recovery/twrpinstall",

-        "bootable/recovery/twrpinstall/include",

-        "bionic",

-        "system/core/base/include",

-        "system/core/include",

-        "system/core/libpixelflinger/include",

-        "external/freetype/include"

-

-    ],

-    srcs: [ 

-        "gui.cpp",

-        "resources.cpp",

-        "pages.cpp",

-        "text.cpp",

-        "image.cpp",

-        "action.cpp",

-        "console.cpp",

-        "fill.cpp",

-        "button.cpp",

-        "checkbox.cpp",

-        "fileselector.cpp",

-        "progressbar.cpp",

-        "animation.cpp",

-        "object.cpp",

-        "slider.cpp",

-        "slidervalue.cpp",

-        "listbox.cpp",

-        "keyboard.cpp",

-        "input.cpp",

-        "blanktimer.cpp",

-        "partitionlist.cpp",

-        "mousecursor.cpp",

-        "scrolllist.cpp",

-        "patternpassword.cpp",

-        "textbox.cpp",

-        "terminal.cpp",

-        "twmsg.cpp"

-    ],

-    shared_libs: [

-        "libminuitwrp",

-        "libc",

-        "libstdc++",

-        "libaosprecovery",

-        "libselinux",

-        "libziparchive"

-    ],

-    static_libs: [

-        "libotautil"

-    ]

+bootstrap_go_package {
+    name: "soong-libguitwrp_defaults",
+    pkgPath: "bootable/recovery/gui",
+    deps: [
+        "soong",
+        "soong-android",
+        "soong-cc"
+    ],
+    srcs: [
+        "libguitwrp_defaults.go"
+    ],
+    pluginFor: ["soong_build"]
+}
+
+libguitwrp_defaults {
+    name: "libguitwrp_defaults"
+}
+
+cc_library_static {
+    name: "libguitwrp",
+    defaults: ["libguitwrp_defaults"],
+    cflags: [
+        "-fno-strict-aliasing", 
+        "-Wno-implicit-fallthrough",
+        "-D_USE_SYSTEM_ZIPARCHIVE"
+    ],
+    include_dirs: [
+        "bootable/recovery/crypto/scrypt/lib/util",
+        "bootable/recovery/otautil/include",
+        "bootable/recovery/install/include",
+        "system/core/libziparchive/include",
+        "bootable/recovery/recovery_ui/include",
+        "bootable/recovery/fuse_sideload/include",
+        "bootable/recovery/twrpinstall",
+        "bootable/recovery/twrpinstall/include",
+        "bootable/recovery/libpixelflinger/include",
+        "bionic",
+        "system/core/base/include",
+        "system/core/include",
+        "external/freetype/include"
+
+    ],
+    srcs: [ 
+        "gui.cpp",
+        "resources.cpp",
+        "pages.cpp",
+        "text.cpp",
+        "image.cpp",
+        "action.cpp",
+        "console.cpp",
+        "fill.cpp",
+        "button.cpp",
+        "checkbox.cpp",
+        "fileselector.cpp",
+        "progressbar.cpp",
+        "animation.cpp",
+        "object.cpp",
+        "slider.cpp",
+        "slidervalue.cpp",
+        "listbox.cpp",
+        "keyboard.cpp",
+        "input.cpp",
+        "blanktimer.cpp",
+        "partitionlist.cpp",
+        "mousecursor.cpp",
+        "scrolllist.cpp",
+        "patternpassword.cpp",
+        "textbox.cpp",
+        "terminal.cpp",
+        "twmsg.cpp"
+    ],
+    shared_libs: [
+        "libminuitwrp",
+        "libc",
+        "libstdc++",
+        "libaosprecovery",
+        "libselinux",
+        "libziparchive"
+    ],
+    static_libs: [
+        "libotautil"
+    ]
 }
\ No newline at end of file
diff --git a/libpixelflinger/Android.bp b/libpixelflinger/Android.bp
index 5721394..8a4489c 100644
--- a/libpixelflinger/Android.bp
+++ b/libpixelflinger/Android.bp
@@ -1,105 +1,124 @@
-//bootstrap_go_package {

-//    name: "soong-libpixelflingertwrp_defaults",

-//    pkgPath: "bootable/recovery/libpixelflinger",

-//    deps: [

-//        "soong",

-//        "soong-android",

-//        "soong-cc"

-//    ],

-//    srcs: [

-//        "libpixelflingertwrp_defaults.go"

-//    ],

-//    pluginFor: ["soong_build"]

-//}

-

-//libpixelflingertwrp_defaults {

-//    name: "libpixelflingertwrp_defaults"

-//}

-

-cc_defaults {

-    name: "libpixelflingertwrp_defaults",

-

-    cflags: [

-        "-fstrict-aliasing",

-        "-fomit-frame-pointer",

-        "-Wall",

-        "-Werror",

-        "-Wno-unused-function",

-    ],

-    export_include_dirs: ["include"],

-    header_libs: ["libbase_headers"],

-    shared_libs: [

-        "libcutils",

-        "liblog",

-        "libutils",

-    ],

-

-    arch: {

-        arm: {

-            neon: {

-                cflags: ["-D__ARM_HAVE_NEON"],

-            },

-        },

-    },

-}

-

-cc_library_static {

-    name: "libpixelflinger_twrp",

-    defaults: ["libpixelflingertwrp_defaults"],

-

-    srcs: [

-        "codeflinger/ARMAssemblerInterface.cpp",

-        "codeflinger/ARMAssemblerProxy.cpp",

-        "codeflinger/CodeCache.cpp",

-        "codeflinger/GGLAssembler.cpp",

-        "codeflinger/load_store.cpp",

-        "codeflinger/blending.cpp",

-        "codeflinger/texturing.cpp",

-        "format.cpp",

-        "clear.cpp",

-        "raster.cpp",

-        "buffer.cpp",

-    ],

-    whole_static_libs: ["libpixelflinger-arm"],

-

-    arch: {

-        arm: {

-            srcs: [

-                "codeflinger/ARMAssembler.cpp",

-                "codeflinger/disassem.c",

-                "col32cb16blend.S",

-                "t32cb16blend.S",

-            ],

-

-            neon: {

-                srcs: ["col32cb16blend_neon.S"],

-            },

-        },

-        arm64: {

-            srcs: [

-                "codeflinger/Arm64Assembler.cpp",

-                "codeflinger/Arm64Disassembler.cpp",

-                "arch-arm64/col32cb16blend.S",

-                "arch-arm64/t32cb16blend.S",

-            ],

-        },

-        mips: {

-            mips32r6: {

-                srcs: [

-                    "codeflinger/MIPSAssembler.cpp",

-                    "codeflinger/mips_disassem.c",

-                    "arch-mips/t32cb16blend.S",

-                ],

-            },

-        },

-        mips64: {

-            srcs: [

-                "codeflinger/MIPSAssembler.cpp",

-                "codeflinger/MIPS64Assembler.cpp",

-                "codeflinger/mips64_disassem.c",

-                "arch-mips64/col32cb16blend.S",

-                "arch-mips64/t32cb16blend.S",

-            ],

-        },

-    },

-}

+//bootstrap_go_package {
+//    name: "soong-libpixelflingertwrp_defaults",
+//    pkgPath: "bootable/recovery/libpixelflinger",
+//    deps: [
+//        "soong",
+//        "soong-android",
+//        "soong-cc"
+//    ],
+//    srcs: [
+//        "libpixelflingertwrp_defaults.go"
+//    ],
+//    pluginFor: ["soong_build"]
+//}
+
+//libpixelflingertwrp_defaults {
+//    name: "libpixelflingertwrp_defaults"
+//}
+
+cc_defaults {
+    name: "libpixelflingertwrp_defaults",
+
+    cflags: [
+        "-fstrict-aliasing",
+        "-fomit-frame-pointer",
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-function",
+    ],
+    export_include_dirs: ["include"],
+    header_libs: ["libbase_headers"],
+    shared_libs: [
+        "libcutils",
+        "liblog",
+        "libutils",
+    ],
+
+    arch: {
+        arm: {
+            neon: {
+                cflags: ["-D__ARM_HAVE_NEON"],
+            },
+        },
+    },
+}
+
+cc_library_static {
+    name: "libpixelflingertwrp-arm",
+    defaults: ["libpixelflingertwrp_defaults"],
+
+    srcs: [
+        "fixed.cpp",
+        "picker.cpp",
+        "pixelflinger.cpp",
+        "trap.cpp",
+        "scanline.cpp",
+    ],
+
+    arch: {
+        arm: {
+            instruction_set: "arm",
+        },
+    },
+}
+
+cc_library_static {
+    name: "libpixelflinger_twrp",
+    defaults: ["libpixelflingertwrp_defaults"],
+
+    srcs: [
+        "codeflinger/ARMAssemblerInterface.cpp",
+        "codeflinger/ARMAssemblerProxy.cpp",
+        "codeflinger/CodeCache.cpp",
+        "codeflinger/GGLAssembler.cpp",
+        "codeflinger/load_store.cpp",
+        "codeflinger/blending.cpp",
+        "codeflinger/texturing.cpp",
+        "format.cpp",
+        "clear.cpp",
+        "raster.cpp",
+        "buffer.cpp",
+    ],
+    whole_static_libs: ["libpixelflingertwrp-arm"],
+
+    arch: {
+        arm: {
+            srcs: [
+                "codeflinger/ARMAssembler.cpp",
+                "codeflinger/disassem.c",
+                "col32cb16blend.S",
+                "t32cb16blend.S",
+            ],
+
+            neon: {
+                srcs: ["col32cb16blend_neon.S"],
+            },
+        },
+        arm64: {
+            srcs: [
+                "codeflinger/Arm64Assembler.cpp",
+                "codeflinger/Arm64Disassembler.cpp",
+                "arch-arm64/col32cb16blend.S",
+                "arch-arm64/t32cb16blend.S",
+            ],
+        },
+        mips: {
+            mips32r6: {
+                srcs: [
+                    "codeflinger/MIPSAssembler.cpp",
+                    "codeflinger/mips_disassem.c",
+                    "arch-mips/t32cb16blend.S",
+                ],
+            },
+        },
+        mips64: {
+            srcs: [
+                "codeflinger/MIPSAssembler.cpp",
+                "codeflinger/MIPS64Assembler.cpp",
+                "codeflinger/mips64_disassem.c",
+                "arch-mips64/col32cb16blend.S",
+                "arch-mips64/t32cb16blend.S",
+            ],
+        },
+    },
+}
diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk
index 2928dfd..c2c24bf 100755
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -36,7 +36,6 @@
 	RECOVERY_BINARY_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/awk
 endif
 
-RECOVERY_BINARY_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/bin/adbd
 RECOVERY_BINARY_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/bin/fastbootd
 RECOVERY_BINARY_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/e2fsck
 RECOVERY_BINARY_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/e2fsdroid
@@ -69,7 +68,7 @@
 RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libbinderthreadstate.so
 RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libmdnssd.so
 RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libinit.so
-RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libdl_android.so
+RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/bootstrap/libdl_android.so
 RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libprotobuf-cpp-lite.so
 RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libbinder.so
 RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libchrome.so
diff --git a/sepolicy/twrp.te b/sepolicy/twrp.te
index 44ceaf8..c27571a 100755
--- a/sepolicy/twrp.te
+++ b/sepolicy/twrp.te
@@ -1,4 +1,6 @@
 recovery_only(`
   permissive recovery;
   permissive init;
+  permissive logd;
+  permissive adbd;
 ')