WinRT License API, Silverlight 8.1 apps and sideload detection #wpdev

Since early 2011, I have been using the method described here.
Recently I have been upgrading all my apps to target Windows Phone 8.1 API. Most of previous API is still accessible in WP 8.1 SL8.1 apps. However a great deal more is available under WinRT API.

With my Alarm Clock app, I have started using WinRT API to pin and update Tiles. I have used WinRT API for background tasks as I can run them more frequently and I can detect Timezone change. I have added IAP to the app.
The app however is available in 2 flavours Free (with ads and restrictions) and Paid. So far I have only been updating the paid app. Of course I use sideload detection for Paid app however while considering update of Free version, I decided to use CurrenApp to execute License check and potentially offer to convert Free users in-place as opposed to getting them to buy another app!!

In good old SL API, I would have used

var license = new Microsoft.Phone.Marketplace.LicenseInformation();
IsTrial = license.IsTrial();

With WinRT that becomes

IsTrial = CurrentApp.LicenseInformation.IsTrial;

While developing and deploying if you observe the behaviour, the IsTrial never returns false. You cannot test Trial scenario without explicit pre-processor directives!
Of course CurrentAppSimulator is only available for WinRT app and not SL8.1 apps. The same behaviour would be exposed by the sideloaded apps. Not downloaded from store equates to full version. Like in good old days, WMAppPRHeader.xml is still attached after certification. So lets modify the code

try
{
   XDocument doc = XDocument.Load("WMAppPRHeader.xml");
 
   IsTrial = CurrentApp.LicenseInformation.IsTrial;
}
catch
{
   IsTrial = true;
}

You treat all apps without WMAppPRHeader.xml as trial. Job done!
Note that IAP are not affected. If you had TestIAP, it is not active by default.

CurrentApp.LicenseInformation.ProductLicenses["TestIAP"].IsActive;

Happy coding!

DLL / Reference hell with #WP8 #SL81 and #WinRT component

Over the last month, I have gone back to “AlarmClock” app (my 3rd Windows Phone app from back in 2011). I have updated it to render time updates on live tile. In fact I am quite proud the mechanism I use. I additionally provided 50 downloadable font packs that users can choose from (purchasable in a set of 10).

Original solution
The update mechanism was initially based on Silverlight Background Task. The tile update mechanism of course updates tile based on local time. However a user reported that when travelling between timezones, the tiles kept showing previous timezone times until the next background task run started pushing new ones based on new local time.

I deliberated on this and came to the conclusion that somewhere something was fishy.. its possible that Tile updates are actually scheduled on UTC as opposed to local time or maybe I just don’t understand it. Either way, I had to fix this issue

Solution 2: Fix for Timezone change
The new windows phone 8.1 introduced a bunch of new WinRT API that included API for Background task including those that run on Timezone change. So I dumped SL based Background Task and went full stream with WinRT component. Added 2 WinRT classs on for Timer and another for Timezone and this worked great.

Another user wanted the clock and tile updates to support multiple Timezones – wanted to pin Hong Kong and Seattle. My app so far only supported local device timezone.

Soluion 3 – Multiple Timezone support

.NET 4.5 comes with TimeZoneInfo class.This provides a nice method GetSystemTimeZones which lists all timezones and make it possible to convert between those. However Windows Phone .NET Runtime does not come with this and there is not suitable WinRT API either. Yay!!
Oren Novotny created a good Win32 wrapper which works on both WP8, WP81, SL81 and WinRT
I fired up Nuget Package Manager and searched for timezone..found Timezone conversion between WinRT and PCL.. Added a reference to the App and reworked it to support user selectable timezone etc. This required me to select target between x86 and ARM – any CPU no longer an option.

Next step?? Add Timezone helper reference to WinRT component. Bang bang bang.. nugget sorted it all out.. that was easy.. modified the background processor to update all tiles with correct timezone times!! nice :) What could possibly go wrong ?

Hit F6, (Old school.. modified VS 2013 to build o F6 like before).. all good. Hit F5… wait for it !!!!

Runtime exception – File not found System.Runtime.InteropService.. quick search showed reference conflict..

Step 1) Set WinRT component to x86 instead of Any CPU.. maybe that will do the trick!!!

Nope far from it… Result System.BadImageFormatException thown when trying to run the app.

Step 2) Download code and make a part of existing WinRT component..

