I Hate you Android

Problem: you want to download a large file from an application.

For WikipOff, I want to let users download large (a few Gbs) files from the application. Thoses files are going to be hosted on any kind of website, mostly on my own server, through https:// links.

I’m a lazy developer, which means I want to write as less code as possible. So I ask Google how to download large files the Android-way.

Turns out I have a few options, from tons of code to write, to almost none :

  • Implement a Service
  • Code an AsyncTask
  • Use the DownloadManager service

DownloadManager Service

Cool, Android comes with a download manager, let’s try to use that.

Fail number one

I want my app to support 2.3.x platforms and up. Unfortunately the DownloadManager class won’t let you download https:// links.

### Fail number two

I have no interest in paying for certificates that are trusted by Google, my certificates are self-signed. The problem is DownloadManager will only check against the device’s global certificate store.

A bug calling against this has been open since 2009, and Google’s only answer is to add your own certs in the system store.

Unfortunately adding your own certificates in Android is a pain in the ass.

To add a certificate in your device’s store, you must either push the certificate in DER format through USB, or use an app and enter manually the URL to an SSL service that presents the cert.

Once that’s done, Android KitKat will keep threatening you with crazy messages saying that all your communications may be monitored.

### Okay, let’s code instead

FUCK IT I’ll do my own download manager

AsyncTask

AsyncTask is a weird kind of class you can implement to have work done in the background of your app, and get updates while it’s being done.

Why it’s weird:

  • Your class has to extend AsyncTask<T, TT, TTT>. That’s three different generic types where you can put any kind of stupid shit you want.
  • The methods you interact with take varargs, so if you’re concerned with doing one job you have this ugly code everywhere :
    protected Long doInBackground(T... stuff) {
        T myArg = stuff[0];
        doStuff(myArf);
    }
    protected void onProgressUpdate(TT... progress) {
        setProgressPercent(progress[0]);
    }
  • You can’t move this weird class in its own file. It has to stick inside the calling code, because it has no callback functionality. setProgressPercent method, which may update a ProgressBar, has to be around.

That’s ugly shit, let’s see about Services

Service

This class, and its simple implentation IntentService looks very Android-y. You implement a Service, register it, and communicate with it with Intents. It handles queing new tasks and the code is clean.

Unfortunately, the service will stop when your app gets paused and you have no way to cleanly stop a task once it’s started. It will also get killed if your app gets Paused, for example when the screen locks…

A way to prevent this is to code a whole new Service from scratch, and make it run in the foreground, using notifications…. Does that looks familiar? Yes ! that’s exactly what DownloadManager is. Do I want to recode all that from scratch ?

Back to HTTP

OKAY GOOGLE

THANK YOU FOR MAKING SIMPLE STUFF TOO SIMPLE TO BE USEFUL

This is my third branch, I’ve refactored all the download managing code three times. I’m tired of trying to circumvent Android deficiencies. I’m defeated (again), I’ll play with your stupid rules.

Asus ZenBook UX303LN-4199H Debian install tips

Boot and configure Windows OEM in order to keep productId, and a restore partition. Gonna help for any warranty or resell. Wifi needs firmware, and you need wifi for the install, so get the debian installer from : http://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/daily-builds/sid_d-i/current/amd64/iso-cd/firmware-testing-amd64-netinst.iso

Working “top line” buttons, in /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi="

Select internal speakers/jack as default sound card (instead of HDMI). In ̀/etc/modprobe.d/something.conf:

options snd-hda-intel index=1,0  # fucking hdmi

Use bumblebee, to make apps use nvidia GPU when needed

apt-get install bumblebee-nvidia primus
dpkg --add-architecture i386 ; sudo apt-get update
sudo apt-get install bumblebee-nvidia primus primus-libs:i386 libgl1-nvidia-glx:i386
sudo adduser $USER bumblebee

Disable instant shutdon in wonsole when accidently hitting the power button instead of Suprr: check your /etc/systemd/logind.conf file. It should look like this:

#HandlePowerKey=poweroff

and change the value to

HandlePowerKey=ignore

Patch for kernel 3.16, to get a “working” touchpad : https://github.com/hanipouspilot/ubuntu-fixes/commit/de3ba763aebbea303f077acfc75952af23b1f38b

And use tutorial on https://wiki.debian.org/HowToRebuildAnOfficialDebianKernelPackage to build your new kernel.

Included in Sid’s kernel as of 3.16.7-ckt9-1.

