Writing apps for the N900, part 2 — packaging

Here’s a list of all these posts, which I’ll keep updated as I add new ones.

Matters arising from last time. A number of people asked, in the comments here and on Y Combinator, whether the change to using Qt instead of GTK in Maemo 6 will mean that Maemo 5 apps will need to be rewritten. I think it’s understandable that the switch will make people ask this question, but I don’t foresee any problems. If you want to write Qt applications, you can write them now under Maemo 5 and they’ll run; if you write GTK applications now, they will still run under Maemo 6 when it comes out. The GTK libraries won’t stop shipping with Maemo just because Qt becomes the primary toolkit.

Work behind the scenes. Today we’re talking about packaging. The version of raeddit we wrote last time downloads all the data from reddit and then puts up a window. If you’re on a slow connection, this could take several seconds. The Maemo guidelines say programs should put up a window as soon as possible, and indeed if they don’t put one up within a fairly long amount of time, the desktop assumes they’ve stalled and puts up a message to tell the user there was a problem.

So I’ve modified raeddit to put up the window immediately it launches, and to load the data in a separate thread. I was simply going to put up one of those whirly “please wait” symbols in the titlebar, but my ten-year-old user interface consultant told me that percentage-loaded bars are much more helpful. So I made the change to version 04 (diff to version 03), but since it has little to do with writing Maemo apps in particular, I’m not going to go into great detail about it. This also involved a slight change to the reddit client library, so that it could call a callback every so often to update the progress bar. The new version is backward-compatible with the old.

Where to find the files. The files we’re going to talk about are at the link; if you’d like a local copy you can get one with

git clone http://www.gnome.org/~tthurman/pics/maemo/raeddit-04/.git

So, packaging. Packaging under Maemo isn’t much different from packaging under Debian or Ubuntu. I said last time that I wasn’t going to replicate the contents of existing tutorials, and there are plenty of good packaging tutorials out there. But I’ll bend the rule a little in order to tell you what I changed to turn this into a packaged program.

The Makefile. Last time we were compiling by hand, but now we need the package to be capable of building itself. We could use autotools, but we’re trying to keep things really simple. So here’s a simple Makefile that knows how to compile and install the program.

But what do we need to install?

  • The compiled binary itself, into /usr/bin.
  • A desktop file, into /usr/share/applications. This tells the desktop where to find the program, how to launch it, and what the icon is. The moment you drop the file into that directory, through installing the package or otherwise, the desktop will pick it up and add it to the menus. The file is pretty straightforward, but if you want the full details you can read the spec.
  • The reddit alien An icon for the desktop file to refer to. We’ll use the obvious candidate– the reddit alien– and hope the reddit admins don’t mind us borrowing their logo to refer to their site.

The debian/ directory. That’s all very well, but we also need some instructions about how the package should be put together.  These live in the debian/ directory. There are only three you really need to concern yourself with:

  • debian/rules is another Makefile to explain how to package the program. (Now you understand the in-joke with that shirt). I’ve been using the same debian/rules with minor ad hoc tweaks for a while now; you can probably adapt it.
  • debian/changelog needs to say, at the very least, the date, your name, “initial release”, and that this is (say) version 0.01.
  • debian/control is mostly self-explanatory, but there’s one thing you need to know…

Adding an icon to debian/control. If we added the basic package to App Manager, it would appear like this:

Package in the Maemo repository

The blue square means that it doesn’t have an icon. App Manager isn’t going to download and unpack every package just to see whether we’ve included an icon, so we need to include one in debian/control, which will make its way into the package index. However, there’s not as much room, so it needs to be just 26×26. We’ll just show the alien’s head: All we have to do to get it into debian/control is to uuencode it (producing this result) and then put it into debian/control, indented by one space, under the heading XB-Maemo-Icon-26:. (No, I don’t know what the B is for either.)

This makes our entry in App Manager much prettier:
Package in the Maemo repository

Building it. So now all we need to do is to run dpkg-buildpackage on our package, copy it to the phone, and install it. Rather than show how to do that here, I’ll just show you a log of me doing it, since it’s quite a mechanical process.

Firing it up. And now we can load the program from the ordinary menu and run it. I would show you screenshots, but I think screencasts are far more fun. So here’s a quick video on YouTube of raeddit in use. I’ve added the current version of raeddit, such as it is, to maemo-extras, so that you can actually install it with App Manager if you feel so inclined.

One quick plug: if you’d like to see a longer screencast of a more advanced Maemo 5 program, I’m working on a location-aware system to find nearby belltowers hung for English full-circle change ringing. It uses the database from Dove’s Guide. You can see a screencast of the work in progress here.

Next time, when the user clicks a post, instead of going straight to the linked site we’ll figure out how to put up one of these menus:

Example of a Hildon selector

After that, who knows? I added a long list of possibilities to the previous post, so feel free to advocate as to which you’d like to see fixed first.

Published by

Thomas Thurman

Mostly themes, triaging, and patch review.