Nope still the same error(s)

While deliberating, realised that I called code from Background Task directly from my app.. 3rd trial

Step 3)

Remove calls to code in Background Task from App
Nuget Reference to App
Code within WinRT component for internal use
App – x86 / ARM target
WinRT component – Any CPU tagt

Bingo.. It all work as advertised!!

Took me day to figure try out various options

End of line for CineworldMetro

Last night I did something I wasn’t sure I should do!! I removed (unpublished) my cineworld app from Windows Phone and Windows 8 stores.

In just over 2 years it has had 90K on phone and 40K on Windows8. It has come a long way and like a few other of my projects, it gave me a chance to try various scenarios in terms of design and performance.

Sadly one thing I never thought significantly was sustainability of the app in long term. My azure hosting had been free till date and from next week I start paying real money towards it. I have spend many many hours towards its dev and since the app doesn’t make any money for me so I can’t justify giving it a life line.

It has been good fun. Thanks for all the fish.

Lumia 930 – 1 week on #ConnectsTrial

For good part of last 6 months, I ensured that I took a moment to bug @Connects team w.r.t Lumia 930. Of course it wasn’t available back then.. they knew it, I knew it but that had to be done. I even reminded them that they never sent me a 1520 to review :) and I suppose it worked :)

On 14th of this month, I got an email stating that they have 930 and I could be the first one to get my hands on it.. quickly filled out the form.. bang bang.. they dispatch the device the next day. I patiently waited good part of the morning for DHL to bring it in… At noon, I get an email stating package awaiting to be collected!!

The packaging isn’t brick box like earlier Lumia models but a flatter version like the one for Lumia 630.. I suppose this is the packaging for gen 2 devices.
930-Pic1 930-Pic2 930-Pic3 930-Pic4

The device is striking.. even without switching it on that much is clear.. the screen reminds me of Lumia 800’s curved glass and it is ever so slightly curved. The aluminium and the back shell remind me of Lumia 925 but its significantly flatter.. in fact the dimensions of 930 are about the same as Nexus 5. The back is tapered to give a feeling of thinness. I am not a big fan of green but I’d take the green or orange models instead of white or black ones. The green gives a nice neon lightening effect on a white table.. it is remarkably pleasant.

The first thing I did after powering it on was restored a Lumia 1020 backup on it. The device did warm up during this time and while all Lumia devices do warm up, I think aluminium chassis aids heat flow. The AMOLED display is just gorgeous.. At 441 dpi, it is significant ahead of any other devices out there oh and its full HD – 1080p. The device use Snapdragon 800 chipset and comes with 2GB of RAM. The outcome, its snappy.

It comes with 20MP CMOS as opposed to 40MP CMOS in Lumia 1020 but the combination of faster SoC and smaller CMOS means that taking pictures is a pleasure.. Here is a test capture showing speed differences.. both 1020 and 930 are set on 10 second delay.. I have tried best to tap at same time

the lens in 930 is wide though not as much as that of 1020. min focus distance is similar to that of Lumia 1020. You can view some of the pictures I have uploaded and judge for yourself

https://www.facebook.com/media/set/?set=a.10152213561226921.1073741827.543056920&type=1&l=d8d7d8ce45

The battery life is similar to that of Lumia 1020.. my usage gives me just enough to last through the day. I have occasionally seen it warming up but I think a firmware might be due to fix that issue. Another side note, on a white background, I have seen the screen flicker a bit.. again a firmware update should sort that out.

I did power my 1020 a few times and I find it offensively slow and laggy. except for the 40 MP sensor I don’t cant think of anything that would pull me back.. I would trade it all in for a Lumia 930. Infact I am seriously thinking how on earth are @Connects team planning to get this device back.. they really think I am joking.. sigh.. I suppose they are in for a surprise :)

 

App tile transparency for WP8.1 apps #wpdev

One of my popular lines is “Don’t throw shit around.. what goes around comes around!” and rightly so. A few weeks back I was making fun of @dvlup for blogging about how to create transparent tiles for the WP apps :)

I know the irony isn’t lost on me. The idea is with WP8 apps, you create tile images which are transparent png with white bits.. if you had a star or a clock that would be white, the rest would be transparent and you used this. This would make your app’s tile transparent and if you had a fancy background, you would see through the tile.

