Getting Windows Phone 7 Updates without Flushing ROM

Chris has been doing excellent job with Windows Phone updates. Inspired by his blog post, I have updated my Samsung Omnia 7 to March 2011 update. I intend to describe it in detail how I have done it, because there’s another way you can do it by flashing your phone ROM, which ideally means that it will change your BIOS program, inject the update and disable your phone to receive future updates – it sounds to me extremely risky! However, I was looking for less hackier way.

Warning: There’s no guaranty that it will work for you as well, so do it at your own risk. Jailbreaking may not work further after the update as I cannot install the apps that I built on the phone anymore.

First of all, Windows Phone update is delivered by region, so where you live matters. For example, if you have bought the phone (in my case) from United Kingdom and use in Bangladesh (where not even marketplace has been launched), you are not going to receive updates. That’s certain. There’s an update schedule for USA if you wish to follow when you are going to get your update. However, if you cannot wait, here’s how I have done it.

Step 1: Unlock the phone

  1. You will have to install Visual Studio 2010 and Windows Phone SDK to unlock it. I am a Windows Phone 7 developer, so I already have it.
  2. Follow instruction here how you can unlock it. I am not going to discuss it here, because they probably have faced legal issues with Microsoft with the tools and so on. But it’s very easy two steps procedure. So, I am leaving it to you guys to find it out how to unlock it. It’s out there somewhere in the XDA developers forums. I can tell you up to that. The rest is your super efficient search capability. Winking smile

Step 2: Unbrand the phone

  1. Now that you have unlocked it, you will be able to install Windows Phone apps (deployable .xap files) without needing it to be on the Marketplace. Like Windows, your Windows Phone also has registry, and there resides a key which holds the branding information. You will have to change that.
  2. Grab the RegistryViewer and download it. Run this tool with administrative privilege: C:Program FilesMicrosoft SDKsWindows Phonev7.0ToolsXAP DeploymentXapDeploy.exe. It comes as part of the Windows Phone SDK. Now deploy the RegistryView to your phone.
  3. Open RegistryViewer from the phone. Go to HK Local Machine > System > Platform > DeviceTargetInfo > MobileOperator. Note down its value. In my case it was TMO-GB. That means it is T-Mobile, Great Britain. Set it to 000-88, which basically unbrands it.

Step 3: Fake location

  1. Now you will have to give Zune an illusion that you are seeking an update from some location where it is already available. To do that, connect to a Hungarian VPN. Download and run it. Connect to EUROIP L2TP Hungary, and use username: demo, password: demo.
  2. Plugin the phone, unlock the screen, open Zune.
  3. From Zune, go to Settings > Phone > Update. After a while, there you go “A update is available.
  4. Disconnect from the Hungarian VPN and proceed with the update wizard.
  5. If you have a strict company policy (such as Microsoft Exchange users) that you must have a PIN to unlock your phone’s home screen, you have to do so every time the update procedure restarts your phone.
  6. After you have completed the February 2011 NoDo update, follow the same procedure in Step 3. Voila! You will get March 2011 update as well.

Disclaimer: The procedure mentioned above is as-is, with no guaranty at all. It just worked for me for my specific location and phone. Use this information completely at your own risk. Hope it works for you.

Shameless plug: Forgot to mention that I was awarded Most Valuable Professional (MVP) again by Microsoft for 2011 in ASP.NET/IIS. Thank you Microsoft! Smile

10 C# tips in 140 characters Part-2

OK – I have tweeted 10 more C# tips in continuation of the part 1. Follow the hashtag #csharptip so that you do not miss any. Here they are – see if you find useful.

  • Tip 11: In C# 4.0 you are no longer limited to 4 parameters max in Func, 16 it is. Same goes for Action.
  • Tip 12: From CLR PoV, Stack is where local variables and parameters are stored and removed when not referenced anywhere anymore.
  • Tip 13: From CLR POV,Heap’s where objects reside.As soon as an object is created,allocated in the Heap and returned a reference to it
  • Tip 14: For 10x better performance in random access I/O than FileStream,new MemoryMappedFile and MemoryMappedViewAccessor is in C#4.0
  • Tip 15: MemoryMappedFile facilitates shared random file access across the processes. Use MemoryMappedFile.OpenExisting(“SharedFile”))
  • Tip 16: string.IsNullOrWhiteSpace is newly introduced in C# 4.0, added feature is it allows checking WhiteSpace as well.
  • Tip 17: BitArray is more memory efficient than array/collection of bool, because instead of byte, it stores bit per element.
  • Tip 18: are two variables pointing to the same object instance? use: object.ReferenceEquals(a, b)
  • Tip 19: RegexOptions.Compiled compiles exp to in-memory IL & results 30% faster execution but at a cost of one time slow startup time
  • Tip 20: to avoid the runtime Regex compilation overhead, you can put them all into single assembly by Regex.CompileToAssembly.

