Bluetooth profile selector [jailbreak]

A little while back I described how to disable A2DP on your iPhone. It required manual modification of some files on the iPhone, which is not for the faint of heart. Now, I have created an application that allows you to change the Bluetooth profiles on a per-device basis. It works very easy.

Bluetooth device selectionBluetooth profilesAbout BTPS

Go to Cydia and look for the Bluetooth Profile Selector application. It is hosted with the BigBoss repository that is installed with Cydia by default. After installation you should see a red box with a Bluetooth icon inside of it.

The application shows all Bluetooth devices that have been detected. Just tap on one of the devices and the next screen is displayed that contains all the profiles that the iPhone can use on that device. The default setting enables all profiles, but you can choose which profiles that you want to enable. When you’re finished, just press the home button and the settings will be applied. During this process the Bluetooth server is restarted, so you’ll lose any active Bluetooth connections for a short while.

You can also download the package here. Put it on your iPhone and use SSH to run dpkg -i BTPS.deb to install it.

UPDATE: Apple has changed something in v4.3.1 and the profile selector cannot be used since then. Unfortunately, I don’t have an iPhone with v4.3.1, so I cannot test it. There has been some people that claim that they can fix it, so you can download the code here.

I received several requests from people if they could donate. You can donate via Paypal if you like:


Clean your mighty mouse

Apple’s Mighty Mouse is not so mighty after all. After some time, dirt will fill up the scrollwheel and you cannot scroll anymore. I did some cleaning by rubbing the wheel over a tissue with some cleaning fluids, but that didn’t work anymore after half a year.

I found this tutorial on the internet that tells you how to take apart your mouse and clean it good. It’s not for the faint of heart, and you will definitely make some scratches on the bottom ring, but you hardly see it after you put it back together. I didn’t use a chisel, but used a small house knive (use at your own risk).

Here are the complete instructions:

Know what your Time Machine is doing

If you use Mac OS X, then you should take a look at Time Machine. It’s a very convenient and easy to use backup solution. The only drawback of Time Machine is that you often don’t know what it is doing. When you dig deeper, you can find out what is happening under the hood.

Console

Mac OS X ships with the Console application (Applications – Utilities – Console) enabling you to view all kind of logfiles. The system.log file contains the information from Time Machine. If you don’t see a file-list at the left of the window, then press the ‘Show Log List’ button and select the proper file. The system.log contains a lot of information, so you need to filter on the apple.backupd string. The logging shows:

  • Where the Time Machine backup is stored.
  • How many space is required for the backup and if it needed to delete old backups to make space.
  • Deleted backups, because they have expired. These are most often the hourly backups of the day before.
  • How many files are copied during this backup.
  • Any errors that occurred when copying the files.

A typical session should look something like this:
Console window

BackupLoupe

Sometimes, the Time Machine backups are very large and you cannot explain why, then probably one or more large files are modified and need to be backed up regularly. Typical examples are virtual machines, Entourage’s datafile, iTunes library, … It’s a good idea to exclude these files or directories from Time Machine, but make sure you backup these files using a different method.

If you want to know what is in each Time Machine backup, then you definitely should take a look at BackupLoupe. It’s an easy to use utility that allows you to peek in the Time Machine backups, so you know exactly what is in each backup. The application costs only €1.49, which can be payed using PayPal. You can try the application for free though, but I recommend to pay for this application. It’s worth it.

Parallel processing

Did you know that the first 3Ghz Pentium CPU was introduced over 8 years ago? When you now look for a state-of-the-art processor, you’ll find the Intel Xeon “Nahelem” CPU, which runs only at 2.66Ghz. From the start of the Pentium processor (66Mhz, 1993) the clock speed doubled almost every 2 years. 10 year later we hit the 3Ghz barrier and since then we haven’t seen higher clock speeds anymore. So what happened since 2002? Well… Modern CPUs can do more in a cycle then the Pentium 4 could, but this is not the major speed improvement. The number of cores per CPU is the big difference. The current Nahelem processor is a quad-core processor, while the Pentium 4 was a processor with just a single core.

The hardware industry choose multi-core as a solution to increase performance. There are only two ways to benefit of multiple cores:

  1. You need to run multiple CPU intensive programs that can run in parallel.
  2. The application needs to take advantage of multiple cores.

Server applications typically handle more requests at the same time, so these are great for multi-core computers. Normal end-users often have only one CPU intensive application running. If the application isn’t written for a multi-core CPU, then the program is running at maximum performance, but only utilizes 50% (or less) of your CPU power. This is a waste of CPU power.

[h2]Why do programmers ignore multi-core[/h2]
Why do these programs don’t use these additional cores? Well… I think most programmers are not used to think about multicore programming, because multi-cores were only common in a server-based applications. Another issue is that multi-threading is difficult. Typical problems of multi-threaded applications are:

  • Race conditions and deadlocks, because multiple threads access the same resources and are not synchronized correctly. These bugs are often very hard to reproduce and to track down.
  • Threading limitations in libraries. Some libraries are not thread-safe or haven’t been tested well on multi-core systems.
  • Single threaded GUI frameworks (Windows GUI applications can only access the UI on the main GUI thread), so you need to synchronize GUI actions. Note that this restriction also applies to Apple OS X applications.
  • Additional coding effort to create and manage threads.
  • Multi-threading has overhead too.

Programmers need to know about these issues and because of constant time pressure, it is easier to ignore multi-threading and perform all work on the main thread. Microsoft and Apple understand to get more power from their systems, they should address these issues. Solving the fundamental problems, such as deadlocks, race conditions, … cannot be solved. It was possible to make multithreading more programmer-friendly and to significantly reduce the overhead.