## NetworkManager

To prevent NetworkManager from managing not real interfaces, edit ̀/etc/NetworkManager/NetworkManager.conf :

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false

[keyfile]
unmanaged-devices=interface-name:vmnet1;interface-name:vmnet8;interface-name=tun0

NetworkManager will warn about /usr/bin/arping not being found:

apt-get install iputils-arping

If you want to be asked for your WPA2 keys, you need to : apt-get install gnome-keyring

Déboires d'un linuxien un peu old-school devant le présent de chez Microsoft

Nouvelle machine, nouveaux ennuis.

J’achète un laptop pour particulier chez une grande enseigne informatique, je rentre chez moi. Avant de l’attaquer au tournevis pour remplacer le disque dur tout lent par un SSD correct, et installer un système que je connais, je le démarre “normalement”, afin au minimum de tester les fonctionnalités de base. Pas envie d’avoir d’avoir des soucis avec la garantie en cas de gros tas de pixel mort.

Je branche je boote

J’ai pas trop d’options différentes, mais j’ai envie de cliquer partout pour tester le trackpad. J’active par mégarde le “Narrateur” qui va me lire tout ce qu’il se passe à l’écran.

C’est chiant. Je reclique au même endroit, le narrateur me pronounce en anglais robotique “Command not available” et j’a une mini-fenêtre qui s’affiche en bas à gauche de mon écran. Le laptop continue de me parler avec sa voix à la GripsouGrishnak quand je fais des choses. Je ferme la mini fenêtre… ouf elle est partie.

Je dis à Windows que je suis un Français de France en France qui parle Français (France).

J’accepte une tonne de légalo-bullshit sans le lire.

Je choisi de nommer donner un petit nom à ma nouvelle acquisition, je mets Choupinette.

Je configure le Wifi en tapant à la main ma clé à rallonge. Dommage que je ne puisse pas utiliser la webcam intégrée pour scanner un QRcode, parceque je m’y reprends à 3 fois.

Je demande la configuration rapide parceque j’ai peur de ne pas être capable de gérer plus compliqué, et que je suis pressé.

Il me demande un compte hotmail avec un magnifique “Connectez-vous pour accéder facilement ŕ votre courrier électronique, vos fichiers, paramčtres…”. Je me dis alors que le Français de France doit être une langue trop exotique. Je crée un nouveau compte car je n’ai pas d’autre options, et les accents reviennent.

Il me demande alors:

  • mon nom, je mets n’importe quoi
  • mon email, je mets n’importe quoi en @hotmail.com, ca me rappelle MSN (T-E-X-T-OOOO génération texto)

Le bousin fait des trucs, avec plein de couleurs qui me permettent au passage de tester d’éventuels pixels morts de l’écran, ce qui est très pratique.

C’est long, et rien ne se passe à part me dire que c’est “Bientôt prêt”. C’est bientôt prêt pendant 5 minutes, puis l’installeur passe en “souris qui attend”. Alors j’attends.

Longtemps.

Très longtemps.

Je me demande ce qu’il peut bien faire de bizarre, et je regarde si l’installeur fait des choses sur le réseau.

Et il se trouve que oui, plein de connexions vers des IP Microsoft avec un port “à la con” (qui se trouve être du teredo) sont bloquées par mon parefeu :

SRC=192.168.3.139 DST=157.56.144.215 PROTO=UDP SPT=54095 DPT=3544

Damned ! J’autorise tout à sortir depuis cette IP, et j’attends… et il se passe pas grand chose.

Du NetBios, de l’ARP, des bricoles, le pointeur de la souris continue de tourner sur lui même.

Pf. 15 minutes plus tard je reboot un peu de rage, quand je m’aperçois qu’en fait mon compte spécial lolilol kikoo msn me sert à ouvrir la session. Quelle idée à la con! Quelle idée à la con numéro 2 d’avoir mis n’importe quoi comme mot de passe dont je ne me rappelle plus.

Pas grave, je demande à Microsoft, via Internet sur un autre poste, comment réinitialiser mon mot de passe, sachant que toutes les informations de téléphone, etc. sont complètement fausses.

Et là magie: il me répond bien gentilment de tout simplement réinstaller mon OS… ce qui va me prendre encore 20 bonnes minutes.

LINKCEPTION

wget "http://tinyurl.com/m7mgdn3"

or

http://tinyurl.com/m7mgdn3

Source code https://github.com/conchyliculture/inception