42Gears Speaks
26Oct/110

Kiosk mode on Android

SureLock for Android has been released. Trial version is available for download from our website as well as from the Android market.

Lock down android device into kiosk mode

Lock down android device into kiosk mode

Features:
* Lock down smartphones and tablets into kiosk mode
* Restrict users to allowed applications only
* Block users from accessing Home screen
* Block user from playing games, browsing or installing unapproved applications
* Block user from changing System Settings
* Admin can securely unlock the device with a password

Check out more details on our website at http://www.42gears.com/surelock/

Go to Home


12Sep/110

Crash Reporter for Android application developers

Programs crashing post release is not uncommon. Such situations are also not easy to handle as they might be occuring under certain conditions which might not easy to replicate. Crash dumps come in handy to solve such field issues.

Wikipedia defines crash reporter as "an application whose function is to report crash data to a third party, usually to the party responsible for the crashed program. Crash reports often include data such as stack traces, type of crash, and version of software. This information helps software developers to diagnose and fix the underlying problem causing the crash."

Imagine a Logistics Company who has deployed their newly developed "Proof of Delivery" (POD) application. The application was "sufficiently" tested in-house where it went through multiple validation cycles. It was then commissioned for use on hundreds on Android based devices going into the hands of the mobile workers.

Crashed Android application

Crashed Android application

Everything was working fine until one day a report came in coming in from the field stating that the POD application was crashing intermitently. There was apparently no way to reproduce the behavior consistently. The issue was escalated to the development team which got ready to look into the "bug". But there was problem. This particular phone was hundreds of miles away and there was no way the dev team could figure out what was happenning to the application. If only they could get hold of the stack trace when the application crashes. That was not possible as the end-user was a NOT programmer or a techie who could pull the crash report from the phone and send it to the development team.

Thats when the development team got an idea. They remembered when the devices were rolled-out, the IT department had installed a Remote Mobile Device Management solution to keep an eye on the devices in the field. This MDM system was actively being used to gather various device health information, to push new software updates, to secure and to track the phones.

IT manager knew about a feature in the MDM solution that could monitor any application on the device and could report issues incase the application failed. MDM was asked to monitor the POD application. The user was then asked to launch it.

Crash Report in SureMDM

Crash Report in SureMDM

A few hours later the application crashed, but this time MDM caught the crash, collect the crash report with stack trace. This crash report was provided to the development team. And voila! the problem was fixed in no time by the smart developers. New version of the POD application was re-deployed on the phones remotely using the MDM solution.

Conclusion

Crash Reporting is an important feature which ensures any serious issues with the application don't go un-reported. Sometimes such crash reports are the only way to diagnose and fix the problems.

Wondering which MDM solution supports Crash Reporting for Android devices. Thats SureMDM from 42Gears Mobility Systems. Now you can not only control and manage the mobile devices, but also the mobile applications when they run into problems.

Go to Home


13Feb/113

Getting rid of flickering in .NET CF forms with custom drawn controls

.NET Compact Framework doesnt provide builtin double buffering for forms. In case you have multiple custom drawn user controls on a form, loading will mostly show flickr. Overriding OnPaint and drawing the form and its child controls to an offscreen bitmap before putting it out to actual display is expected to solve this. But, once a child control is added to another container control, overriding OnPaint of the parent container control doesnt allow you to paint the child as the child's client rect is clipped out from the graphics object passed to parent's OnPaint.
The solution to this problem is to avoid adding the custom user control to the forms. Instead, maintain your own list of such controls. Form's constructor should make these changes.

//this.Controls.Add(customControl); //don't do this
control_list.Add(customControl); //control_list is Forms own custom list for it's child controls.

When we do that, GWES doesn't know of these controls as child to our form and hence allows us to paint anywhere we like. We can now paint all child controls (by calling their respective OnPaint) to an offscreen bitmap before blting it to actual display. Heres a sample code which does something like this.

protected override void OnPaint(PaintEventArgs e)
{
using (Bitmap doubleBuffer = new Bitmap(this.Width, this.Height))
{
using (Graphics gxOff = Graphics.FromImage(doubleBuffer))
{
using (Brush backBrush = new SolidBrush(this.BackColor))
{
gxOff.FillRectangle(backBrush, this.ClientRectangle);
}

foreach (CustomControl ctl in control_list) //control_list is list of child controls maintained by Form
{
Rectangle rc = new Rectangle(ctl.Left, ctl.Top, ctl.Width, ctl.Height);
if (e.ClipRectangle.IntersectsWith(rc)) //update only those child control which fall within the invalidated region
{
ctl.OnPaint(new PaintEventArgs(gxOff, ctl.ClientRectangle), ctl.Left, ctl.Top);
}
}

e.Graphics.DrawImage(doubleBuffer, 0, 0);
}
}
}

This scheme, however, also requires the form to manage and delegate other GWES events (keypress, clicks, etc) to respective child control. Following code snippet shows that for MouseDown

protected override void OnMouseDown(MouseEventArgs e)
{
foreach (CustomControl ctl in control_list)
{
Rectangle rc = new Rectangle(ctl.Left, ctl.Top, ctl.Width, ctl.Height);
if (rc.Contains(new Point(e.X, e.Y)))
{
ctl.OnMouseDown(e);
this.Invalidate(rc);
break;
}
}
}

I know its a bit of pain but in case you have simple custom controls like buttons, picturebox, very few events need to be overridden and its worth for the flickr free smooth rendering of your forms.

SureMDM: Mobile Device Management for Starters and Experts

Go to Home


8Feb/110

