Vendor CM Build: Allow parallelize the optimization of framework-res.apk

from: http://review.cyanogenmod.com/#/c/19170/

This change enhancement the optimization of cm ota package, allowing do the optimization of
framework-res.apk in a parallel way. The current script optimize first the
framework-res package and then the rest of packages with xargs in parallel. The framework-res
package can be processed with xargs in parallel copying all the packages to a temporally folder
to apply xargs (because opticharged need that the package is the current directory).
This shortens the time of optimization process, because while framework-res package is
optimized, the rest of processor cores can be optimizing other packages.

Change-Id: I047f8c01b066db99e4dcc8bcb2f30c72492e1af8
diff --git a/tools/squisher b/tools/squisher
index 9a4b0bd..250a248 100755
--- a/tools/squisher
+++ b/tools/squisher
@@ -53,10 +53,25 @@
 printf "Unpacking $OTAPACKAGE..."
 unzip $QUIET $OTAPACKAGE
 echo
-cd $REPACK/ota/system/framework
-$OPTICHARGER framework-res.apk
-cd $REPACK/ota/system/app
+
+# Move all apks to the same directory so xargs can
+# use also with framework-res.apk. This allow process
+# framework-res.apk in parallel with other apks
+mkdir -p $REPACK/parallel
+cd $REPACK/parallel
+cp $REPACK/ota/system/framework/framework-res.apk .
+cp $REPACK/ota/system/app/*.apk .
+
+# Do optimization in parallel
 find ./ -name \*.apk | $XARGS $OPTICHARGER
+
+# Move optimized apks to repack directory
+mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk
+mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/
+
+# Return to directory
+cd $REPACK/ota
+rm -rf $REPACK/parallel
 )
 
 # Fix build.prop