Apple introduced Grand Central Dispatch (GCD) in Snow Leopard (OS X v10.6) and Microsoft will introduce Parallel extensions for .NET as an integrated part of .NET 4 (which will be released at the end of the year). Both technologies are similar in theory.

Grand Central Dispatch

Grand Central Dispatch was introduced with Snow Leopard (OS X v10.6) in August 2009. Apple claims that only 11 CPU instructions are required to schedule a task for GCD. It is also pretty easy to use. I will provide an example of using GCD (taken from Wikipedia). This is the single-threaded example:

- (IBAction)analyseDocument:(NSButton *)sender {
    NSDictionary *stats = [myDoc analyse];
    [myModel setDict:stats];
    [myStatsView setNeedsDisplay:YES];
    [stats release];
}

Using GCD it will look like this:

- (IBAction)analyzeDocument:(NSButton *)sender
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSDictionary *stats = [myDoc analyze];
        dispatch_async(dispatch_get_main_queue(), ^{
            [myModel setDict:stats];
            [myStatsView setNeedsDisplay:YES];
            [stats release];
        });
    });
}

The document will be analyzed by any available thread, but the GUI will be updated on the main thread (OS X GUI applications need to use the main thread for GUI interaction). As you can see, it’s pretty easy to dispatch blocks of code on another thread. Multi-threading is even more useful when you can use it in loops, like this:

for (i = 0; i < count; i++) {
      results[i] = do_work(data, i);
}
total = summarize(results, count);

Which can be rewritten to use GCD like this:

dispatch_apply(count, dispatch_get_global_queue(0, 0), ^(size_t i) {
    results[i] = do_work(data, i);
});
total = summarize(results, count);

Of course you must rely that all calls to do_work are complete independent of each other, but this code will probably execute up to 4 times faster on a quad-core system then the version without GCD.

.NET 4

Microsoft decided to introduce their technology in .NET 4 instead of the operating system itself. The drawback is that it is only available for .NET based applications, but this will be the majority of the future applications. The advantage is that Windows XP and Windows Vista will also benefit of this extension making it available to a broader audience.

I think the parallel extensions are more thought out than GCD, because they are more elegant to use. I think this applies to the entire .NET framework compared to Apple’s Objective C with Cocoa alternative. The parallel extensions can be used like this:

Parallel.For(0,count, delegate(int i) { results[i] = do_work(data, i); };
total = summarize(results, count);

As you can see, it looks very similar to the GCD approach. The major advantage of .NET 4 is that the parallel extensions are also included in LINQ, called P/LINQ. So the code listed above can also be rewritten as:

data.AsParallel().Select(t => do_work(t)).Count();

Adding AsParallel(). to an enumeration translates the enumeration in a parallel enumeration, which makes it very easy to use.

Conclusion

Using multiple threads is much more convenient and more lightweight to use in Snow Leopard and .NET 4. For complex operations, you will benefit from these technologies, so make sure you are prepared.

Why I decided to jailbreak my iPhone

After owning the iPhone for a while, I was fed up with the closed nature of the device. I wanted to disable A2DP and found out that there was no way to do it. I decided to jailbreak the device to take a look about how to do this and found out that there are numerous other advantages as well:

  • The iPhone defaults to output audio on an A2DP device, when it is in the neighborhood. I want to always use the dock connector, but you need to modify your iPhone settings to do this.
  • Some Microsoft Exchange configurations are configured so your iPhone requires an access code at least once per hour. I use my iPhone often, so this was quite annoying. I installed Exchange Unlock to disable this functionality.
  • Access toggles easily using SBSettings application (available through Cydia) to enable some hidden features of the iPhone (i.e. numerical battery level). You can also access some frequently used toggles (WIFI, BlueTooth, …) much easier or show a list of running applications.
  • You can run applications in the background with the Backgrounder application (available through Cydia). This is especially great when using navigation products that are normally disabled when you are receiving or placing a phone call. Make sure you terminate the application when you really don’t need it anymore to prevent the application from draining the battery.
  • The default battery indication is quite lousy, but you can enable a numerical display. You can enable the SBShowBatteryLevel key in /var/mobile/Library/Preferences/com.apple.springboard.plist file or use a third party tool like SBSettings (available through Cydia). This application also allows to perform some other neat tricks, so make sure you take a look at it.
  • Install IPA files from other sources then the iTunes Store. Install AppSync for OS 3.0 on your iPhone (available through Cydia via Hackulo.us repository). Drag the IPA files into iTunes and you can sync them just like normal applications. The only difference is that you’re not updated about updates of course.
  • Access your phone using SSH, so you get access to the entire filesystem and are able to execute any command on your iPhone.
  • There are numerous other reasons why you want to jailbreak your iPhone. Some people like Winterboard to change the appearance of the phone. I like the default style, so I decided to stick with the normal springboard.

Are there any disadvantages? Yes, there are (unfortunately):

  • Whenever you upgrade your iPhone’s firmware, then you lost your jailbreak and need to start over again. This isn’t a major issue, because iPhone updates aren’t released very often. Always make sure you check if you can jailbreak the new version before you perform the upgrade.
  • Some applications can destabilize your iPhone. I only install applications that I really need and test them thorough. The applications listed above have never affected the stability and battery life in any way. You only need to be careful with Backgrounder, because you can easily leave an application in the background without knowing.