Samstag, 20. Juli 2013

Android's Package Download

Recently I have asked on several forums (XDA Developer, Stackexchange) how the Android package download works. I got no useful answer. First the bone heads at Android Enthusiasts did not understand my questions and after they got it, they closed the questions, because the topic has nothing to do with Android (roflpimp). At XDA Developer I was not able to ask the question in the right section, because I had not written enough junk to be qualified for the right sections.

You see I had to figure it out on myself. I configured an ALIX board as an wireless access point connected my old Cyanogen 7 Defy and started an update. I captured the traffic with Tshark and analyzed it with Wireshark.

The Android 2 client does two requests for a package update. The first request gets answered by an redirect and the second starts the download. This is the first request.

And this is the second.

First the client contacts the host and requests something from /market/download/ and after that the client contacts some random host in a probably random sub domain below and requests something from /market/GetBinary/. The traffic is not encrypted. This makes to possible to block the package download without breaking other Google services.

This is an example configuration for Squid.

acl apps url_regex "/etc/squid3/apps.url"
http_access deny apps
deny_info TCP_RESET apps

The file with the regular expression contains only one entry.


Successful blocks are marked as TCP_DENIED in the log file.

1374352802.189      0 TCP_DENIED/403 0 GET - NONE/- text/html

Donnerstag, 11. Juli 2013

Renaming inheritance relations with Rhino in Oracle´s SQL Data Modeler

The default naming rule for inheritance relations is a simple enumeration.

  • Hierarchy_1
  • Hierarchy_2
  • and so on...

Recently I had the problem to clean up an existing model. This can be done by hand but it is a very annoying job. Oracle´s SQL Data Modeler includes Mozillas Rhino engine to perform automatic tasks on the model. It is much more convenient to unify the relation names by a script. The following script does the job.

var entities = model.getEntitySet().toArray();
for (var e = 0; e < entities.length; e++) {
    var entity = entities[e];
    if (entity.isInheriting()) {
        var relation = entity.getInheritanceRelation();
        var source = relation.getSourceEntity().getName();
        var target = relation.getTargetEntity().getName();
        relation.setName(source + "_" + target + "_ih");

The new names are created by the name of the source entity and the name of the target entity separated by an underline and suffixed by "ih".

The documentation of the classes and methods available from JavaScript is quite limited. But the file datamodeler/xmlmetadata/doc/index.html in the Data Modeler package list all of them and it is possible to use the debugger repl to test their functionality.

Mittwoch, 10. Juli 2013

Abuse inheritance for embedding with SQL Developer

Creating relational models in SQL is often a very annoying job, because of the limited expressiveness of the relational model. Thanks to PostgreSQL it is possible to create inheritance relationships between different entities. But the object oriented world spurns more and more inheritance. Inheritance was invented to reuse code but after Barbara Liskov formulated her substitution principle most object oriented disciples bless embedding instead of inheritance. Evangelists like Google´s Go banish inheritance at all and allow only embedding.

Never the less Oracle´s SQL Developer does not know anything about embedding and provides only single inheritance. The following example shows how to use this for embedding. I would like to created objects in my database which timestamps. A "creatable" should have a create time stamp, a "deletable" should have an additional delete time stamp and a "modifyable" should add a third time stamp. This is the logical model:

The engineering strategy "one table per child" results in a relational model with only one table.

The attributes of all ancestors are merged into the table. Whenever I need the three time stamps I can specify the inheritance without the need to add them manually to the entity.

But one thing is still annoying. The columns are prefixed with the abstract table names, which leads to unnecessary redundancy in the name of the columns. I did not find a way to suppress this naming style but I found a way to fix the names by writing a custom transformation script. SQL Developer embeds Mozilla´s Rhino engine, which provides a way to manipulate the engineered model. The following script removes the table prefixes from the three columns.

function set_name (object, name)

tables = model.getTableSet().toArray();
for (var t = 0; t<tables.length;t++) {
    table = tables[t];
    tname = table.getName();
    columns = table.getElements();
    for (var c = 0; c < columns.length; c++) {
        column = columns[c];
        cname = column.getName();
        if (m = cname.match(/.+_((CREATE|DELETE|MODIFY)_TS)$/))
            set_name(column, m[1]);

Freitag, 5. Juli 2013

instanceof in Java

Javas instanceof Operator ist nicht nur wahr für die Klasse der ein Objekt angehört sondern auch für sämtliche Elternklassen. Das folgende Beispiel
class instance
  static class A {}
  static class B extends A {}

  static<T> void println(T arg) { System.out.println(arg); }

  public static void main (String[] args)
    A a = new A();
    B b = new B();
    A c = b;

    println (a instanceof A);
    println (a instanceof B);
    println (b instanceof A);
    println (b instanceof B);
    println (c instanceof A);
    println (c instanceof B);
generiert die folgende Ausgabe:
$ javac -cp . -Xlint:unchecked && java instance
Lediglich Objekte der Elternklasse sind keine Instanz einer Kindklasse.