Taking high res photos with Windows Phone 8.1

There was previously no access to high res resolutions on the camera, but you had to know which model supports which high resolution. Now with the universal apps, you can actually get the all supported resolutions from the camera easily, including the high res and init your camera to use them. Here’s a quick sample snippets to init your camera, select the highest possible resolution and change your camera to use that.

Assumption is that you have CaptureElement in your XAML called captureElement, and MediaCapture element called mediaCapture as a member variable in your code behind in MainPage.xaml.cs

Select the back camera:

var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
var backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back).Id;
await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
{ VideoDeviceId = backCameraId});

Next query all the supported resolutions, and select the highest possible and set that to the camera.

var resolutions = this.mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);

if (resolutions.Count >= 1)
{
var hires = resolutions.OrderByDescending(item => ((VideoEncodingProperties)item).Width).First();

await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, hires);
}

Now you’re ready to start video preview and do photo capturing with these last calls

captureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();

Check out my previous post about setting the camera preview correctly, otherwise your image is going to be tilted quite funkily.

Posted in Universal Apps, Windows Phone 8.1 | Tagged , | 3 Comments

Windows Phone 8.1 camera orientation

Update: The code was missing global bool variable to check if we’re using the front camera, added to code
Using the cameras of Windows Phone 8.1 live viewfinder in Universal apps can be a bit of a challenge. The behavior is different with front and main cameras and most likely you end up with upside down image on your preview, if you run the same code which works for Windows 8.1 when using the front camera. The design of the camera driver is based on WP8.1 chassis specs, and camera orientation is dependent on the native landscape orientation of the display.

Issue here is that the rotation of the front camera and display happens in opposite direction, resulting to inverted image. This all can be a bit confusing, so let’s give you a code which runs on WP8.1 correctly. Note that you need to ifdef this code in Windows for the rotations, or your front camera on tablet will be incorrectly rotated.

First we define the capture element to the XAML like this:

<CaptureElement x:Name="captureElement" 
HorizontalAlignment="Center" 
VerticalAlignment="Center" 
Stretch="UniformToFill">
</CaptureElement>

In the following code we check if front camera is available, and take it in use, otherwise fall back to the main camera. After that we set the camera mirroring according to the chosen camera, as it differs with front and main camera as well. Lastly we subscribe to the orientation change event:

bool frontCam;

...

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    mediaCapture = new MediaCapture();
    DeviceInformationCollection devices = 
await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

    // Use the front camera if found one
    if (devices == null) return;
    DeviceInformation info = devices[0];

    foreach (var devInfo in devices)
    {
        if (devInfo.Name.ToLowerInvariant().Contains("front"))
        {
            info = devInfo;
            frontCam = true;
            continue;
        }
    }

    await mediaCapture.InitializeAsync(
        new MediaCaptureInitializationSettings
        {
            VideoDeviceId = info.Id
        });
            
    CaptureElement.Source = mediaCapture;
    CaptureElement.FlowDirection = frontCam ? 
FlowDirection.RightToLeft : FlowDirection.LeftToRight;
    await mediaCapture.StartPreviewAsync();

    DisplayInformation displayInfo = DisplayInformation.GetForCurrentView();
    displayInfo.OrientationChanged += DisplayInfo_OrientationChanged;

    DisplayInfo_OrientationChanged(displayInfo, null);
}

Now we need to adjust the orientation of the capture element according to the screen orientation (the animation makes your eyes bleed, but there’s no way to disable orientation animations for a control). This code is modified from the MSDN Windows 8.1 advanced camera sample.

private void DisplayInfo_OrientationChanged(DisplayInformation sender, object args)
{
if (mediaCapture != null)
{
mediaCapture.SetPreviewRotation(frontCam
? VideoRotationLookup(sender.CurrentOrientation, true)
: VideoRotationLookup(sender.CurrentOrientation, false));
var rotation = VideoRotationLookup(sender.CurrentOrientation, false);
mediaCapture.SetRecordRotation(rotation);
}
}