Hope it helps.

10 C# tips in 140 characters

Today I have gone on a rampage on C# on my Twitter account, which I would like to share with you here. Follow the hashtag #csharptip so that you do not miss any. I would say it is never an easy job to share programming tips in 140 characters. Hence, I have tried hard to squeeze as much information as into those tweets. I hope you will read it after decompressing. Smile

  • Tip 1: double’s internal representation is base 2 and native to the processor, decimal’s base 10, which is 10 times slower than double
  • Tip 2: double is sufficient for most scientific calculations, whereas decimal is more appropriate for financial.
  • Tip 3: dont digest, catch & throw that arithmetic overflow: var min = int.MinValue; checked { –min; }
  • Tip 4: unlike const, readonly objects you can assign in two places: declaration time as well as inside the constructor
  • Tip 5: you do not need to upcast Animal = (Animal)tiger, but downcast explicitly: Animal animal = tiger; tiger = (Tiger)animal;
  • Tip 6: how do you make internal members visible? adding this: [assembly: InternalsVisibleTo ("Ally")]
  • Tip 7: you can extend another interface with the same method signatures: ICredit : IDebit
  • Tip 8: to implement the same methods of extended interfaces, do it explicitly: ICredit.Charge(decimal d) and IDebit.Charge(decimal d)
  • Tip 9: you can add implementation specific method body without virtual-override, using new: public new int GetHashCode()
  • Tip 10: use default(T) for generic type initialization and comparison for you do not know if it is going to be reference/value types

Again, do not forget to follow me on Twitter: TanzimSaqib

A brief introduction to thinking efficient algorithim design

Computation heavy algorithms cost more money before optimized. You can feed your server systems enough RAM and CPUs to handle the CPU cycles and memory they require. This is not one of the most recurring investments and generally good for the application it is serving overall. If you are developing Smart Client/Desktop applications, your software can take as much as it can as long as it is running. However, in two cases careful software design can save (saving is earning) obvious money.

Windows Azure – if your application demands more resources than it should (may be after refactoring and performance tuning), the more users you will start to captivate, the more the cloud resources will be used. Therefore, you will have to pay extra bills.

Windows Phone 7 – Even though Microsoft set quite high bar on system specification as minimum, you will start to see your apps suffer if you take the liberty to use the system resources without considering efficient design. Given that there is no relational database on-device, you have to do a lot of XML parsing and string processing as part of local data support such as user settings. The more your apps suffer in performance, the more you will eventually receive negative reviews and possibly the more you will be losing customers.

Let me tell you beforehand that this article is based on pure fundamental data structures, yet I have tried to give a Windows Phone and Windows Azure flavor lest developers should miss it. Everybody talks about new features, but this topic was needed to be brought to developers’ attention for our very nature of getting hands on the code first.

The Problem

String algorithms are usually very costly, yet easy to understand. I’ll pick up a random string related problem here, and walkthrough step by step how to optimize it. Assume you are building a Calculator app (I know this is no exciting sample case), however, unlike real calculator, user will enter the full expression as string at once, and you will have to parse and say that the brace usage was correct or no. For example:

{1+[2+(3+4)]} Correct
{(3+5)-[2*1]} Correct
{3+5}-[2+1] Correct
(2+[3+5)+1] Incorrect

The Ad-hoc Solutions

It can be solved in couple of ways. One of them could be running an index on the string from one side and find the matching braces from the other side running another index.

Ad-hoc1

Another way could be running two indexes from the same side. Once a brace has encountered, the other index moves ahead and try to find matching brace immediately after.

Ad-hoc2

In both the designs, we are running a loop through the whole string for each brace we encounter. This means in worst case, these algorithms can run as high as O(n^2) and for large enough strings it will run pretty bad. For example, for a 32KB string, it may take 1073741824 condition checks.

Stack-based Solution

In order to improve from the prior designs, we need to reduce one of the loops. We cannot remove the first loop which basically starts from one direction and finds braces through the whole string. But we will get rid of the other loop using a clever data structure.

Stack is one of the most popular data structures, which is suitable in many design problems, such as this. It is a data storage which ensures First In Last Out (FILO) principle, meaning that items can be retrieved from the storage exactly in reverse order of entry. So, we will loop through the string, start extracting braces from one direction and as long as no matching brace is found, we will keep pushing them to the Stack. However, if we find braces facing opposite direction, we will pop from the Stack, compare and proceed.

Here is the algorithm:

BraceMatch