Solution to “Not Found” error when uploading large data in your Azure web application

So you deployed your brand-new ASP.NET web application to Azure cloud. All seems to be working perfectly until a user tried to upload large amount of data (approx. over 30MB) through your application UI. Unfortunately the operation failed. Surprisingly small file uploads works just fine.

To fix the problem you need to ensure that following configuration are made in the web.config file.

<httpRuntime maxRequestLength="102400" executionTimeout="3600" />

Here value of maxRequestLength is in KB so that makes it 100MB. Having a bigger executionTimeOut value ensures that the file upload operation is not terminated prematurely by the web server.

<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1024000000" />
</requestFiltering>
</security>
...
...
</system.webServer>

Here the value of maxAllowedContentLength is in bytes so that makes it 100MB again.

Restart the website and large data uploads should work just fine.

Go to Home


26Nov/100

SureCop: Anti-theft for Windows Mobile just got better

Latest version of SureCop, our Anti-theft solution has been released with an important improvement. It now has better support for handling various phone number formats. If the phone is not responding to SMS commands from partner phones even if the correct password is specified, you should try out the latest version.

Download is available from the following link: http://www.42gears.com/surecop/ or http://www.surecop.com.

Go to Home


Tagged as: No Comments
31Oct/100

Delete File or Folder path in C#

Following is a C# code snippet to delete a path (file or directory). First we have to determine whether the path is a file or a folder and then call appropriate Delete methods. In case of directory, you can specifiy whether the contents should be recursively deleted before deleting the directory.

void DeletePath(string path)
{
try
{
FileInfo finfo = new FileInfo(path);
if (finfo.Attributes == FileAttributes.Directory)
{
//recursively delete directory
Directory.Delete(path, true);
}
else if(finfo.Attributes == FileAttributes.Normal)
{
File.Delete(path);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}

42Gears has recently released SureCop, an Anti-theft software for Windows Mobile phones.To learn more about SureCop for Windows Mobile and how it can help you secure your mobile phone, please visit the product website http://www.surecop.com. To learn more about our products, please visit http://www.42gears.com.

Go to Home


29Jun/100

C# code to soft reset a Windows Mobile device

Here is the C# code to soft reset a Windows Mobile device (using P/Invoke)

[DllImport("coredll.dll", SetLastError = true)]
static extern int SetSystemPowerState(string psState, int StateFlags, int Options);

const int POWER_FORCE = 4096;
const int POWER_STATE_RESET = 0x00800000;

private void SoftReset()
{
SetSystemPowerState(null, POWER_STATE_RESET, POWER_FORCE);
}

Go to Home


19May/100

How to get information about softwares installed on Windows Mobile devices?

Best method is to ask the configuration service provider (CSP).

Step 1: Add Reference to Microsoft.WindowsMobile.Configuration
Step 2: Add the following statements at the top of the c# code file.

using System.Xml;
using Microsoft.WindowsMobile.Configuration;

Step 3: Prepare a csp string (xml format) and pass it to ProcessConfiguration method of ConfigurationManager. Return value is the xml string which contains all currently installed softwares on the device.

private void ListInstalledSoftwares()
{
string cspString = "<wap-provisioningdoc><characteristic-query type=\"UnInstall\"></characteristic-query></wap-provisioningdoc>";
XmlDocument xmlResult = null;

// Use CSP to get list of installed applications
try
{
XmlDocument configDoc = new XmlDocument();
configDoc.LoadXml(cspString);
xmlResult = ConfigurationManager.ProcessConfiguration(configDoc, false);
Debug.WriteLine(xmlResult.InnerXml);
}
catch (Exception ex)
{
Debug.WriteLine("Failed to get list of installed applications. CSP failure. [Exception: " + ex.Message + "]");
}
}

Go to Home


14May/100

How to disable “Unsigned Prompt Policy” on Windows Mobile?

Many Windows Mobile (Pocket PC) devices ship with one-tier security configuration enabled. That means if an unsigned application is started, then the user is prompted whether to allow the unsigned application to run or not. If the user based on his/her judgment allows the application to run, the application runs in privileged mode whereby it can access all system APIs and protected registry keys.

Now this feature can be very annoying during development. So rather than signing the executable the developer can temporarily disable the Unsigned Prompt Policy by making some registry changes.

Steps to disable Unsigned Prompt Policy on Windows Mobile:

  • Use Remote Registry Editor or a third-party tool such as PHM Registry Editor.
  • Set the following registry value to 1 to disable Unsigned Prompt Policy. (Default value is 0).

    ; Unsigned Prompt Policy
    [HKEY_LOCAL_MACHINE\Security\Policies\Policies]
    "0000101a"=dword:1

    Note: Create the above registry entry if it does not already exist.

Go to Home


10May/100

How to get process id and thread id from a Window Handle in .NET CF?

Specify the namespace for doing P/Invoke stuff i.e. calling Win32 API functions from managed code.

using System.Runtime.InteropServices;

GetWindowThreadProcessId Win32 function retrieves the identifiers of the process and thread that created the specified window.

Here is how we declare GetWindowThreadProcessId for use in managed code (c#).


[DllImport("coredll.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

Description:

  • hWnd is the window handle
  • lpdwProcessId stores the process identifier after the method returns
  • return value of the function is the id of the thread that created the window

Calling GetWindowThreadProcessId via P/Invoke:

// Set the hWnd value below with window handle of your interest
IntPtr hWnd = this.Handle;
uint processid = 0;
uint threadid = GetWindowThreadProcessId((IntPtr)hWnd, out processid);

And there you go....