For the last piece we need to check the video rotation according to the chosen camera like this:

private VideoRotation VideoRotationLookup(DisplayOrientations displayOrientation, bool counterclockwise)
{
switch (displayOrientation)
{
case DisplayOrientations.Landscape:
return VideoRotation.None;

case DisplayOrientations.Portrait:
return (counterclockwise) ? VideoRotation.Clockwise270Degrees : VideoRotation.Clockwise90Degrees;

case DisplayOrientations.LandscapeFlipped:
return VideoRotation.Clockwise180Degrees;

case DisplayOrientations.PortraitFlipped:
return (counterclockwise) ? VideoRotation.Clockwise90Degrees :
VideoRotation.Clockwise270Degrees;

default:
return VideoRotation.None;
}
}

That’s all it requires, have fun with it!

Posted in Universal Apps, Windows Phone 8.1 | Tagged , , | 6 Comments

Format your date in Universal app according to user preferences

With the new Universal app model, many things have changed, and there’s very little documentation available to find out how you need to address certain things in the new app model. One of those things is formatting your date according to the region settings chosen by the user. CultureInfo is no longer recommended class to be used, and if you tried to dig out yourself the chosen regional format, you might have found it to be quite difficult in cases where user has chosen to use different language (en-US) and different regional settings, for example de or fi.

It’s pretty easy still, only figuring it out where to find that info is not. So here’s the codeblock which formats datetime according to the chosen regional setting:

DateTime date = DateTime.Now;
GeographicRegion userRegion = new GeographicRegion();
var userDateFormat = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate",new [] {userRegion.Code});
var dateDefault = userDateFormat.Format(date);

We use the GeographicRegion to get the chosen region, and then we create DateTimeFormatter according to that culture, which we use to format the date on the last line. Hope this snippet helps you!

Posted in Universal Apps, Windows Phone, Windows Phone 8.1 | Tagged , , , | 1 Comment

How to call your app

With yesterdays announcements at BUILD, there were some new terms introduced along with the new app models. I thought they were a bit mouthful, so I decided to draw this small chart to help you easily figure out what is what.

Naming

First we have the apps build with the traditional, Silverlight -based classic Windows Phone app model apps. If you you target 8.0 they’re called Windows Phone Silverlight 8.0 apps, and if you target WP 8.1 then they’re Windows Phone Silverlight 8.1 apps.

If you are creating Windows Phone Store apps, depending on your choice of technology, they’re either Windows Phone Store apps using XAML /HTML.

Interestingly we don’t make the difference when we talk about Windows Store apps for Windows, but refer to them generally as Windows Store apps.

Lastly there are the Universal Windows apps, which are build with the shared project tooling targeting both Windows and Windows Phone.

Hope that cleared some of the confusion!

Posted in Universal Apps, Windows Phone, Windows Phone 8.1 | Tagged | Leave a comment

What there is and what there might be

As there is no one good public source for Windows Phone chassis specs, I decided to put together a small table which will list the things all Windows Phones have common and what are the optional things devs need to test for the existence.

WP8 chassis

Display part is quite self explanatory, interesting thing is that the specs go up to 7″ screens, which works out for phablets quite nicely. Screen resolutions are also something that devs need to realize, but fortunately the platform is quite nice about them and you don’t have to design for three different resolutions but it scales them automatically. The sensor part is a bit more complicated, and I’ll give a quick overview of them.

First of all, there are some sensors which are found in each WP no matter who’s the manufacturer, let’s call them base sensors. The base sensors are in the minimum hardware specifications, and can be found even in the low end models.

Base sensors

Assisted Global Navigation Satellite System receiver (A-GNNS) is for quick satellite fix, and helps you to get a faster location data for poor GPS signal or when the signal is not available.This sensor you don’t access yourself from the code but the system will take care of it when you deal with the GPS.

Ambient Light sensor can sense light from range of 0 lux up to 4000 lux or more. For this sensor, you have no access from your code either, so you can’t sense the lighting conditions but this information is delivered to OS itself only.

