Skip to content

Commit

Permalink
fix opticharger
Browse files Browse the repository at this point in the history
Change-Id: I3512cc943509468a4da18b6f3c7399425c0bf4ea
  • Loading branch information
Hashcode committed Sep 23, 2012
1 parent 47c6678 commit 26e0b70
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 7 deletions.
149 changes: 149 additions & 0 deletions releasetools/opticharger
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/bin/sh
#
# Super-mega opticharger of doom
# Shrinks apks by running pngcrush or optipng or pngout on png images
#
# Point APKCERTS at the full path to a generated apkcerts.txt file, such as:
# /home/shade/dev/sources/android-cm-eclair/out/target/product/dream_sapphire/obj/PACKAGING/target_files_intermediates/cyanogen_dream_sapphire-target_files-eng.shade/META/apkcerts.txt
#
# cyanogen - [email protected]
# ChrisSoyars - [email protected]

set -e
QUIET=1
BASE=`pwd`
BRUTECRUSH="-brute"
TMPDIR=/tmp/opticharge-$$

if [ -z "$BRUTE_PNGCRUSH" ]
then
BRUTECRUSH=""
fi

if [ "$APKCERTS" = "" ];
then
if [ "$TARGET_BUILD_VARIANT" = "userdebug" ]; then
TARGET_BUILD_VARIANT="eng"
elif [ "$TARGET_BUILD_VARIANT" = "user" ]; then
TARGET_BUILD_VARIANT="eng"
fi

APKCERTS=$OUT/obj/PACKAGING/target_files_intermediates/$TARGET_PRODUCT-target_files-$TARGET_BUILD_VARIANT.$USER/META/apkcerts.txt
if [ ! -f "$APKCERTS" ];
then
echo "Set APKCERTS to the path to your apkcerts.txt file"
exit 1;
fi
fi

if [ ! -f "$APKCERTS" ];
then
echo "Invalid path to apkcerts.txt, set APKCERTS to the correct path."
fi

if [ "$(which pngcrush)" != "" ];
then
optimize_png () {
pngcrush -q ${BRUTECRUSH} $1 ${1}.out 1> /dev/null 2> /dev/null
mv ${1}.out ${1} 2> /dev/null
}
elif [ "$(which optipng)" != "" ];
then
optimize_png () {
optipng -o7 -quiet $1 1> /dev/null 2> /dev/null
}
elif [ "$(which pngout-static)" != "" ];
then
optimize_png () {
pngout-static $1
}
elif [ "$(which pngout)" != "" ];
then
optimize_png () {
pngout $1
}
else
echo "Please install pngcrush, optipng, or pngout"
exit 1;
fi

if [ "`which aapt`" = "" ];
then
echo "Please ensure aapt is in your \$PATH"
exit 1;
fi

if [ "`which zipalign`" = "" ];
then
echo "Please ensure zipalign is in your \$PATH"
exit 1;
fi

if [ -e "$1" ];
then
NAME=`basename $1`;
echo "Optimizing $NAME...";

if [ "$2" != "" ];
then
CERT=build/target/product/security/$2.x509.pem
KEY=build/target/product/security/$2.pk8
if [ ! -f "$ANDROID_BUILD_TOP/$CERT" ];
then
echo "$CERT does not exist!";
exit 1;
fi
else
APKINFO=`grep "name=\"$NAME\"" $APKCERTS`;
[ $QUIET ] || echo "APKINFO: $APKINFO";
if [ "$APKINFO" = "" ];
then
echo "No apk info for $NAME";
exit 1;
fi
CERT=`echo $APKINFO | awk {'print $2'} | cut -f 2 -d "=" | tr -d "\""`;
KEY=`echo $APKINFO | awk {'print $3'} | cut -f 2 -d "=" | tr -d "\""`;
if [ "$CERT" = "" ];
then
echo "Unable to find certificate for $NAME"
exit 1;
fi
if [ "$CERT" = "PRESIGNED" ];
then
echo "$NAME is presigned, skipping"
exit 1;
fi
fi

[ $QUIET ] || echo "Certificate: $CERT";

[ -d $TMPDIR/$NAME ] && rm -rf $TMPDIR/$NAME
mkdir -p $TMPDIR/$NAME
trap "rm -rf $TMPDIR; exit" INT TERM EXIT
cd $TMPDIR/$NAME
unzip -q $BASE/$1
for x in `find . -name "*.png" | grep -v "\.9.png$" | tr "\n" " "`
do
[ $QUIET ] || echo "Crushing $x"
optimize_png $x
done
cp $BASE/$1 $BASE/$1.old

[ $QUIET ] || echo "Repacking apk.."
aapt p -0 .dat -0 .dict -0 .arsc -F $NAME .

[ $QUIET ] || echo "Resigning with cert: `echo $CERT`"

[ $QUIET ] || echo java -jar $ANDROID_HOST_OUT/framework/signapk.jar $ANDROID_BUILD_TOP/$CERT $ANDROID_BUILD_TOP/$KEY $NAME signed_$NAME
java -jar $ANDROID_HOST_OUT/framework/signapk.jar $ANDROID_BUILD_TOP/$CERT $ANDROID_BUILD_TOP/$KEY $NAME signed_$NAME
[ $QUIET ] || echo "Zipalign.."
zipalign -f 4 signed_$NAME $BASE/$1
if [ ! $QUIET ]; then
ls -l $BASE/$1.old
ls -l $BASE/$1
fi
rm $BASE/$1.old
else
echo "Usage: $0 [apk file]"
fi

14 changes: 7 additions & 7 deletions releasetools/squisher
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if [ ! -f "$OTAPACKAGE" ]; then
exit 1
fi

OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger
OPTICHARGER=$ANDROID_BUILD_TOP/device/amazon/otter/releasetools/opticharger
QUIET=-q
DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"

Expand Down Expand Up @@ -69,6 +69,12 @@ rm -rf $REPACK/ota/recovery
[ -d $REPACK/ota/system/lib/modules ] && \
find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded

# Remove wl1271-nvs.bin so that wl1271-nvs_127x.bin can re-write it
rm $REPACK/ota/system/etc/firmware/ti-connectivity/wl1271-nvs.bin

# Remove camera.omap4.so -- it hangs media server
rm $REPACK/ota/system/lib/hw/camera.omap4.so

# Determine what to name the new signed package
REALDATE=`date -u +%Y%m%d`

Expand All @@ -86,12 +92,6 @@ else
OUTFILE=$OUT/$TARGET_PRODUCT-JB-$REALDATE.zip
fi

# Remove wl1271-nvs.bin so that wl1271-nvs_127x.bin can re-write it
rm $REPACK/ota/system/etc/firmware/ti-connectivity/wl1271-nvs.bin

# Remove camera.omap4.so -- it hangs media server
rm $REPACK/ota/system/lib/hw/camera.omap4.so

# Pack it up and sign
printf "Zipping package..."
( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
Expand Down

0 comments on commit 26e0b70

Please sign in to comment.