[Android Software/Hacking General [Developers Only]] mikeoswego:
Well, I've got something put together that works. Since I control the rom, I have the list of versions for the installed apps in /system rather than having to check them on the fly. This script is tacked onto an existing script in the Motorola rom.

It looks for updated apps in packages.xml, compares the version and if the system version is greater/equal, it does an rm -rf on the version in /data. Then it goes through packages.xml to find the start of the package entry for the version in /data, removes that line and all up to the /package line. Then it goes through packages.xml again to find the lines marked as "updated-package" and "/updated-package" for the app and sed removes the "updated" part. Finally, if any action was taken, it reboots the phone. After the reboot, the optimizing apps dialog comes up for the apps updated, all settings are still in place and the version number for the system installed app has been updated. This all takes some time and it is 30 seconds or more after the lock screen appears before the reboot occurs. I'm not thrilled by the auto reboot but on the other hand there is no need to wipe dalvik-cache and wait for an eternity if Xposed is installed to rebuild the entire cache. Maybe I could speed this up by reading packages.xml into an array rather than reading it from the disk, I'll have to think about that.

Here is the code:

# Hack to clean up apps in data after image upgrade
#
reboot=no
tmp=$(grep "\<updated-package name" /data/system/packages.xml)
tmpline=$(echo "$tmp" | grep -c \>)
let tmpline=tmpline+1
counter=1
while [ $counter -lt $tmpline ]; do
appname=$(echo $tmp | cut -d \> -f $counter | cut -d \" -f2)
poscounter=1
position=empty
datainfo=$(grep "<package name=\"$appname\"" /data/system/packages.xml)
poscounter=1
until [ "$position" == " version=" ]; do
position=$(echo "$datainfo" | cut -d \" -f $poscounter)
if [ "$position" == " version=" ]; then
let poscounter=poscounter+1
dataversion=$(echo "$datainfo" | cut -d \" -f $poscounter)
fi
let poscounter=poscounter+2
done
sysversion=$( grep "$appname\"" /system/etc/applist | cut -d \" -f2)
if [ "$sysversion" == "" ]; then
sysversion=0
fi
if [ $sysversion -ge $dataversion ] ; then
position=empty
poscounter=1
until [ "$position" == " codePath=" ]; do
position=$(echo "$datainfo" | cut -d \" -f $poscounter)
if [ "$position" == " codePath=" ]; then
let poscounter=poscounter+1
datapath=$(echo "$datainfo" | cut -d \" -f $poscounter)
fi
let poscounter=poscounter+2
done
rm -rf $datapath
reboot=yes
if [ -f /data/system/packages.tmp ]; then
rm /data/system/packages.tmp
fi
packline=no
endpackline=no
doneline=no
foundpack=no
while IFS= read line; do
if [ "$doneline" == "yes" ]; then
printf "%s\n" "$line" >> /data/system/packages.tmp
else
if [ "$foundpack" == "yes" ]; then
endpackline=$(echo $line | grep "</package")
if [ ! "$endpackline" == "" ]; then
doneline=yes
fi
else
packline=$(echo $line | grep "<package name=\"$appname\"")
if [ ! "$packline" == "" ]; then
foundpack=yes
else
printf "%s\n" "$line" >> /data/system/packages.tmp
fi
fi
fi
done < /data/system/packages.xml
mv /data/system/packages.tmp /data/system/packages.xml
if [ -f /data/system/packages.tmp ]; then
rm /data/system/packages.tmp
fi
packline=no
endpackline=no
doneline=no
foundpack=no
while IFS= read line; do
if [ "$doneline" == "yes" ]; then
printf "%s\n" "$line" >> /data/system/packages.tmp
else
if [ "$foundpack" == "yes" ]; then
endpackline=$(echo $line | grep "</updated-package")
if [ ! "$endpackline" == "" ]; then
printf "%s\n" "$line" | sed 's/updated-package/package/' >> /data/system/packages.tmp
doneline=yes
fi
else
packline=$(echo $line | grep "<updated-package name=\"$appname\"")
if [ ! "$packline" == "" ]; then
printf "%s\n" "$line" | sed 's/updated-package/package/' >> /data/system/packages.tmp
foundpack=yes
else
printf "%s\n" "$line" >> /data/system/packages.tmp
fi
fi
fi
done < /data/system/packages.xml
mv /data/system/packages.tmp /data/system/packages.xml
fi
position=empty
let counter=counter+1
done
if [ "$reboot" == "yes" ]; then
reboot
fi
#
#End clean up hack

Thanks again for your ideas and taking time to help me out with this!