Proximity sensor will detect if the phone is in your pocket or on your ear, and will turn off the display to save battery. Again this sensor is not accessible from the code. Malfunction of this sensor will lead to situation where you can’t end the phone call as screen stays black. In these cases, it is advised to take the phone to repair center, and ask them to put some silicon around the sensor, that helped me (had this issue with three different WPs).

Vibration is the first sensor of these which you can actually access from your code, using Microsoft.Devices.VibrateController – .NET class or Windows.Phone.Devices.Notification.VibrationDevice – Windows Phone Runtime API. In hardware, vibration is done either by motor, speaker or haptics transducer.

Next up is the Accelerometer, which is three-axis with HW sampling rate up to 100 Hz. The accelerometer detects changes in the physical acceleration of your phone and fires events as X,Y,Z orientations change. This sensor can be accessed with WPRT in Windows.Devices.Sensors.Accelerometer and it delivers from SensorBase<T> class.

Optional sensors

There are a few sensors in WP which may or may not be there, depending on the make and model of your phone. When using these sensors, be sure to check at the beginning that they do exists in your code, before using them.

First and maybe even the most interesting of these all is the NFC, near field communication. I’ll write a separate post about doing NFC with WP, but what is important here is to remember to check if your client is enabled with NFC with the following code snippet:

ProximityDevice device = ProximityDevice.GetDefault()
if (device != null)
{
  // do your stuff
}

Magnetometer, also known as Compass is three-axis with sampling rate of 60 Hz. You can access it from Windows.Devices.Sensors.Compass class, and it also delivers from SensorBase<T> class. Interesting side-note is that if your app has ID_CAP_LOCATION, this will give your app more accurate computation of the declination which is different in different point on the earth and changes with time.

Lastly there is the Gyroscope, which is three-axis with sampling rate from 5 Hz to 250 Hz or more. If your device has a gyroscope, it must also have a magnetometer. You can access it through Windows.Devices.Sensors.Gyrometer and it also delivers from SensorBase<T> class.

That wraps it up for now, and in the next post I’ll talk more about using the NFC sensor.

Posted in Windows Phone, Windows Phone 8 | Tagged , , , , , , | Leave a comment

Windows Phone Development MVP

Yesterday I got an email from MVP Awards with the information that I’ve received the Most Valuable Professional -award from Microsoft for my Windows Phone community activities. With a quick check it seems I’m the first in Finland and in whole Nordics to receive MVP for Windows Phone dev, what an incredible honor! That definately motivates me to try to be even more active on the community!

Posted in Uncategorized | Leave a comment

Windows Phone 8 and the music resume -rules in the marketplace

Seems that this old issue is still causing some scratching of head among the devs, how to implement this properly in Windows Phone. This has changed a bit from WP7, and the rule has been updated (6.5.1. & 6.5.3) to apply only to XAML apps. Now you don’t have to worry about radio anymore, as that’s not in the mix with WP8.0.

Here are the few scenarios where you need to fill this requirement.

First we implement the code for normal apps, which want to play a non-interactive full motion video, or a non-interactive audio segment (e.g. cut-scene or media clip) – in this scenario you don’t need to ask user’s consent for this action.

Here are the steps needed to implement it properly. Open your MainPage.xaml.cs file, and insert these namespaces,  and after that also insert them to your App.xaml.cs as well:

using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Media;

And then add a boolean variable to your App.xaml.cs to mark if resume is needed:

public bool needToResumeMusic = false;

Then you go to the class where you need to play your own media. First add this code as a class level variable:

App thisApp = (App)Application.Current;

Next you open the method where you are going to play your own media, and add this code before it:

FrameworkDispatcher.Update();

if (!MediaPlayer.GameHasControl)
{
    thisApp.needToResumeMusic = true;
    MediaPlayer.Pause();
}

Please note that the Update is critical to be there, or the app will have serious stability issues.

