Merge up to AOSP marshmallow-release

In order to maintain compatibility with older trees, we now have
minadbd.old and minui.old. I had to use a TARGET_GLOBAL_CFLAG to
handle ifdef issues in minui/minui.d because healthd includes
minui/minui.h and there was no other alternative to make minui.h
compatible with older trees without having to modify healthd rules
which is outside of TWRP.

Note that the new minui does not currently have support for qcom
overlay graphics. Support for this graphics mode will likely be
added in a later patch set. If you are building in a 6.0 tree and
have a device that needs qcom overlay graphics, be warned, as off
mode charging may not work properly. A dead battery in this case
could potentially brick your device if it is unable to charge as
healthd handles charging duties.

Update rules for building toolbox and add rules for making toybox

Use permissive.sh in init.rc which will follow symlinks so we do
not have to worry about what binary is supplying the setenforce
functionality (toolbox, toybox, or busybox).

Fix a few warnings in the main recovery binary source code.

Fix a few includes that were missing that prevented compiling in
6.0

Change-Id: Ia67aa2107d260883da5e365475a19bea538e8b97
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index e58b755..d54bfa4 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -4,110 +4,150 @@
 OUR_TOOLS := \
     start \
     stop \
-    getprop \
-    setprop
+    
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
+    OUR_TOOLS += \
+        getprop \
+        setprop
+endif
 
 # If busybox does not have SELinux support, provide these tools with toolbox.
 # Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
 ifeq ($(TWHAVE_SELINUX), true)
     TOOLS_FOR_SELINUX := \
-        ls \
-        getenforce \
-        chcon \
-        restorecon \
-        runcon \
-        getsebool \
-        setsebool \
-        load_policy
+        ls
+
+    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
+        TOOLS_FOR_SELINUX += \
+            load_policy \
+            getenforce \
+            chcon \
+            restorecon \
+            runcon \
+            getsebool \
+            setsebool
+    endif
+
     OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
 
     # toolbox setenforce is used during init, so it needs to be included here
     # symlink is omitted at the very end if busybox already provides this
-    OUR_TOOLS += setenforce
+    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
+       OUR_TOOLS += setenforce
+    endif
 endif
 
 ifeq ($(TW_USE_TOOLBOX), true)
-    ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
-        OUR_TOOLS += \
-            mknod \
-            nohup
+    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
+        # These are the only toolbox tools in M. The rest are now in toybox.
         BSD_TOOLS := \
-            cat \
-            chown \
-            cp \
             dd \
             du \
-            grep \
-            kill \
-            ln \
-            mv \
-            printenv \
-            rm \
-            rmdir \
-            sleep \
-            sync
-    else
-        OUR_TOOLS += \
-            cat \
-            chown \
-            dd \
-            du \
-            kill \
-            ln \
-            mv \
-            printenv \
-            rm \
-            rmdir \
-            setconsole \
-            sleep \
-            sync
-    endif
 
-    OUR_TOOLS += \
-        chmod \
-        clear \
-        cmp \
-        date \
-        df \
-        dmesg \
-        getevent \
-        hd \
-        id \
-        ifconfig \
-        iftop \
-        insmod \
-        ioctl \
-        ionice \
-        log \
-        lsmod \
-        lsof \
-        md5 \
-        mkdir \
-        mkswap \
-        mount \
-        nandread \
-        netstat \
-        newfs_msdos \
-        notify \
-        ps \
-        readlink \
-        renice \
-        rmmod \
-        route \
-        schedtop \
-        sendevent \
-        smd \
-        swapoff \
-        swapon \
-        top \
-        touch \
-        umount \
-        uptime \
-        vmstat \
-        watchprops \
-        wipe
-    ifneq ($(TWHAVE_SELINUX), true)
-        OUR_TOOLS += ls
+        OUR_TOOLS := \
+            df \
+            iftop \
+            ioctl \
+            ionice \
+            log \
+            ls \
+            lsof \
+            mount \
+            nandread \
+            newfs_msdos \
+            ps \
+            prlimit \
+            renice \
+            sendevent \
+            start \
+            stop \
+            top \
+            uptime \
+            watchprops \
+
+    else
+        ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
+            OUR_TOOLS += \
+                mknod \
+                nohup
+            BSD_TOOLS := \
+                cat \
+                chown \
+                cp \
+                dd \
+                du \
+                grep \
+                kill \
+                ln \
+                mv \
+                printenv \
+                rm \
+                rmdir \
+                sleep \
+                sync
+        else
+            OUR_TOOLS += \
+                cat \
+                chown \
+                dd \
+                du \
+                kill \
+                ln \
+                mv \
+                printenv \
+                rm \
+                rmdir \
+                setconsole \
+                sleep \
+                sync
+        endif
+
+        OUR_TOOLS += \
+            chmod \
+            clear \
+            cmp \
+            date \
+            df \
+            dmesg \
+            getevent \
+            hd \
+            id \
+            ifconfig \
+            iftop \
+            insmod \
+            ioctl \
+            ionice \
+            log \
+            lsmod \
+            lsof \
+            md5 \
+            mkdir \
+            mkswap \
+            mount \
+            nandread \
+            netstat \
+            newfs_msdos \
+            notify \
+            ps \
+            readlink \
+            renice \
+            rmmod \
+            route \
+            schedtop \
+            sendevent \
+            smd \
+            swapoff \
+            swapon \
+            top \
+            touch \
+            umount \
+            uptime \
+            vmstat \
+            watchprops \
+            wipe
+        ifneq ($(TWHAVE_SELINUX), true)
+            OUR_TOOLS += ls
+        endif
     endif
 endif
 
@@ -135,7 +175,7 @@
         upstream-netbsd/lib/libutil/raise_default_signal.c
 endif
 
-ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
+ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
     LOCAL_CFLAGS += \
         -std=gnu99 \
         -Werror -Wno-unused-parameter \
@@ -165,7 +205,7 @@
     LOCAL_SHARED_LIBRARIES += libselinux
 endif
 
-ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
+ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
     # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
     # The linker strips out all the unused library code in the normal case.
     LOCAL_STATIC_LIBRARIES := libusbhost
@@ -182,7 +222,7 @@
 
 $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
 
-ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
+ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
     ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
 else
     ALL_TOOLS := $(OUR_TOOLS)