My R&D World

All Things R&D

Monthly Archives: June 2012

Fglrx begin to abandon chipsets older than HD5000 series

The newest fglrx in Gentoo portage (x11-drivers/ati-drivers–12.6_beta) only supports Radeon Evergreen (HD5000 Series) and newer chipsets, which means the graphic card (Radeon HD 3650) on my Lenovo Thinkpad T500 was abandoned by fglrx.

I have to consider transferring to radeon in the future.

GSoC 2012 Weekly Report on OI WebIntents Agent (June 18-24)

Hi,

Last week I was trying to integrate Android apps for web intent invocations. The task is much harder than I thought, and it is only half-done now. Here I would like to share a screen shot for the button click event at http://examples.webintents.org/usage/startActivity/index.html.

Now at least two problems are in the way:

  1. How to map a Web intent to its corresponding Android intents
  2. How to transfer data of types other than ’text/*‘

I am afraid I may not solve the two perfectly at current stage but I will try every effort.

Next week I will continue with the remaining integration work. If it is done, I will start with developing the management interfaces of the intents registry.

I would appreciate very much if you have any feedback.

Cheers

GSoC 2012 Weekly Report on OI WebIntents Agent (June 11-17)

Hi there,

In the last week, I solved the login issue of Twitter. It’s a problem of cookie management during HTTP transactions. I’ve written an article on how to make cookie set-get operations when making HTTP request-response by your self. The github code has been updated. It should be much better than the last version.

Another big change is that I created a CustomWebView class and overrode its loadUrl method instead of the previous shouldOverrideUrlLoading of the default WebView class. It’s my fault for past detours. I should have used this method earlier.

Another activity class named “org.openintents.wiagent.ui.WebIntentsAgentActivity” was created for naming reasons, it was to substitute for the work of WIAgentWebView which will be disposed of in the future. As for all the class changes which relate to the design part, I will update the design report before middle-term evaluation.

Some one told me the fire of “DOMContentLoaded” is much faster than “onload”. I spent one afternoon in testing their performance. For mobile devices, DOMContentLoaded is indeed faster than onload (around 60 seconds, so slow for onload). But it still be not enough for this project (I think it might be a result of the Webkit two pass layout for mobile versions, i.e. rendering first, others later). So I think the method of Javascript injection which I used in applying will be abandoned in this project.

I couldn’t make it to add local apps to the suggested application list last week. That continues to be on my schedule for this week.

Cheers

Cookie Management in Android Web Apps Development

I write this article because cookie management was a big issue which I spent quite some time on it in my GSoC2012 project but Google provides little reference.

Google engineers suggested using HttpURLConnection which would be a trend instead of Apache HTTP Client in this blog. However, HttpURLConnection has far less APIs than Apache HTTP Client which makes new programmers a little confused on how to manage cookies during HTTP request-response transactions. Even the reference of HttpURLConnection provides little useful materials on this field but only suggest using vm-wide cookie manager.

Actually, android.webkit has a very useful cookie manager which makes our programming much easier. Its full name is “android.webkit.CookieManager”.

Below is the code script which I use for cookie management in HTTP request-response.

HttpURLConnection urlConnection = null;
try {
    urlConnection = (HttpURLConnection) url.openConnection();

    // Set cookies in requests
    CookieManager cookieManager = CookieManager.getInstance();
    String cookie = cookieManager.getCookie(urlConnection.getURL().toString());
    if (cookie != null) {
        urlConnection.setRequestProperty("Cookie", cookie);
    }
    urlConnection.connect();

    // Get cookies from responses and save into the cookie manager
    List cookieList = urlConnection.getHeaderFields().get("Set-Cookie");
    if (cookieList != null) {
        for (String cookieTemp : cookieList) {
            cookieManager.setCookie(urlConnection.getURL().toString(), cookieTemp);
        }
    }

    InputStream in = new BufferedInputStream (urlConnection.getInputStream());
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (urlConnection != null) {
        urlConnection.disconnect();
    }
}

Line 6 returns a singleton CookieManager so you don’t have to worry about cookie lost when using it in different places. Line 14 is to get cookies if the response message has multiple “Set-Cookie” fields.

Cookies are critical in login system of many websites. Hope this article will help you.

GSoC 2012 Weekly Report on OI WebIntents Agent (June 3-10)

Hi there,

Eventually, I escaped the annoying and frustrating realm surrounded by GFW and made it to have access to Twitter and all the websites I need.

This week, I implemented the simple share activity, though still with some bugs. The app starts with a local html file including links online. When you click the link, it will redirect you to the onlne “startActivity” page from webintent.org. The reason for this is that I need to change the page code before it is loaded into the WebView.  The button of the page will start an “http://webintents.org/share” activity. Then our agent  will suggest you with related registered apps, Twitter now.

The function is now very simple and buggy. The main cause is the limited api of android.webkit. It seems sometimes “shouldOverrideUrlLoading” does not get called as I want. I think I should discuss with others on this problem.

Next step, I plan to let the suggested apps having local Android apps on the list which is one of the goals of this project.

The latest code has been published. Because of my skills, I believe they are not very good. Any feedbacks are welcome.

Thanks

GSoC 2012 Weekly Report on OI WebIntents Agent (May 22-June 2)

Hi,

Sorry for the currently slow development.

Since my blog at wordpress.com is blocked by GFW, I have submit this week’s report here. Next week I will go back to Canada and everything will be back to normal.

The current published version of the agent runs far less reliable on intent invocation grab of some examples at http://examples.webintents.org/, especially for those in iframes. The reason is because a bug from Javascript same orgin policy being created after the website had been updated.

My former idea was to insert Javascript code before WebView loading corresponding pages which let the Java code on Android grab intent invocations. I was trying to insert the code in the method “onPagefinished” of WebViewClient. But after many tests, I found the solution is unreliable. Because the connection speed of mobile devices is far less than a desktop computer, the moment when this method get called is slow and uncertain. The user may often have to wait several minutes for my inserted scripts to execute. This problem also happens to the “onload” event.

Now I am overriding the method “shouldOverrideUrlLoading” of WebViewClient by getting Http response in my own code, modifying the data and loading it into WebView. The initial development goes smoothly and I have succeed in grabbing the intents invocation at http://examples.webintents.org/usage/startActivity/index.html.

A problem is when “shouldOverrideUrlLoading” gets called. I’ve tested some conditions and it only didn’t get called when loading url in “onCreate” method of Activity. I can work around this as long as the first shown page of the app not containing any intents invocation.

In the next week, I will focus on this new solution to get it working on web twitter.