The runtime of this algorithm is O(n), which means, number of comparisons it will make in worst case is linear to the number of characters the string has, which is incredible performance improvement over ad-hoc solutions that we have considered with complexity O(n^2). So, next time you build a Windows Phone app, think about efficient string handling and general performance improvement can be achieved through better design for lack of relational database and other hardware specific limitation.

Do not just jump right into the code. Design first, and better, code later. It is even more necessary than useful in handheld devices and the cloud where CPU cycles and memory aren’t cheap.

Trying out WordPress app for Windows Phone 7

Hello, I am writing this post from WordPress app for Windows Phone 7. It is looking pretty good. You can add media, and do some basic formatting such as bold, italic etc.

I am not sure I will use this for posting many a times, because most of my posts are based on programming or such. However, I will obviously use this app to manage the comments. One big downside is that it does not support landscape orientation which makes typing little inconvenient. Overall ot pretty good.

Posted from WordPress for Windows Phone

Getting to Know Windows Phone 7

I hope you already know that the long awaited Windows Phone 7 is out. This is the Microsoft’s latest mobile operating system everybody was waiting for. As usual this is just an OS, not a Zunephone or not a standalone device like iPhone. Microsoft believes in freedom of choice especially in the case of hardware. They also believe same software excellence can be delivered without selling a dedicated device. Rumor has it they are going to release a massive update to Windows Phone 7 in January 2011, which can be treated as large as Windows Phone 8. And I believe Microsoft will continue to push such updates without abandoning your existing Windows Phone 7 devices, which is nice in comparison to world’s one of the most popular smartphones. Let’s take a quick tour around the phone. Slide1

Microsoft has come up with a brand new concept of phone. They have taken nothing from the predecessor or the competitors. This is a completely new start in terms of user interface and user experience. They are calling it Metro. We will talk about it later on. There are applications and there are also hubs which we will see in a while.

Bing has been used not only as a search engine, but also as a decision engine. Windows Phone OS set the bar for hardware requirements quite high, and it’s only fair in order not to compromise the experience throughout the devices from many different vendors.

Developer’s Choice

The true surprise for the developers was the choice of paths. There are two ways to develop a Windows Phone 7 app, using Silverlight runtime which is basically Silverlight 3.0, and XNA runtime, for developing Games which is subset of the XNA Game engine.

Slide2

Metro UI

Metro UI is a design language and it is a result of hard work Microsoft Research has put behind for years. The special feature of Metro is there’s always less irrelevant graphics. It is mostly text based. It is a consistent design pattern which presents information in perfect color, font and size combination, so that you can quickly glance and go.

Hubs

Like all the smartphones out there, there are apps in Windows Phone, but there are other things which are known as hubs. Hubs are basically collection of relevant apps grouped into a tile. When you glance the tile, it takes you to the page where those apps are found in integrated fashion. Now, if you look at the People hub, you will see there are recent contacts, you can swipe left or right to see other parts of the hub. There you see alphabetically sorted contacts with Facebook status tied to them as well as the text messages that you have exchanged. You can also search and add contacts.

People

Music

Another hub is Music + Videos. As you can expect you will have all sorts of multimedia including FM Radio and Podcasts are here integrated into this hub. Similarly you have Pictures, Games with XBOX Live integrated with it, as well as Office Productivity suite.

Bing as a Decision Engine

Let’s take a look at how they have integrated bing service into the phone. It actually helps you to take decisions. When you type niagara falls restaurants, it automatically recognizes that you are hungry and looking for a restaurant to dine. There you go the list of nearby restaurants on the map along with their ratings and address.

Bing Slide9

Let’s take a look at the hardware spec they set as minimum. The reason was to assure user that they have absolute freedom to choose any device, because it will deliver certain level of experience that Microsoft thinks user will not complain about.

The complete episode is on CodeTV: http://codetv.net/41/getting-to-know-windows-phone-7/

Full source code of the News Framework has been released

I have released full source code of the News Framework on Oct 25, 2010. You can grab it from here (external).

Those who are unfamiliar with the News Framework here is a summary. News Framework is an open source (to be released in a while) offline news reading framework on which any RSS based news website can have its own Windows Phone 7 application in just minutes. The configuration, content and styles can be managed from outside of the framework itself to fit the needs.

Feature list of this framework can be found here (external).

Video demonstration here (external).

Getting started guide here (external).

Project homepage here (external).

Latest source code here (external).

Welcome to my new home

I have been deciding for a while to build my new home to get rid of the http://weblogs.asp.net/TanzimSaqib blog that I had. The major motivations for moving away from weblogs.asp.net was the annoying advertisements and the inflexibility of the blogging platform as far as the permissions given to a normal user. With my new blog, I have full control over as to what appears and what not as well as a lot more space to utilize.

Here are a very few blog posts that I made there for the record: