[Sony Xperia M2] linuxct:
OTA trouble - how to fix it?

Guys, I've realized something...

Doing several experiments in another OTA Beta Channel, I've seen that only CWM and PhilZ recognized the OTA commands, TWRP just stayed doing nothing, so, I decided to have a loot at it...

It seems that OTA Updater detects our phone is manufactured by Sony, so the app is set to write the recovery commands onto a extendedcommands files, which is CWM propietary, instead of using OpenRecoveryScript or a command file. This results in a non-fully-working OTA.

Here's a pick of the code I'm talking about:

if (Build.MANUFACTURER.toLowerCase(Locale.US).contains("sony")) {
if (backup) {
os.writeBytes("echo 'backup_rom /sdcard/clockworkmod/backup/ota_" +
new SimpleDateFormat("yyyy-MM-dd_HH.mm", Locale.US).format(new Date()) +
"' >> /cache/recovery/extendedcommand\n");
}
if (wipeData) {
os.writeBytes("echo 'format(\"/data\");' >> /cache/recovery/extendedcommand\n");
}
if (wipeCache) {
os.writeBytes("echo 'format(\"/cache\");' >> /cache/recovery/extendedcommand\n");
}

for (String file : files) {
os.writeBytes("echo 'install_zip(\"" + file + "\");' >> /cache/recovery/extendedcommand\n");
}
} else {
if (backup) {
os.writeBytes("echo '--nandroid' >> /cache/recovery/command\n");
}
if (wipeData) {
os.writeBytes("echo '--wipe_data' >> /cache/recovery/command\n");
}
if (wipeCache) {
os.writeBytes("echo '--wipe_cache' >> /cache/recovery/command\n");
}

for (String file: files) {
os.writeBytes("echo '--update_package=" + file + "' >> /cache/recovery/command\n");
}
}

Having that in mind, and that I don't have a proper build environment for this, I decided to modify the Smali.

The result is the following:

.line 267
sget-object v8, Landroid/os/Build;->MANUFACTURER:Ljava/lang/String;

sget-object v9, Ljava/util/Locale;->US:Ljava/util/Locale;

invoke-virtual {v8, v9}, Ljava/lang/String;->toLowerCase(Ljava/util/Locale;)Ljava/lang/String;

move-result-object v8

const-string v9, "nothing"

invoke-virtual {v8, v9}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

move-result v8

if-eqz v8, :cond_3

Where nothing is where the sony variable was set.

.line 285
const-string v8, "echo \'backup SDM\' >> /cache/recovery/openrecoveryscript\n"

invoke-virtual {v5, v8}, Ljava/io/DataOutputStream;->writeBytes(Ljava/lang/String;)V

.line 287
:cond_4
if-eqz p4, :cond_5

.line 288
const-string v8, "echo \'wipe data\' >> /cache/recovery/openrecoveryscript\n"

invoke-virtual {v5, v8}, Ljava/io/DataOutputStream;->writeBytes(Ljava/lang/String;)V

.line 290
:cond_5
if-eqz p3, :cond_6

.line 291
const-string v8, "echo \'wipe cache\' >> /cache/recovery/openrecoveryscript\n"

invoke-virtual {v5, v8}, Ljava/io/DataOutputStream;->writeBytes(Ljava/lang/String;)V

.line 294
:cond_6
move-object v0, p1

.restart local v0 # "arr$":[Ljava/lang/String;
array-length v4, v0

.restart local v4 # "len$":I
const/4 v3, 0x0

.restart local v3 # "i$":I
:goto_1
if-ge v3, v4, :cond_7

aget-object v2, v0, v3

.line 295
.restart local v2 # "file":Ljava/lang/String;
new-instance v8, Ljava/lang/StringBuilder;

invoke-direct {v8}, Ljava/lang/StringBuilder;-><init>()V

const-string v9, "echo \'install "

invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v8

invoke-virtual {v8, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v8

const-string v9, "\' >> /cache/recovery/openrecoveryscript\n"

invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v8

invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v8

invoke-virtual {v5, v8}, Ljava/io/DataOutputStream;->writeBytes(Ljava/lang/String;)V

Where Backup SDM means backup current ROM (System + Data - No MD5 check), Wipe data (obvious), and Wipe cache (obvious too) are the parameters you choose inside the app. By default, wipe cache is turned on, but you can deactivate it if you want.

Being that said, I'm now in a state I don't know what to do. Shall I send a OTA to you all, so that you manually install it and fix it, or place the APK here and you manually replace it, or make it flashable... I don't know.

Please, let me know what you guys prefer.

Thank you.