Fast forward today, I was testing WP8.1 update to my alarm clock app. What does it do ? well shows you tile update every minute with a nicely rendered tile. and yes I made the tile transparent. But the tile comes up as grey.. WTH

alarmclock1

so I start looking around and I remember that Windows 8 app manifest had a background color, Open the Package.appmanifest and I find this

<m3:VisualElements
    DisplayName="AlarmClock"
    Square150x150Logo="Assets\SquareTile150x150.png"
    Square44x44Logo="Assets\Logo.png"
    Description="AlarmClock"
    ForegroundText="light"
    BackgroundColor="#464646">

hmmm no alpha value to make it transparent. So I tried to set BackgroundColor to Transparent.. nope.. transparent ? Bingo!!

<m3:VisualElements
    DisplayName="AlarmClock"
    Square150x150Logo="Assets\SquareTile150x150.png"
    Square44x44Logo="Assets\Logo.png"
    Description="AlarmClock"
    ForegroundText="light"
    BackgroundColor="transparent">

alarmclock2
Now if you used transparent png for tiles, your WP 8.1 app’s tiles are transparent.

Image scaling related crashes on 1080p devices #wpdev

Back in March one of the 1Shot camera app users emailed me stating that the app crashes when using he uses digital zoom on Lumia 1520. I couldn’t reproduce the issue on my 1020. I then borrowed a friend’s 1520 and hmm sure I could reproduce it but I couldn’t catch the exception.

So we left it at that.. fast forward on Friday I get a mail back from chap in question and he states that he’s running latest greatest version of preview and the freaky crash is still happening. Luckily I have the 1520 at my desk and decided to put it to good use over the weekend.

So I put VS configuration in Debug mode and I set VS to catch all thrown exceptions. Run app and swipe left right and top bottom and every so often the app crashes.. no exception being caught.. the app just disappears and we are back to home screen. The only clue was the output of debug mode.. The program ‘[4880] AgHost.exe’ has exited with code -1073741819 (0xc0000005) ‘Access violation’.

The sad reality, the debug output is littered with messages starting ‘AgHost.exe’ (CoreCLR: Silverlight AppDomain): A quick check on the net showed that AgHost.exe is used to manage access through identity verification.. great. The error code wasn’t particularly useful either.

In this particular case, the error only occurred when zooming in. My implementation of digital zoom was scaling the preview image for the live view. The only action associated with crash was zooming in and out. As it happens, I detect manipulation delta and compute scale..

private void LivePreviewTapTarget_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
    if (!this.viewModel.CaptureInitiated && AppSettings.InternalAppSettings.DragZoom)
    {
        SetDragToScale(e.CumulativeManipulation.Translation);
        e.Handled = true;
    }
}

void SetDragToScale(System.Windows.Point pScale)
{
    double x = Math.Abs(pScale.X);
    double y = Math.Abs(pScale.Y);

    double manipulation = x > y ? pScale.X : pScale.Y;

    bool zoomOut = manipulation >= 0 ? false : true;

    double scale = (this.viewModel.HasHighResolutionCamera ? 0.01 : 0.005) * Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));

    if (zoomOut)
        this.viewModel.ViewScale = initialScale + scale;
    else
        this.viewModel.ViewScale = initialScale - scale;

    System.Diagnostics.Debug.WriteLine("zoomout {0}, scale {1}", zoomOut, scale);
}

My initial thought was that it being a newer SoC, the Xaml Renderer was somehow being proactive somewhere and getting itself in a mess.

Test 1: show less frames and show larger jumps so there is less rendering. For High Res camera I used constant of 0.01.. increase it to 0.05.

The resultant build crashed very very fast. hardly took a swipe or two to head back to home screen.

So I wanted to try the reverse but by laptop decided to shutdown and I was too knackered to continue yesterday.
Earlier today I had a chat with Bill Reiss.. he mentioned that he had some problems with 1520 too and that it had something to do with how large the image becomes on 1080p screen.

So I decided to continue where I left yesterday but with a reduction only for 1080p devices.
Test 2: reduce the multiplication constant to 0.0015 if a 1080p device is detected.
Result: Significant reduction in crashes.. I can still get it to crash but not that often. Here is the changed version