Then you need to put only the resume part to your code, and if you’re using for example MediaElement to play music/video, it has MediaEnded -event which you implement like this:

void Player_MediaEnded(object sender, RoutedEventArgs e)
{
      // Do your cleanup here
      ...
      if (thisApp.needToResumeMusic)
      {
         MediaPlayer.Resume();
      }
}

Now it can handle the switching of background music, but there are two scenarios which you still would want to handle. User might navigate away or kill your app while you’re in the process of playing your music, and you would want to resume the background music on those cases as well. That’s why you edit your App.xaml.cs with these changes:

private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
    if (needToResumeMusic)
    {
       MediaPlayer.Resume();
    }
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
   if (needToResumeMusic)
   {
      MediaPlayer.Resume();
   }
}

Second scenario is that you want to play a background music in your own app, in which you would just add dialog box asking for consent just before the GameHasControl -check and move the Resume to the exit of your app.

So, it’s pretty simple to tackle this nasty little rule without too much coding. Hope it clears things and helps you pass the store certification!

Music Resume Sample – includes code, just put your own media file there and change the name of the file to play to test this.

Posted in Windows Phone, Windows Phone 8 | Tagged , , | Leave a comment

Windows Phone 8 Kernel Architecture

Okay, there has to be a good descriptive picture the WP8 kernel, as it has been a huge advertisement point for the whole unified model for Windows and Windows Phone. Or that’s what I thought, until I tried to find one for almost a day with no success. Maybe I’m not the only one, and I thought I draw my own version based on all the information I could dig up (almost only good source was the Windows Phone Internals Preview 1), mixed with some BUILD videos about Windows 8. As amazing it is, there’s absolutely nothing in MSDN about the kernel structure of WP, so here’s something for those with endless thirst for knowledge:

From top to bottom, the famous shared core consist of two distinct parts, Windows Core System and Mobile Core. The Windows Core system is the part that actually shares code with Windows and is the bare essential of OS kernel. The Mobile Core is the part that shares functionality and code with the Windows kernel, but it’s no longer 1:1 copy, but tuned to mobile needs, with less functions than the big Window’s kernel. So together the Core System with Mobile core are the only areas with codeshare between the two platforms. There are areas where the APIs are the same, but the code behind differs between Windows and Windows Phone.

Above the shared core sits the Windows Phone system, with prebuild apps like people hub and Music & Videos, Windows Phone Shell, Connection management and Platform services etc. The platform services itself consists of four major elements, which provide services to all applications.

Package Manager is the part which handles the lifecycle of an application from installing to uninstalling, and the metadata while it’s installed on the system. That data includes information about pinning and extensibility points the app has registered.

Execution Manager handles the applications and background agents and their execution logic. It is responsible for creating the host process and application state messages, such as app startup/shutdown and deactivation.

Navigation Server is handling all the moving between foreground applications on the phone. It handles it by telling execution manager what application to launch or reactivate and keeps track of the navigation stack.

Resource Manager monitors the system resources of all the active processes and enforces constraints on them, focus on CPU and Memory. If the app is misbehaving, Resource Manager can terminate the app to ensure the stable and quick response of the phone.

That’s the quick version of the shared core for Windows ecosystem, hope you find it useful!

Posted in Windows Phone, Windows Phone 8 | Tagged , | Leave a comment

Windows Phone 8, let’s get the party started!

Finally the SDK is out and we can talk about all the great stuff that the SDK brings to us. There are some big changes with unified programming model, but also some differences, like HTML5/JScript not being there as a project template (you can still embed the browser control..) and XNA not being present but replaced with DirectX.