22 thoughts on “Writing apps for the N900, part 2 — packaging”

  1. Do you guys do ANYTHING about isolating apps from each other and restricting them from doing Bad Things, such as Android and the iPhone do?

  2. edit: or have plans to do so? I’ve been downright curious about the proper way to approach this issue on Linux. Android sort of hacks up user accounts to accomplish it. Which really work well, by the way. Very well. Just makes it unable to be used as a real multiuser system. Maybe that’s okay though?

  3. So, you basically “forked” debian/control, with your own sections, Standard-Version and new fields?

    Have you thought about cooperating more with the Debian community?

  4. @Faidon, @Jerome: Adding a “XB-” header is not a fork but the defined extension headers’ prefix. Please read the Debian packaging policy plus Wikipedia for the definition of “fork”.
    And for future reference please don’t post complete nonsense.

  5. I’m well aware of what XB- fields are, what a fork is (there were quotes for a reason), and I’m perfectly aware of the Debian packaging policy, probably better than you are (I’m a DD).

    Your comment doesn’t help and neither is your attitude.

  6. @Jerome: I’m not “you guys”, I’m just writing this as an individual. I’m not sure I understand the question, though: why are processes more likely to interfere with one another on a phone than they are on a desktop machine?

    @Faidon: I don’t know; I didn’t design the Maemo packaging policy. I’m just writing this as an individual. You could ask on http://talk.maemo.org if you want to find rationales for the way things are done.

    @Marius: Thanks.

  7. Thomas:

    Because given a market where apps are published in, with users not capable of making security decisions, people will publish apps that create bot nets and other undesirables. It will happen.

    Android runs each individual application as it’s own uid, and upon installation, you are prompted to allow that application to have access to only some very limited capabilites: “can send SMS messages”, “can read contacts”, etc. The UID is added to a set of groups which express those. And it cannot extend beyond them. Any access to data is done through IPC APIs which can restrict access.

    The OS will also terminate the app if it consumes excessive CPU, and a host of other protection features. The last thing you want is random apps installed by users to generate support calls to the carrier… interfere with people’s phone calls. Etc. Both the iPhone and Android have thought this through very well.

  8. If you can use debhelper 7, then your entire sample debian/rules can be replaced by:

    #! /usr/bin/make -f
    dh $@

    You can use all the standard debhelper-related files in debian/, and if you need to override the behaviour of one of the commands that dh calls, then just add an override_dh_foo target. This saves on a lot of cargo-culted boilerplate without making it unreasonably difficult to figure out where to make customisations when they’re necessary (speaking as a Debian developer who’s been cargo-culting the last debian/rules he wrote each time for the last ten years or so …).

  9. > Do you guys do ANYTHING about isolating apps from each other and
    > restricting them from doing Bad Things, such as Android and the iPhone do?
    Yes, google has created so crappy platform that I’m restricted from running my favorite Pidgin and OpenTTD on their pltform at all. How nice to lock-out device owner outside his device for his own moneys. Surely, that’s so cool to get jailed and use your own moneys to pay for all costs related to this procedure.

    Actually, n900 is a *computer*. *Real* one. Like, say, notebook. But smaller. With ability to run apps from your Linux desktop. Not a java toy from Google which is a useless brick at the end of day.

    Now one question: will you ever buy PC if it’s crippled so you can’t be Administrator (root, or whatever) in your OS and can’t install programs on your own and have to write them on Java only and all from scratch and run them in slow VM machine because PC manufacturer does not trusts you to access your bare metal while it is you are who payed for this metal after all?

    That’s what separates useless java toy from a self-sufficient computer.

    And yes, if you’re granted full freedom, you’re free to do various things. You can even grab a gun and shoot yourself into the leg if you want to. Or you can do another things if you want. Some of them will even make you appear on DarwinAwards.com – and that’s freedom we all must have.

    Jailing you and handcuffing just to prevent chance you can shoot yourself into the leg is a brutal violation of your freedom, after all.

    Google tells something equal to this: “We will not allow you to harm yourself! So, we will jail you, handcuff you and policeman will stand near your ass, 24/7. That’s for your own safety. Luke! So, be happy – you’re now totally safe – nobody can harm you in our heavily guarded jail!”.

  10. > Because given a market where apps are published in, with users not
    > capable of making security decisions, people will publish apps
    > that create bot nets and other undesirables. It will happen.
    Does all this mumbling means that Google’s devices are intended for idiots and FOR IDIOTS ONLY? No, dude, if you’re about to drive a car, you have to learn a set of simple rules. Rather than get forbidden to drive a car or being forced to hire personal driver, personally provided by Google, inc. So, that’s where Google’s logic flawed.

    And after all, if someone going to shoot himself to leg, we must not handcuff him and jail him to prevent this (since this will restrict person’s freedom). We only should make sure he is not going to harm others with his gun and punish him if he does (so he do not wants to harm others due to risk of punishment). And that’s up to ISPs to disconnect hacked users, just like police should catch people guilty in a crimes.

    P.S. actually, botnets are quite hard to create because repository is still being run by NOKIA and bad thing will have certain problems at this place. And installing bad apps from another sources is a bit harder and gives warnings. If user is determined to play Russian Roulette, we’re not in position to jail him to prevent it. Look, on my PC I can install whatever I like. Why can’t I do the same on my n900? What’s the difference? Both are computers and both are connected to networks.

Leave a Reply

Your email address will not be published. Required fields are marked *