int DeviceScaleFactor = -1;
private void GetScaleFactor()
{
    object physicalScreenResolutionObject;

    if (DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out physicalScreenResolutionObject))
    {
        var physicalScreenResolution = (Size)physicalScreenResolutionObject;

        DeviceScaleFactor = (int)(physicalScreenResolution.Width / 4.8);
    }
    else
    {
        DeviceScaleFactor = Application.Current.Host.Content.ScaleFactor;
    }
}

void SetDragToScale(System.Windows.Point pScale)
{
    double x = Math.Abs(pScale.X);
    double y = Math.Abs(pScale.Y);

    double manipulation = x > y ? pScale.X : pScale.Y;

    bool zoomOut = manipulation >= 0 ? false : true;

    if (this.DeviceScaleFactor == -1)
    {
        this.GetScaleFactor();
    }

    double scale = (this.viewModel.HasHighResolutionCamera ? 0.01 : 0.005) * Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));

    if (DeviceScaleFactor == 225)
    {
        scale = 0.0015 * Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
    }

    if (zoomOut)
        this.viewModel.ViewScale = initialScale + scale;
    else
        this.viewModel.ViewScale = initialScale - scale;

    System.Diagnostics.Debug.WriteLine("zoomout {0}, scale {1}", zoomOut, scale);
}

if the Device scale factor is 225, its a 1080p device and one should exercise caution.

My thoughts on Lumia 630

Towards the end of May 2014, Microsoft Mobile aka Nokia Devices released their first / last windows phone device. Its was different on many scales – it was the first device to feature Windows Phone 8.1 – Windows Phone Blue. Prior to that only developers had access to the Blue builds thanks to the Dev Preview Program.

Thanks to @Connects team I had a Lumia 630 at my desk on 2nd June.
 1Shot_20140602_100914 1Shot_20140624_143725

It comes in a very compact box as compared to previous Lumia devices. The colour of the device I got was gorgeous orange. Its very bright and nice at the same time. This is the first device that my daughter wanted.. She has played with a variety of Lumia devices before – 800, 620, 820, 920, 925 and 1020 (cyan, black, yellow, white & silver) and never asked for one

The device resembles previous Lumia devices in terms of over all layout. Micro USB at the bottom, the power and volume buttons on the side. Headphone jack at the top. The few missing ones at the camera button and hardware buttons for back, windows and search. Soft buttons make appearance when the screen is powered and provide haptic feedback. Camera can be launched by using camera app or by pinning camera to notifications bar – quick launch area.

1Shot_20140624_143858 1Shot_20140624_143939

Hardware:

  • Quad core Snapdragon S400 1.2GHz
  • 4.5 inch IPS LCD display with Gorilla Glass 3.
  • 5MP rear camera
  • 512MB RAM

It does not come with Ambient Light Sensor, Proximity Sensor or Front facing camera. Rear camera does not have flash of any sorts. Even Lumia 520 shipped with Ambient Light Sensor and Proximity sensors. 620 had LED flash to go along. Not this one. Lack of ambient sensor means no automatic brightness control – you need to manually keep a lid on it.. With camera and brightness control occupying 2 of the 4 quick launch buttons, you’d start wishing for more.

The only hardware issue I had was that it refused to see my home Wi-Fi network. I have it set on 802.11n which works fine on Lumia 920 / 925 and 1020 but not on 630.. oh well. Camera is okay for most  casual snappers – simple 5MP snapper.

Its not a bad device – most apps start just fine. The processor handles most tasks easily. 512MB RAM limitation however does hit many apps and games and there’s just nothing you can do about it. This device would have fit perfectly to match Moto E and Moto G devices with other low-end devices adding to the mix.

However I have been disappointed to an extent.. the device isn’t available at advertised £89.99. Recently MicroMax India announced 2 Windows phone device that will be priced better than Lumia 630. Both of these devices run Snapdragon 200 (Dual core) with 1GB RAM. Beyond the hype, most should go for larger memory than more cores. Earlier today morning Microsoft launched Nokia X2 – the 2nd iteration of the android line up. Spec-wise even that has a better setup than 630 and is priced lower.

From being happy about a decent low-end device, today I am left unsure about what’s its place would be in the market. Nokia Lumia 520 captured 30% of Windows Phone market in a month and helped Windows Phone in many markets. I am not so sure of 630.. lets hope Microsoft Mobile has more tricks up its sleeves.

1Shot_20140624_143908 1Shot_20140624_144042