For a short capture of the coolest things with WP8 I would say these things everyone doing WP dev should check out and learn:

  • Lock screen – This is new thing to WP devs, pretty same to big Windows. Now you can provide background images and notifications to the lock screen of the phone, notification stuff is pulled from your program’s primary tile (text, icon, count) but background images you can define inside your app
  • Navigation – There’s a new WinRT based navigation API to use beside to old trustworthy API from 7.x. Now you can do actual navigation apps, that won’t die if user goes away from the app, but can continue to track on the background. You can also ask directions easily with ms-drive-to and ms-walk-to URI schemes within your app.
  • In App Speech support – Now you can actually integrate speech support to your own app with voice commands, speech recognition, and text-to-speech. Voice commands can be deep links to your app (HelloWorld show image), speech recognition you can use inside your app to command your app/game (vessel turn left) and text-to-speech is a “robot” speaking your text to the user.
  • Wallet – Create added value to your membership app, create coupons for your shopping app… endless possibilities here, NFC is the big thing here on WP8, and you should not pass up the opportunity to add these functionalities if applicable to your app.
  • In-app purchases – If you want to monetize your app, think about micropayments. Buy a new report template within your app, buy new tools/weapons in your game.. options are endless. Micropayments are the next sliced bread in WP marketplace, so don’t miss out on the opportunities they offer, and with this API, you got a solid backend ready with couple of easy steps within your app.
  • Localization of your apps -there’s now build in templates for this. Localization is one of they key elements to make money with your app in different marketplaces. There are really cheap crowdsourcing places to go to get your apps ready for example to China market, the user base is so huge that micropayments will definitely boost your income

Other noteworthy changes are the new map control, Pivot & Panorama ditched from SDK and moved to ROM, Bluetooth APIs, inclusion of Windows.NET.Networking, revamped storage apis, associating your app with certain filetypes and now the store compiles your .NET code in the cloud, ensuring the fastest possible startup for your apps at consumer devices. I’ll be posting more in detailed look for each of these categories later on.

Posted in Windows Phone | Leave a comment

What changes with Windows Phone 8 development

Thought I give a short summary for you who are interested in bringing your WP7.5 app to WP8 for what you should look out for.

In general you shouldn’t recompile your WP7.5 app to WP8, for two reasons. Firstly, WP7.5 apps will work on WP8 as is, without any need to rework the code. Secondly, recompiling apps is only going to get you in trouble, because there are some changes in the way .NET Framework and CLR has been implemented on WP8 compared to WP7.5. There is a totally new kernel on WP8 and for example totally new garbage collector implementation on WP8. Also precision is not the same in all cases with WP7.X and WP8 with number handling.

