Saturday, May 23, 2015

Back to Samsung Firmware

Oops I did it. I mean, I installed CyanogenMod on my Samsung Galaxy S2.
After a week spent with it, I can say for sure that the only thing I really appreciated is the new version of Android OS (Kitkat, so Android 4.4.4, instead of Samsung's 4.1.2) . All the rest sucks (sorry!).
This is my list of major compliances:
  1. Not energy efficient. A battery charge last at maximum half a day
  2. Unstable. It reboots at least once a day
  3. Ther's not an FM radio and I cannot live without http://www.modenaradiocity.it/
That's enough for me. Time to come back to Samsung Firmware: yes I will reinstall Samsung Firmware, obtain root access and remove all the unnecessary Samsung apps that only last memory.

It's 12:00 AM. Let's start.

As a first step let's do a Nandroid backup. It's easy to do it starting with an already installed CyanogenMod ROM. In fact CyanogenMod comes with a CWM-based Recovery that makes it easy to do a full, Nandroid backup.
  1. Turn off the phone
  2. Enter recovery mode: with the phone still off, press simultaneously VOLUME UP + HOME + POWER keys
  3. The device will start in recovery mode
  4. Select backup and restore (use VOLUME UP / VOLUME DOWN keys for moving through the menu items and use POWER key for selecting an item)
  5. Choose either backup to /storage/sdcard0 or /storage/sdcard1
  6. After about 15 mins, the procedure finished. My God! I started with a 65% of battery charge and now it's about 10%!!! Anyway, I chose to backup onto sdcard0, therefore the procedure created some subdirs for me, specifically: clockworkmod/backup and another directory labeled with today's datetime. Inside that directory the procedure saved all the stuff. 
It's 12:20 AM. My phone is charging now. I need to reach about the 60% of the full charge for completing the next step. So, let's pause for a while and have some rest/fun with other activities. 

It's 01:05 AM now. Phone charge is about 68%. Time to install Samsung Firmware back. We will use a PC with Odin already installed and Samsung firmware file already in there.
  1. Connect the phone (still swiched off) to PC using a USB cable
  2. Start Odin and load the original Samsung Firmware by clicking on AP button and selecting the corresponding firmware file
  3. Start the phone keeping VOLUME UP + HOME + POWER keys pressed
  4. Follow the instruction on the phone
  5. Click Start button from Odin window
  6. At the end of procedure the phone will install the Samsung Firmware and will boot.
  7. If the phone keep restarting again and again without finishing the boot procedure, a hard reset is needed. In order to do this, switch off the phone. Then press VOLUME UP + HOME + POWER keys. The device will start in recovery mode. Select the item wipe data / factory reset and reboot.
It's 02:50 AM now. Samsung Firmware is working, but I haven't finished yet. I want to get rid of all the junk Samsung app that are pre-installed by the vendor. Ok. Time to root the phone.


Sunday, March 17, 2013

From one monolithic log files to many, more manageable, smaller logs

... Then they came to me for interpreting the n-th log file: it was an intricate mess of thread traces. When I went home I wrote an utility for splitting that mess into several files each one with a single thread trace.

Welcome to my log-splitter

Tuesday, January 08, 2013

Reading Android SDK doc offline - I want to build my app - day 3

The ADT bundle doesn't install documentation by default, therefore the only way to read it is by using a internet connection. Here I'll describe how to acquire that documentation for reading it locally.

First off, be sure to launch your Eclipse IDE as computer administrator. (The details about how to do that are a little bit OT here, anyway... if you start Eclipse using a shortcut in Windows 7, be sure that, after opening its property, the item Run this program as an administrator is checked on under the tab Compatibility).

Now open your Eclipse IDE, then from Windows menu, choose the item Android SDK Manager. A window similar to the one in figure will open up.




Here you can see what already has been installed locally and what still hasn't. Check the item Documentation for Android SDK then click on Install button.

After installing the documentation, you can browse it under docs folder, located into SDK root folder. The entry point is the file offline.html.

What kind of Java am I using? - I want to build my app - day 3

Right now I'm doing some experimentations with Eclipse IDE using Java, but... wait a moment: is this the JVM I'm used to program for desktop/server applications?

Well... no. Take a look here to get what Dalvik is and here for getting some basic differences from JVM.

Monday, January 07, 2013

Time to study and to experiment - I want to build my app - day 2

This is day 2 of my experience in building my own Android app.

I downloaded the whole ADT bundle for Windows here and I installed it.
Then I started my training by chapter one, Building Your First App, that's basically an Hello World app.

This is a quite easy app to develop that shows you some basic concepts behind Android development: the Activity class, the View class and the Intent class. Beside that, it helps you familiarize with the emulator and its usage for building, running and debugging apps.

My impression now is... there is a lot of things to study and the complexity is high because the field is huge and this platform suffers fragmentation: I mean you cannot rely on the fact your app will run on Jelly Beans only (at least for my app). Therefore some APIs cannot be used generally and you have to learn way A as well B to do just the same thing.

Before continuing my training, I discovered a site where Open Source Android app are listed: it can be useful for doing some practice by studying already-skilled-programmers' code. Here it is: F-Droid. This site, as well as the SDK samples, can help a lot. (Practice makes perfect).

Saturday, December 22, 2012

Disappointment with tablet screen protectors

It was the third screen protector I tried to apply to my 7 inches Android tablet. I ended up thinking that is nearly impossible to apply a screen protector on a tablet surface without introducing some air bubble or dust.

So, now, I give up. My Android tablet will never have any of these gadgets.

After this (frustrating) experience my conclusion is: screen protectors are easily appliable only on small screen sizes, i.e. on mobile phones, otherwise... forget about them.

I want to build my app - day 1

Welcome back.
I see my last blog entry here is dated September 2010... a lot of time ago.
Don't worry for me: I'm alive and well. I still work on Java, I do a lot of photos and enjoy life.

Starting from today, I'd like to bring some new air here, at least I promised that to myself: I want to seriously build some apps. 

I own an Android 4.1 phone and an Android 4.2 tablet and I already told to myself countless times this year to develop some ideas, but I'm still fighting against less or no time at all, so the challenge here is to find out some good time to put words into action.

Today is day one for this project. I will post here my progress on a regular basis labeling each entry with the keyword myapp.

Thursday, September 16, 2010

Apache Ant - How to search a and replace regular expressions inside a text

As reported by documentation, Ant provides a task, <ReplaceRegExp>, "for replacing the occurrence of a regular expression with a substitution pattern in a selected file or set of files". Now the question is: do Ant also provide a task for doing the same on texts? Well... the answer is no.

Anyway, this doesn't mean that it's not possible to achieve the same effect on texts. Actually there are at least two ways: the first is to use AntContrib's <PropertyRegex> task. The second (that works only starting from Ant 1.7.1) is to combine some standard Ant task to do the same: just read on.

Let's start from the <concat> task. The documentation says: "Since Ant 1.7.1, this task can be used as a Resource Collection that will return exactly one resource". Moreover "since Ant 1.6 it supports nested FilterChains". This is important because FilterChains are formed also by TokenFilters and a TokenFilter can be a ReplaceRegex string filter. Confused? Take a look at the following code:
<macrodef name="replaceStringWithRegExp">
<attribute name="string"/>
<attribute name="searchPattern"/>
<attribute name="replacementPattern"/>
<attribute name="property"/>
<sequential>
<tokens id="id">
<concat>
<string value="@{string}"/>
<filterchain>
<tokenfilter>
<replaceregex pattern="@{searchPattern}"
replace="@{replacementPattern}"
flags="g"/>
</tokenfilter>
</filterchain>
</concat>
</tokens>
<property name="@{property}" value="${toString:id}"/>
</sequential>
</macrodef>
Here I've defined a macro named "replaceStringWithRegExp". It takes four input parameters:
  1. string: text to match against a regular expression
  2. searchPattern: regular expression
  3. replacementPattern: substitution pattern
  4. property: name for a new property that will contain the result of the replacement
The input string is treated as a String resource (see <string>), filtered using a FilterChain (see <filterchain>) that's made of a TokenFilter (see <tokenfilter>). The TokenFilter is a ReplaceRegex string filter (see <replaceregex>).

To extract the result of <concat> task, I've wrapped this task around a <tokens> task and I've assigned an id to the external task. Finally, using the expression ${toString:id} it's possible to extract the toString value from the <tokens> task: this is the result of the search and replacement. Pretty tricky, isn't it?

Now let's try it.
 <replaceStringWithRegExp string="James Bond" 
searchPattern="(\w+)\s+(\w+)"
replacementPattern="My name is \2, \1 \2"
property="result"/>
<echo message="${result}"/>
Here we get: "My name is Bond, James Bond". Well, it works.

Wednesday, September 15, 2010

Apache Ant - How to find empty directories

To find out empty directories just using standard Ant tasks is not a trivial job. Here I'll show you how this can be accomplished applying a technique that involves an accurate use of <copy> task and <present> selector.

Let's take a look at the following script excerpt:
<property name="dirToCheck" value="c:/temp"/>

<copy todir="${java.io.tmpdir}/_copy_" includeEmptyDirs="false">
<fileset dir="${dirToCheck}"/>
</copy>

<dirset dir="${dirToCheck}" id="emptyDirs">
<present present="srconly" targetdir="${java.io.tmpdir}/_copy_"/>
</dirset>
In the previous code we want to check for empty directories starting from a base directory identified by property named "dirToCheck".

The idea is to use the <copy> task to clone the directory structure into a temp dir (${java.io.tmpdir}/_copy_) without including empty directories (includeEmptyDirs="false"). This way we get a clone of the original directory structure without its empty directories.

Empty directories can now appear from the comparison between the original directory structure and the cloned one: they simply emerge as those directories that are present only in the original structure, as the <present> selector shows.

Tuesday, August 10, 2010

How to get Huawei E1750 USB modem working on Ubuntu Lucid

Some times ago I installed Ubuntu 10.4 LTS (aka Lucid) on my laptop. At that point I wasn't sure whether my Huawei E1750 USB modem were recognized or not by the new OS, so I plugged it into a USB port. The result was the USB modem was recognized as a mere USB drive, so no internet connection could be established.
In order to solve this problem, I discovered that I needed to install a package named "usb-modeswitch".
As the documentation says, several new USB devices have their proprietary Windows drivers onboard, especially WAN dongles. When plugged in for the first time, they act like a flash storage and start installing the driver from there. If the driver is already installed, the storage device vanishes and a new device, such as an USB modem, shows up. This is called the "ZeroCD" feature.
On Debian, this is not needed, since the driver is included as a Linux kernel module, such as "usbserial". However, the device still shows up as "usb-storage" by default. usb-modeswitch solves that issue by sending the command which actually performs the switching of the device from "usb-storage" to "usbserial".
Also I discovered that before installing "usb-modeswitch" the package "usb-modeswitch-data" must be installed.
I then downloaded these two packages using a Windows machine with a working internet connection. The URL I used were:
Using a USB storage key I moved the downloaded packages on the Ubuntu machine.
Then I installed them using the following terminal commands:
    sudo dpkg -i usb-modeswitch-data.deb
    sudo dpkg -i usb-modeswitch.deb
I restarted Ubuntu, connected the USB modem and now it was perfectly recognized. As a proof for this I noticed that Ubuntu's network menu (located top right) showed a new item, Mobile Broadband, with the option to connect to a mobile network.
Please note that this solution is working not only for Huawei E1750 USB modem but also for many other devices, as specified here.

Sunday, November 29, 2009

Photo retouching...

The following video shows a technique I used to remove some distracting elements from the original shots of this album.

Sunday, November 22, 2009

How to enable Ruby debug in RubyMine 2.0 on Windows

I recently had the chance to evaluate JetBrains' RubyMine. I was well impressed by this IDE except for the impossibility to debug Ruby code.
However I didn't gave up and, googling a bit, I found a thread inside JetBrains Developer Community that helped me to fix my installation and finally to debug Ruby code inside RubyMine.
Although the entire procedure is fully described in that thread, I think is worth summarizing the fundamental steps to fix the environment.
Let's start from a scenario where Ruby 1.9 has been installed with the one-click installer and RubyMine 2.0 has been installed too. (If you installed Ruby with the zip binary, reinstall it using the one-click installer as found here. That's because currently the ruby debugger ide only works on Windows using a RubyInstaller installation). Also verify that Ruby's root path doesn't include spaces.
  1. Download Ruby DevKit. (The links brings you to a .7z file, that you can open with 7Zip).
  2. Open the .7z file and follow the instructions in INSTALL file: basically they said to extract top-level folders (i.e. bin and devkit) to the Ruby's root folder and to modify the contents of fstab file according to your installation. In my case, my Ruby folder was: C:\programmi\ruby19, so my fstab file contents became:
    C:\Programmi\Ruby19\devkit\gcc\3.4.5\mingw32 /mingw
    C:\Programmi\Ruby19\devkit\msys\1.0.11\usr\local /usr/local
  3. Execute the command gem install ruby-debug-ide19
    (Note that's fundamental to install ruby debug ide as ruby-debug-ide19 because RubyMine looks for a gem with name ruby-debug-ide19 and not ruby-debug-ide, as you would expect). Also be patient because the command takes a while to complete.
  4. Open with a text editor the file command.rb that's part of the installed ruby-debug-ide19 gem. In my case, that file was under folder C:\Programmi\Ruby19\lib\ruby\gems\1.9.1\gems\ruby-debug-ide19-0.4.12\lib\ruby-debug
  5. Modify the beginning of procedure debug_eval (at line 120) so to enter a new statement between statements str = str.to_s and max_time = 10. The new statement to enter is:
    return "" if str == "$FILENAME"

    At the end, the procedure debug_eval should begin like this:
    def debug_eval(str, b = get_binding)
      begin str = str.to_s
      return "" if str == "$FILENAME"
      max_time = 10
      to_inspect = str.gsub(/\\n/, "\n")
  6. Save the file
That's it. Enjoy Ruby debugging with RubyMine!

Friday, November 13, 2009

How to install the current Flash player into Chrome Portable/Firefox Portable on Windows

  1. Download the current Flash Player as xpi package from http://fpdownload.macromedia.com/get/flashplayer/xpi/current/flashplayer-win.xpi
  2. Rename the package's extension from .xpi to .zip
  3. Open the zip package and extract files flashplayer.xpt and NPSWF32.dll.
  4. For Chrome Portable: put extracted files into folder Chrome\plugins
  5. For Firefox Portable: put extracted files into folder App\Firefox\plugins
The current Flash player has now been installed into your portable browser. Let's verify the correctness of the installation.
  1. (Re)start your browser
  2. Type about:plugins in the address bar
  3. A list of installed plugins appears. Verify that Shockwave Flash is present and that there is an entry with MIME type application/x-shockwave-flash and suffix swf.
To check what's the version of the installed Flash player, open the page with URL http://kb2.adobe.com/cps/155/tn_15507.html

Saturday, January 31, 2009

Flash Player SecurityError: Error #2060

This post starts with a security error echoed by Flash Player: I'm talking about Error #2060, an error that is associated with the use of ExternalInterface.call.

For those of you that just don't remember what ExternalInterface is responsible of, I have to say that this class allows ActionScript to "talk" with the Flash Player container: in my current example, I was calling a JavaScript function from inside ActionScript. My idea was to allow ActionScript to run a user-specified Windows program through the intermediation of the ActiveX WScript.Shell, instantiated in a IE-managed HTML page.

So, the code for the ActionScript part looked like this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="402" height="22"
backgroundColor="white">
<mx:Script>
<![CDATA[
private static const JS_FUNCTION_NAME: String = "jsRunProgram";

private function callExternalProgram(programName:String):void {
if (ExternalInterface.available) {
ExternalInterface.call(JS_FUNCTION_NAME, programName);
}
}
]]>
</mx:Script>
<mx:Label text="External program to call:"
y="0"
fontWeight="bold"/>
<mx:TextInput id="txtProgramName"
text="notepad"
x="151" y="-2" width="198"
enter="callExternalProgram(txtProgramName.text)"/>
<mx:Button label="Run" x="352" y="-2"
click="callExternalProgram(txtProgramName.text)"/>
</mx:Application>

... and inside HTML page I had this JavaScript fragment:
<script language="javascript" >
function jsRunProgram(programName) {
shellObj = new ActiveXObject("WScript.Shell");
shellObj.run(programName);
}
</script>

The idea here is not obvious, but pretty simple: the user enters a program name in a Flex TextInput, then presses the Enter key and voilà... ActionScript calls the JavaScript function jsRunProgram providing it with the text just entered by the user. JavaScript, in turn, instantiates the ActiveX WScript.Shell and instructs it to run the program entered by the user. This way, ActionScript can run every Windows program the user typed: notepad, iexplore, cmd... just to name a few.

I developed this solution inside Adobe Flex Builder. Now, when I opened
inside the Flex Builder browser the HTML page containing the Flash control corresponding to the ActionScript code, all ran as expected. Cool!

The surprise came out when I closed the Flex Builder browser and tried to open the same page in IE. I couldn't believe my eyes: everytime ActionScript tried to call JavaScript a Flash error popped out complaining about error 2060: Security sandbox violation.

This behavior sounded so unbelievable to me for several reasons:
  1. Inside Flex Builder browser it ran without problems
  2. I couldn't imagine why Flash player had security concerns for accessing its containing HTML page.
I spent about a half weekend finding a solution.

Firstly, I browsed the Internet and I discovered that the same problem is not so uncommon. Some people suggest to deploy all the files in a web sever and, instead of accessing the HTML page via file system, access it via a HTTP connection to the web server. They say it works, but I was not interested in that solution primarily because I didn't want to introduce a web server.
So I didn't try that solution.

I found two different solutions.

The first:
  1. Change Flash Player security settings to allow it to access the local directory containing the HTML page. (To change Flash Player settings it's required to call this URL)
  2. Change IE security settings to allow the use of ActiveX WScript.Shell
The second:
  1. Rename the HTML page to HTA.

How to call a program as Windows service

It's really easy to call a program as a Windows service.
In order to proceed, you firstly need two programs: instsrv.exe and srvany.exe. These programs are produced by Microsoft and are parts of Windows Resource Kit Tools.

To call a program as a new Windows service, follow this procedure:
  1. Create a new directory, let's say winsrv, on drive c
  2. Store both instsrv.exe and srvany.exe on that directory
  3. Open a DOS window
  4. Type: cd /d c:\winsrv
  5. Type: instsrv "service name" c:\winsrv\srvany.exe
  6. Exit from DOS window
  7. Open regedit
  8. Navigate to this key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\service name
  9. Add a new key: Parameters
  10. Under the key Parameters, add these three string values: Application AppDirectory AppParameters
  11. Set the AppDirectory value to the directory where the program is stored into
  12. Set the Application value to the program name
  13. Set the AppParameters value to the command line parameters passed in program invocation
NOTE
In order to run the specified program, you may provide additional authentication information. This can be accomplished specifying log on parameters in the service properties.

To remove the new service, just follow this procedure:
  1. Open a DOS window
  2. Type cd /d c:\winsrv
  3. Type instsrv "service name" remove

Monday, December 29, 2008

Flex

For those who are still in doubt about how powerful Flex/AIR are, I have here a little example that shows how to build a generic RSS reader in just about a hundred of line of code.


This program acquires the news from a user-provided RSS source, lists all the news and allows the user to dig into each news double clicking on it. It's based on the AS xml syndication library as3syndicationlib.
... I have some doubts about the feasibility of such a simple thing in JavaFX.

;-)

Monday, December 08, 2008

Why I'm perplexed about JavaFX

JavaFX 1.0 is finally out.
I took a look at the official website and I saw a lot of good-looking gadgets: a video player, a puzzle whose pieces are parts of a video, a stopwatch and a lot more.

It's seems JavaFX wants to compete with Adobe Flash in bringing some special effect to the user's desktop.

Frankly and honestly, Sun's solution doesn't impress me much: still applets are loading s-l-o-w-l-y, too slow compared with Flash counterparts. Moreover Linux is not supported yet. I see that JavaFX site shows only special effects, like rotating cubes and so on, but I don't see any "serious" component that could help the programmer to display and manage database data easily: that means, for instance, that if you want to display a resultset, JavaFX doesn't provide you with some kind of datagrid component (à la Flex) and you have to build your own by yourself.

Maybe my conclusion is too severe, but I think that from a user point of view Flash is more responsive than JavaFX and for a developer interested in building enterprise-class RIA applications JavaFX is just inadequate compared with Flex.

Sunday, November 23, 2008

How to configure ToggleNic.exe to work with Windows XP italian

ToggleNic is a useful Windows tool for enabling and disabling network connections from the command prompt. It can be downloaded here.

After installation, ToggleNic is configured (by default) to run with the english version of Windows: in other words, it doesn't work with localized Windows version, like mine (italian).

In order to let it work with a localized Windows version, all you need to do is to modify the file ToggleNic.exe.config found inside ToggleNic installation folder.

This config file is a simple XML-based configuration file. Specifically, you need to look at (and change properly) these settings:
  • NetworkConnectionsFolderName
  • EnableVerbName
  • DisableVerbName
These items respectively collect: the localized names of network connections folder, the menu item corresponding to "enable connection" and the menu item corresponding to "disable connection". Obviously, for a localized Windows version, they cannot be like those in the default configuration.

For the italian version of Windows XP, I've checked the following values work.
  • NetworkConnectionsFolderName: Connessioni di rete
  • EnableVerbName: &amp;Abilita
  • DisableVerbName: &amp;Disabilita

Please notice the &amp; at the start of EnableVerbName and DisableVerbName: it's because menu items are provided with a keybord shortcut. (That's what &amp is meaning for).

A useful site for getting info on Windows processes

Sometimes it happens you don't know what a Windows running process is needed to or whether it's a normal Windows process or something different.

The Process Library site has a huge database of information about processes. So when in dubt...