What you should consider is to bring your app to Windows 8 with the same trouble, as now with the shared kernel and programming model (XAML+C#/C++) you are able to double your presence in the markets. We’ve been able to reuse pretty much 99% of the code in couple of titles we’ve done targeting Win8 and Windows Phone 8 platforms with C++ DX based games.

Windows Phone 8 will also include in-app purchasing , so finally you can bring additional paid content to your apps/games. Micro payments have proved to be a very efficient way to a developer to earn more money, as buying decision bar is much lower with small amounts, and there will be more purchases for items/features than you would expect with right kind of content.

These are just a tip of the iceberg, and when the NDA is lifted, I’ll talk more about other cool features that are hidden in the SDK, that will make WP8 rock!

Posted in Windows Phone, Windows Phone 8 | 2 Comments

Windows Phone Garbage collection

Thought I clear up some things regarding the functionality of the Garbage Collector in Windows Phone, which is maybe a little bit misunderstood functionality of the platform among the people coming from other non .NET environments.

First of all, the whole point of garbage collection is to automate memory management on behalf of the developer, taking (almost) all the pain out of handling allocating and releasing memory. As managed developers, we don’t need to know too much what’s happening behind the curtain, but let’s go through some basics anyway, so we can feel more comfortable leaving our valuable memory to be handled by the Compact Framework.

Managed objects can move around the memory, unlike native objects, this is one important thing to understand. The system can compact memory and decide to move things around without asking your permission, so you can’t have memory pointers in traditional sense. Internally there is some methods that the framework uses to disable moving the memory when it’s handling some managed memory buffers, but thats all hidden from average developers.

As there are two types of objects, value and reference types, there is also two ways the framework handles the memory for these objects. For value types compiler checks when they go out of scope, and generates code to destroy and reclaim their memory in very deterministic manner. Reference type objects are a bit trickier. For their memory the GC reclaims the memory when it seems appropriate, and it is not controlled by your code. It follows through how you reference the object and finally when there are no more references left, it will destroy it.

The GC in Windows Phone 7 Mango is so called generational garbage collector. That means that the GC has two queues, gen-0 and gen-1. Gen-0 has those which will have very short life cycle and it’s collected on each GC round, and Gen-1 is for those who reside longer in memory and is collected rarely. Those objects who survive the gen-0 sweep, are promoted to gen-1.

Posted in Windows Phone | Leave a comment

Rating control for Windows Phone 7.5

Long evenings at hotels can be strangely productive time, and last night I started to think that there is no simple and lightweight star rating control available (I know only one, but it’s a big too big for my taste).

It has two properties, Rating and Scale. With Rating you can set or get the current rating and with Scale you can set what scale you want there to be (for example 1-5 stars, you would give Scale the value of 5). It does still lack the production code level error checking, so if you consider using it, better add some try catches. Here’s the file:

RateControl

You are free to edit and use and it commercial or non commercial, as long as you leave the assemblyinfo intact and use it through my library.

Posted in Windows Phone | 2 Comments

Nokia Windows Phones

Today at Nokia World was announced that Nokia is releasing two Windows Phone, Lumia 800 and 710. These two models are the first Wp phones from Nokia, and will be most likely the most sold WP phones for a while. The Lumia 710 was IMHO more exiting in that sense, that the pricepoint was finally where it should be, retailing at around 270 €. There was not many features except faster processor which would make the 800 a must buy compared to this one (I don’t put too much weight on the design). At this price it really has a chance to capture new markets, and bring WP to whole new markets it couldn’t reach before.

Myself I’ll be still sticking to my two Omnia7s, as they are still quite competetive in specs, and especially the larger screen makes it hard for me to give up on them (if Nokia would have launched either of the phones with front facing camera, then I would have had to consider getting one, but luckily they didn’t so I can save some money..). I think I’ll wait for the WP8 phones before upgrading from my current Mango phones, but today was a very welcome addition to WP models and if I wouldn’t have a WP, I would definately get a Nokia one – I’m envious for the Nokia Drive, that really makes it hard for me to keep my calm and not to rush to preorder a Lumia..

On other development – I’m starting to create a Windows 8 “Metro Style app” for the ringtone editor, hopefully it will be soon available here – I probably put up some developer story about the process as well up here.

Posted in Windows Phone | Leave a comment

Create your own ringtones for Mango

I think I’m not the only one who feels that using Audacity is not the easiest way to create ringtones for your Windows Phone. Once again the annoyance level of using too many separate tools got too high, and I decided to create my own solution for this.

Here’s a little utility, which you can use to create the ringtones with as little hassle as possible. Using it is quite simple, just install it, make sure your tunes are in Music -library in Windows, and run it.

You have a list of all your music in MP3 and WMA format in front of you as a list and you just select the tune you like to use for your ringtone. Then you have two sliders you can use to adjust the selection by dragging them around – it’s fixed to allow max 39 sec piece to be used as ringtone (Mango limit).

You can listen to the preview while editing, just realize that when you drag the end, it will go automatically -5 seconds from the end, helping you to adjust the end better (so it’s not a bug, but a feature.. right;) Draggin the beginning will autostart the preview from the beginning.

After you are satisfied with your ringtone, click the Create Ringtone -button. That will create a file called Ringtone-name of your song.wma to your Music library.

Unfortunately Zune has no SDK so I couldn’t automate the next step. Now you need to open the Zune, and make sure that your Music library is set as your music collection location (See from Settings, Software, Collection). If it isn’t, click Manage and add it. Now if you’re not doing Wireless sync, connect your phone to your computer.

Click Collection, and go to Music page. Now you should see your Ringtone-name of your song.wma in the list. Just drag that to your phone, and now you’re done!

If you open your phone, go to Settings and Ringtones+Sounds, and click Ringtone, you should see your own ringtone on top of the list.

You can download the installer from http://www.symbio.com/cs/RTCreator.zip

Add comments if you have bugs or questions – I try to clarify the instructions according your feedback

Quick note (18.10.2011) – this has been tested only on Windows 7, and should work on Windows 7 & Windows Server 2008 R2.

Posted in Windows Phone | 2 Comments

Speaking gig coming up

If you have a chance, come to see me at Suomen Ohjelmistoyrittäjät organized Nokia/Microsoft ecosystem event 22nd of September in Helsinki, where I’ll be speaking about WP development experiences.

Posted in Uncategorized | Leave a comment

WP 7.5 ‘Mango’ security model

Long time no post :) I had unforeseen delay with a house project that has kept me quite busy lately, and unfortunately WP Mango update NDA prevents phone reviews that I promised earlier :( But now I have a some time to write a short story about security side of Windows Phone. I have not seen too many articles about this, so I thought this might interest someone.

The security model in Windows Phones is based on chambers. These chambers limit what applications can do by putting them inside a security sandbox. There are four different chambers and each of these chambers have certain limitations how applications within them can run.

Security Chambers

Trusted Computing Base is the home of the kernel and kernel-mode drivers. TCB has the highest set of privileges. Processes running here have the access to most of the things in the phone. It goes without saying, that you can’t put your own applications here, and even for OEMs they have to be careful what they put here, as it will affect the security and the performance of the phone. TCB chamber can also modify policy and enforce the security model.

Elevated Rights Chamber is the location where the user-mode drivers and services reside. Processes here have access to most of the things except for the security policy. Drivers that reside here are safer in that sense, that they won’t crash the whole phone if they stop functioning, but there is a performance tradeoff.

Standard Rights Chamber is the place for native code applications. All the apps that do not provide services for the whole device are located here. This is the place where the Microsoft apps, like Outlook Mobile resides.

Least Privileged Chamber is the home of the MO/OEM applications and normal 3rd party applications which you load from the marketplace. LPC differs from the other security chambers for it is dynamic by nature. By default it has minimal access rights, but software running there can request a capability, like access to location, media, network, camera, microphone etc on installation time. These capabilities which each software requires are disclosed at marketplace.

Each 3rd party software has it’s own isolated LPC and can have access to only those capabilities that it has requested and they can not be elevated at runtime. Also each software has it’s own file system, called isolated storage and other applications can not access that. There are no communication between applications except through server.

That’s about the main security architecture, if you have further questions, leave a comment!

Update (25.8.11) – I found out that the Hybrid applications do not run in the SPC but in LPC. When they access drivers etc, the security context will be within the LPC

Posted in Windows Phone | 2 Comments

Mango has been released!

Finally some great news from MS, the Mango WP 7.5 has been RTM! The Final build version is 7720 but developers get now an update from the Beta 2 (7661) to 7712 (Almost RTM version), which is more than great (had some connectivity issues with beta with 3G). After I have updated my phone, I’ll be posting some review about it.

Posted in Windows Phone | Leave a comment

Mango experience

Today in Finnish financial newspaper “Kauppalehti” there’s an online blog (in Finnish) about my and my company’s experiences with the Windows Phone Mango, check out the article at: http://microsoft.blogit.kauppalehti.fi/blog/24105

Posted in Uncategorized | Leave a comment

Preparing for 70-521 transition test..

For me, panic is the best motivator :) Lately had to brush up my WPF/EF/WCF skills trying to prepare for the upgrade test for the MCPD Windows Developer (that I’m about to take tomorrow morning…)

Kind of learned several new things – no matter how long you have worked with some framework, it really pays up to pick up a book on the subject and read from the basics. There’s always something you haven’t realized before or find a new way to use some classes.

I guess the same goes with the Windows Phone. After tomorrow I probably pick up Charles Petzolds excellent e-book (http://www.charlespetzold.com/phone/) and just read it through and see if I’ll be enlightened :)

 

Posted in Uncategorized | Leave a comment

Designing with Metro for Windows Phone

I’ve read through several Metro presentations and sat through some sessions and realized that none of them is really too ground to earth, “what does this really mean to me as an application developer” -approach. I see a lot of “Personal, Relevant, Connected“, “Authentic experience” type of hype words being used, but that really doesn’t tell me how I should put controls to the screen, and how should I visualize them.

I try to cut down the hype and give some concrete examples what and how you should go with Metro when you design your application. Whole point of Metro desing language is to cut out all the excessive bling bling from your applications, have very clean and light feeling to your UI – so just a glance should tell the user all the necessary info, aim for that. So in developer terms – no 3D (authentically digital), no excessive color effects, have a lot of empty space between the controls, use enough big fonts – one could say this is very spartan way of designing the UI.

It goes without saying, that all the Silverlight controls that come with WP SDK adher to this design philosophy, so if you’re creating custom controls, you won’t go too much wrong by mimicking the build in controls look and feel/behavior. For example push buttons don’t have visible focus state, their rectangles are either empty or filled to show the state. Simple and clean.

The screen size is locked to 800 * 480 in every WP7 phone, no matter which model or manufacturer you have. That gives you pretty solid foundation for planning the UI, only thing you need to worry is portrait/landscape(left and right) and if you allow the switch between these two modes.

Full screen games are free from Metro restrictions, feel free to go crazy – but if your game appears withing the WP page frame, then you should follow the Metro guidelines. I won’t go more into details about game design rules, perhaps in a later post separately when I share some of the basic game design guides.

There are Windows Phone Design Templates as part of the Windows Phone SDK, which are layered photoshop templates and with those you can really do pixel to pixel application layouts very easily (Download the 89 Mb package from http://msdn.microsoft.com/en-us/library/ff637515%28VS.92%29.aspx)

And now to the raw details. There are two primary components in WP OS 7 Chrome, Application Bar and Status Bar.

Status Bar can be hidden, but you really shouldn’t do that, as it includes stuff like battery indicator and system clock, which users really like to see. By default only the system clock is visible, and it is opaque and takes 32 pixels in height and 72 pixels in width from your screen. In landscape mode the status bar grows from 32 to 72 pixels. If user taps the Status Bar area, rest of the relevant icons will be shown (Signal, Data, Call forwarding, Roaming, Wireless, Bluetooth, Ringer mode, Input status, Battery)

Application bar is where devs can put their icons. The rules are:

  • Up to four icons, system draws automatically a circle around them
  • Does not move in switch between portrait/landscape, but icons rotate
  • 72 pixels in height, width is whole screen in portrait
  • Opacity recommendated values are 0, .5 and 1
  • Icon size is 48 * 48, white foreground and transparent background using alpha channel

In application bar you have also a menu, where you can put text menu with max 5 items and the text should be between 14 to 20 characters only.Use very simplistic icons, like add could be plus sign, close could be just the X, search for example magnifying class etc. Remember to put text hint, so if your users don’t get your idea, clicking the three dots will bring up the icon buttons with the text hints (and the menu). Cool thing for graphically impaired people like me, is that the SDK comes with 64 free ready icons (C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Icons)

Rule with colors is that use user-defined system theme color unless you have really strong reason against it, as this way you can always guarantee that the theming won’t render your application unusable if your custom drawing color is same as the background of the theme.

For the fonts, stick with system Segoe to maintain WP general look and feel, there are five styles for it (regular, bold, semi-bold, semi-light and black). It is highly recommended not to use any fonts under 15 points in size.

Alright, here was the short intro to Metro, will be continued in part 2 where we go through the basic controls like Panorama and Pivot, then we talk about push notifications and live tiles, toasts etc. We’ll check out also the navigation and some general UX rules, stay tuned :)

Posted in Windows Phone | Tagged , | Leave a comment