Some factoids about Air Quality and its measurement — My Take

For the last 5 days, we had experienced in Singapore what seems like a Hollywood movie script. “Crisis” loomed, leaders (perceived to be) giving bad decisions, people panic into revealing or rise to their true-selves.

SINGAPORE-INDONESIA-MALAYSIA-ENVIRONMENT-HAZE

Confusion, anger and desperation, partly because information was in bits and pieces in National Environment Agency (NEA) site. NEA website has finally re-organised it’s information with better clarity, although I think laymen would probably not understand. I thought I would share some of my takeaways after researching on the topic of air quality within and outside of NEA website. Some facts may well be my wrong interpretation, but all these are what I have concluded after going through NEA site, EPA/Airnow site, various countries environment agency sites such as Hong Kong, United States, Australia, Germany and UK.

  1. PM is no Prime Minister.  PM10 refers to particles of size less than 10 micron, which means it includes those that are smaller than 2.5 micron but bigger than 100 nanometer. Particulate matter is one of the pollutants used to measure air quality, and usually measured in terms of its concentration (microgram/cubic metre)
  2. PM10 versus PM2.5. Because PM10 include particles smaller than 2.5 micron, you would naturally expect concentration of PM10 to be higher than that of PM2.5. E.g. a PM10 concentration of 54 ug/m3 has the same air quality effect as a PM2.5 concentration of 12 μg/m3.
  3. PM10/PM2.5 concentration can be measured as 24 hour average, 3 hours average (in case of NEA for their 3 hours PSI computation), or hourly (used in Australia and some states in US).
  4. (NEA) PSI calculation method is similar to other air quality index used in other countries. Air quality index (or pollution standard index) looks at 5 pollutants (particulate matter, sulphur dioxide, carbon monoxide, ozone and nitrogen dioxide). The so called better AQI used in some countries, is because they look at PM2.5 concentration whereaas NEA looks at PM10. Each pollutant measure is sub-indexed based on a table of scale that corresponds to the concentration. For e.g. sub-index 50 is equivalent to 24 hour particulate matter concentration of 50 ug/m3, or 8 hour Ozone of 118 ug/m3. The PSI (or AQI) is then determined by taking the maximum sub-index of the 5 pollutants. So if PM10 index is 50, but Carbon monoxide index is 200, the air quality is indexed as 200.
  5. PSI is AQI, no? While NEA uses PM10 instead of PM2.5 to calculate the PSI (or AQI), it does report 24 hours PM2.5 separately, used to be every 4 hours but recently reported hourly due to the escalating haze. The PSI/AQI is therefore inaccurate, if every pollutant has low concentration, but the high concentration of particulate matter is mostly due to 2.5 micron or smaller particles. In recent haze incidents, this is not true though, mainly because the concentration of PM2.5 is exceptionally high, so even if PM2.5 pollutant is not used to measure air quality, it’s concentration is already reflected in PM10 measurement.
  6. PSI is not accurate? When 3-hour PSI is low, but PM2.5 concentration shows exceptionally high, that’s most probably because the latter is measured past 24 hour (in the case in Singapore). Only PM10 is measured on 3 hourly basis. Whether it’s 24 hour, 3 hour or 1 hour average, it shows AVERAGE measurement, and it does not correspond to what you see/smell NOW. Obviously, an 1 hourly average measurement will be closer to what you see, while a 24 hourly average will prevent unnecessary panic alarm (or false sense of comfort) due to a particular spike / drop. Therefore it is important to know the duration in which the pollutant or air quality is being measured, and used it accordingly.
  7. Hourly or 24 hourly average is the way going forward? When the air quality is already at hazardous level, a forecast measurement would be more helpful than an hourly or 3 hour reading, because one should already be taking the necessary precautionary measure against the haze. (This is just my take)
  8. Hourly or Real time AQI? Not all countries are using true hourly air quality index measurement. In Beijing and Hong Kong, the hourly report pollutants based on the same definition as Singapore. e.g. it uses 24 hour PM10 concentration at 1500 hrs for a 1500 hr AQI calculation. In US, not all states have 1 hour average PM2.5 / PM10 concentration reading (e.g. Colorado state), let alone 1 hour AQI. In Germany and UK, there’s no reports of 1 hour average measurement. In Australia, it does look like all states have 1 hour moving average readings (at least 2 out of 2 states I checked have 1 hour average readings). Last but not least, NO countries provide real time measurement of air quality index, or the associated pollutants.

Conclusion

I do stand corrected for the above interpretation, but the purpose of the writing is because I read too many postings and accusation that’s based on seriously wrong assumption or understanding. I hope this doesn’t create more confusion than it is already in the cyberspace. If I have more time, I will reference some of the sites to the above points so that you can read for yourself if I have interpreted wrongly or not.

Appendix

London AQI definition http://uk-air.defra.gov.uk/latest/currentlevels

Run for Food: 1000km milestone!

It has been more than 11 months since I started my running regiment. Today, I reached the milestone of completing 1000km of running. It is not a lot for a seasoned runner, but certainly a magic number for me. 11 months ago, I would not have thought I would clock a mileage of 100km, let alone 1000km.

 

 

From the chart, you can tell that I had cut down my running activities in Aug – Sept period. It was due to the injury I sustained in August, and in fact am still recovering from it. Thankfully, it didn’t hold me from attaining my goal.

Incidentally, I had curry fishhead for dinner, what a way to celebrate the goal accomplishment, and keep the motivation going!

Run for Food: Swimming as effective weight loss exercise?

Ever since I had started swimming 3 weeks ago, I had observed my body is responding to the exercise much better than before. This is despite after reading about swimming burns less calories, or how it is less effective than running in achieving weight loss.

Apart from feeling the ache of my body muscles all round after a swim,  versus the feeling of ligament strains after a run, I thought I have become leaner after 3 weeks if daily swim, at least psychologically.

Here’s my reasoning; It is an established fact that exercising burns different source of our body “fuel” (fat, carbohydrates, protein, etc), depending on the zone that our heart is exercising. At aerobic zone, our body burns more calories than exercising at fitness zone, while consuming a more balance percentage of energy source between fat and carbohydrates.  Unless I am on low carbohydrates diet, aerobic zone is the most effective weight loss zone.  Having run for 9 months, I know it is not an easy to keep to aerobic zone throughout the one hour of running, probably due to the loss of body fluid. On the other hand, I noticed that I can keep to the aerobic zone consistently regardless of whether I stick to a 30 mins or 1 hour swimming session.

Back on swimming, I am never been a natural swimmer from the onset. I do not feel comfortable when in the water, even when I could stay a float or swim. For a long while, I would have struggled to complete a 100m  freestyle, let alone a long distance freestyle swim. In the last 3 weeks of swimming, I have been doing one lap of  freestyle with one lap of  breast stroke routine for my swim. The breast stroke is more like a rest stroke for me to catch my breathing before doing the next freestyle lap. But 2.5 weeks of consecutive swimming seems to have paid off.

Me Swimming

On 12th September, I managed to stretch my swimming distance to 2.5km, albeit with the alternate strokes method. Despite four consecutive days of 2km (with one of them being 2.5km) swims, I did not feel any more fatigue, unlike a week ago. While I only completed a 1.5km distance on the 5th swim day (I had originally planned for a 1km swim) I actually completed a 40 continuous laps (or 1km) of freestyle swim. It is simply amazing that after 40 years, I have finally achieved this feat.

With all said, I figure that I should try and improve my strokes so that I can breathe on the alternate sides. That would probably be my next goal while continuing to stretch my freestyle swimming distance. In the meantime, I am looking forward for my next run (target to be a week later), as I am confident that 4 weeks of daily swimming should bring some positive impact to my running sessions.

Exercise Statistics Dashboard (as of 14th September 2012)

 Activity Type  Activity Counts  Activity Distance (km)
 Running  120  862.12
 Cycling  8  220.5
 Swimming  11  26.1

Animal Protection – It starts with you

Ministry of National Development had recently set up an online survey, to collate public feedback on pet ownership and stray management policies. If you have not already done so ( in giving your feedback), it’s high time you do so, whether you are a pet lovers or not. At least, the authority would be able to tweak their policies so to protect the innocent animals while making sure all the ‘troublesome’ human-beings happy (Note: I am referring to both pet and non-pet lovers, as I think human beings are always the problematic one, not the animals themselves)

For me, I think the stray issues need to be dealt with a multi-pronged approach;

1. Pet Homing policies to curb the overcrowding situation in the animal shelters.

The HDB policy on pet ownership should be revisited, so that it would be more supportive in homing of medium dogs. In helping to re-home the stray animals which a significant number of them do not meet HDB guidelines, whether it’s an “all inclusive” or “by exception” policy, it will go a long way to address or mitigate the overcrowding challenge that the animal shelters are facing today. This will also give some hope to the poor homeless, abandoned animals as they deserve better than what they are receiving today.

2. AVA policies to protect the puppies who are helplessly mishandled by the unethical pet commercial entities

OK, not all pet shops or farms are unethical. But that does not mean there is none in this “dark” industry as they disregard the welfare of the baby animals. We do not expect any pet commercial entities to run like an animal welfare association. But at minimum they should and must be pet lovers. A pet lover would not have done what some of us had encountered ourselves, which I had recently blogged in a true revelation of a pet warehouse and the feedbacks I had gathered from the like-minded pet lovers.

The authority could do more to keep such irresponsible entities in check. Do not believe on what some of the companies would say in their “PR-tically” right statements, as some of them are just wolf wearing the skin of a sheep. They might project themselves to be animal lovers, but in reality they are just taking the poor animals as a mere commodity.

We need AVA help to weed out such socially irresponsible dog breeders/sellers, so we do not have a situation of animal ill treatment.  We would also be able to minimize the number of stray dogs. Many of these dogs were abandoned partly due to these scrupulous commercial entities. They will hard-sell their “commodities” to potential pet owners who are not ready yet for pets.The end result? Abandoned animals.

3. Educate potential pet owners about the responsibility of being one

The saying goes, it takes two hands to clap, and the stray situation is no different. If all potential pet owners were to do their homework, on what their duties are in owning a pet, then we would know the pet will be in the goods hand of a responsible owner. The unfortunate truth is a lot of potential pet owners do not. They would therefore be easily swayed by the sweet-talk of the sales people, and the cute-innocent look of the puppies. By the time they bring their “toy” back home, they will realize that the life of a pet owner is not as easy as one have made it out to be. Issues of strays and/or mistreatment by pet owners are brewed as a result.

4. Execute, and execute wisely and properly.

With all the policies in place, it’ll be useless if they are not governed or executed well. A case in point is a recent incident involving a restaurant suspected of selling dog meat. The officers made a first trip to the restaurant for preliminary check, and then subsequently made a second trip to the restaurant again to obtain meat samples. Perhaps they were just following the protocols, but for heaven sake, exercise some common sense because what they had done was just plain meaningless. The restaurant could have gotten sufficient lead time to cover up their bad deeds, if they were indeed guilty. Do more mystery or surprise audit check on these commercial entities where there’s suspect of cruelty treatment of animals, I am sure one will see a different story, and one that matches the reality.

And it is not just with the authorities that should get their acts together, the society needs to play its part as well. As pet owners, we need to do what is necessary to keep our pets clean and happy, but not forgetting to stay in harmony with our fellow neighbors and friends who may not necessary a pet lover. For non pet lovers, let’s exercise some graciousness, for I am sure there are other things you like to do which others may not. But more importantly, if we all exercise our capability as human being in doing what we can to protect the innocent animals, we would not have seen the proliferation of the “pet warehouse” in the recent years.

So let’s take the first step. Let’s give our feedback to MND 🙂

 

Assembly 101 on Android Dalvik Code

Recently, I have been meddling with Android theme resources to modify the theme for my Android-based Galaxy Tab. It was yet another great learning process,  which involves manipulating the graphic resources, replacing the de-compiled XMLs that control the layouts and styling of the interface, etc. Just as I thought I had enough of them, I fumbled on a theming problem which seemed so impossible to fix. I pinpointed the offending code, created the right “answer” to the problem,  but it just didn’t work!

Almost giving up, I decided to trace the source code of the module. It turns out that the code explicitly sets the color of the text (the theming “bug”), and thus all the layout and style modification attempts would not have any effect at all.

   if (entry.label != null) {
            holder.appName.setText(entry.label);
            holder.appName.setTextColor(getResources().getColorStateList(
            entry.info.enabled ? android.R.color.primary_text_dark : android.R.color.secondary_text_dark));
   }

Instead of going back to source codes for changes, I contemplated reverse-engineering. Thankfully with the help of smali, an assembler/disassembler tool for Android apk,  I could correct the problem on the executable directly. Addictive Tips  gave a good overview of an Android application in ODEX and DEODEX format,

WHAT IS AN ODEX FILE?

In Android file system, applications come in packages with the extension .apk. These application packages, or APKs contain certain .odex files whose supposed function is to save space. These ‘odex’ files are actually collections of parts of an application that are optimized before booting. Doing so speeds up the boot process, as it preloads part of an application. On the other hand, it also makes hacking those applications difficult because a part of the coding has already been extracted to another location before execution.

THEN COMES DEODEX

Deodexing is basically repackaging of these APKs in a certain way, such that they are reassembled intoclasses.dex files. By doing that, all pieces of an application package are put together back in one place, thus eliminating the worry of a modified APK conflicting with some separate odexed parts.

In summary, Deodexed ROMs (or APKs) have all their application packages put back together in one place, allowing for easy modification such as theming. Since no pieces of code are coming from any external location, custom ROMs or APKs are always deodexed to ensure integrity.

So before I could attempt the “hack”, the application must be DEODEX’ed, so that we have the complete executable for disassembly. The executable in Android system is in .dex format, or Dalvik Executable, and is stored as classes.dex within the Android Package (.apk) along with other application resources (graphic resources, layout binaries, etc). I extracted out the classes.dex, and do a disassembly.

java -jar baksmali.jar -o out  classes.dex

This will disassemble the executable classes.dex into assembly codes in the folder named out. This step can be skipped if you have previously used APK Tool to decompile Android package to access to the XML codes. The latter however would not assemble the assembly codes when you compile using the tool, so the subsequent steps would still be required if you have made changes to the assembly code.

In my case, the offending code is ManageApplications$ApplicationsAdapter, and the section of the code matches the

    invoke-virtual {v3, v4}, Landroid/content/res/Resources;->getColorStateList(I)Landroid/content/res/ColorStateList;

    move-result-object v3

    invoke-virtual {v2, v3}, Landroid/widget/TextView;->setTextColor(Landroid/content/res/ColorStateList;)V

I simply commented off the third line in the above section of the code, which effectively eliminates the set color instruction. I proceeded to re-assemble the codes,

 java -jar smali.jar -o  classes.dex  out

The output of the assembler is a modified classes.dex, which I then re-package it to the original APK (Settings.apk).

A coat of gingerbread paint on the Galaxy Tab

As mentioned in my previous blog post, I have been experimenting on the Android UI theme work in the last 2 weeks. Last weekend I thought I made the most progress in terms of establishing a deeper understanding of the Android UI framework, and in the process overcame one of the theming roadblock that I have not been able to google a satisfactory answer for.

I have compiled the summary of my theming experiment, and updated that in the previous blog post. In that update, not only I have summarised the key steps to de-compile and re-compile the UI framework, I have also outlined the key components of the de-compiled source where the changes being made and the general effect the change achieved consequently. I could have missed a couple of components, as I did the summary based on my memory re-collection, and as you know, my memory has appeared to be falling lately.

I hope this helps anybody who is interested to theme an Android phone. Feel free to drop your questions or comments if you need help, clarification or correction to what have been shared. I will try my best to answer in the limited capacity I have.

Android UI resource framework for Galaxy Tab

This slideshow requires JavaScript.

A while back I ventured into kernel programming when I tried to meddle with the kernel for my Samsung Galaxy S.  (although in reality, it’s more of modifying the kernel)  I thought I would have stopped my venturing but I guess (geek) habit dies hard. Having spent some time recently to modify the otherwise boring UI of my Galaxy Tablet, I had thought about doing a write up, on  how Android manages its UI resources, i.e. framework-res.apk.

However, time is not at my end, as recent office workload shifts have basically stolen all my  time from my hobby. So I am just going to share what I have created (only applicable for Samsung Galaxy Tablet), and if there is anybody who want to know I do it, I can always try to capture bits by bits of what I have learnt and share whatever I know.

It took me awhile to figure out the intricacies of the framework-res, so I hope you will appreciate/like the latest work!

The mod can be downloaded from this xda thread. The remaining of this article will be updated as and when I have the time, and questions I get about the resource framework.

Steps to modify Framework-res.apk

  1. Decompile the Framework using APKTool.JAR. The command to execute a decompilation is     java -jar apktool.jar d framework-res.apk  <directory-where-decompiled-resources-reside>
  2. Modify the XML resources and/or replace the PNG resource files as you wish
  3. Compile the Framework using APKTool.JAR again. The command to  java -jar apktool.jar b <directory-where-decompiled-resources-reside>
  4. Once the resource is compiled, the newly compiled APK can be found in the dist folder of the framework-res
  5. Before replacing the framework-res.apk in your android device with the newly compiled apk, you need to make sure the newly compiled apk has the META-INF folder and that the AndroidManifest.xml is replaced with the original version. Failure to do so will result in “bootloop”!
  6. For other system apps APK (e.g. Settings.apk), the steps are similiar (i.e. step 1 to 4), except that you do the reverse in step 5.  Instead of copying META-INF folder to your newly compiled APK, copy the res folder and file resource.arsc from the newly compiled APK to the source or original APK. Make sure you copy w/o compressing the files/folder  (i.e. using store mode if you are using WinRAR)

Structure of Res folder in Framework-res.apk

Drawable – controls how the graphics should be rendered under event such as an animation

    •  progress_horizontal.xml – Modify all the color elements to reflect the progress bar
    • stat_sys_battery – Modify the elements to reflect the battery level
    • stat_sys_battery – Modify the elements to reflect the animation of the battery

Drawable-hdpi – Replace the PNGs accordingly for the desirable theme look and feel

    • btn_check_* – for all check buttons design
    • btn_* – for all other type of buttons design
    • ic_* – for all icons used in system wide UI such as menu, etc.
    • menu_* – for the theme design of the menu
    • progressbar_* – to show the indeterminate state of the progress (e.g. in Market, trying to estimate the download size)
    • spinner_* – for the animation of the wait cursor
    • stat_sys_battery* – for the animation and status of battery level
    • stat_sys_* – for icons used in status bar to show status of system services such as signal, wifi, etc
    • stat_* – for all the other icons used in the status bar
    • statusbar_background.9 – for the background theme of the status bar (it’s a .9 png, which means you need to have 1 px border around the original design)
    • status_* – for the interface of the notification window (drop down from the status bar)
    • zzzz_quickpanel_brightness* – for the design of the brightness setting in the quick panel
    • zzzz_quickpanel_icon* – for the design of the icons on the quick panel shortcuts.

Layout – Controls the layout of the UI controls used in Android system wide.

    • preference.xml – Modify the text color of the TextView control, particularly to address the theming needs of the Account Sync screen in “Account & Sync” Settings
    • zzzz_quickpanel_brightness_settings.xml – Modify the text color of the CheckBox control

Values – Configures theme setting such as Colors, Styles, etc 

    •  Styles.xml – Modify the styles to reflect the black theme
      • Theme – “inverse” the color of text
      • Theme.Icon – change the color of the divider (set to dark for dark background)
      • Widget.IconMenu – change the color of the text
      • Widget.TextView.ListSeparator – change the color of the text and background in the separator
      • Theme.ExpandedMenu – change the color of the menu in “More”
      • textColorTertiary – inverse the color

Structure of Res folder in Settings.apk

Drawable-hdpi – Replace the PNGs accordingly for the desirable theme look and feel 

    • ic_settings* – Replace the icons in the setting window according to the desire theme look and feel.
    • ic_wifi* – Replace the icons in the wifi setting window according to the desired theme look and feel

Layout – Controls the layout of the UI controls used in Android system wide.

    • preference_dialog_brightness.xml – change the color of the text in the dialog box (for brightness, contrast and color density setting dialog box)

Values – Configures theme setting such as Colors, Styles, etc

    • style.xml – Modify the whitestyle to use normal or Black theme.

Structure of Res folder in Phone.apk

Values – Configures theme setting such as Colors, Styles, etc

    • style.xml – Modify the whitestyle to use normal or Black theme.

Structure of Res folder in AccountAndSyncSettings.apk

Drawable-hdpi – Replace the PNGs accordingly for the desirable theme look and feel

    • ic_list* – Replace the icons in the setting window according to the desire theme look and feel.

Layout – Controls the layout of the UI controls used in Android system wide.

    • title.xml – change the text color of the Account type and title in “Account Sync Screen”
    • account_sync_screen.xml – change the background of the ListView control (background + colorhintcache)

Values – Configures theme setting such as Colors, Styles, etc

    • style.xml – Modify the whitestyle to use normal or Black theme.

Mobile Broadband Comparison Test – M1 vs Starhub

Green (StarHub) vs Orange (M1)

 

 

Despite being a long time customer with StarHub, I have decided to sign up a new line with M1, for my Galaxy Tab. I could have just subscribed a second sim card from StarHub, instead of a second line. But a recent incident with StarHub triggered my resolution to look at other options. Signing up M1 gives me the opportunity to evaluate their mobile services. Having lived with a mediocre mobile broadband service from StarHub, I was looking forward to M1’s offering, after all had been said about their services.

Here is the video of the comparison test. Test was carried out by running the speedtest application. I did not perform practical test such as timing of web page loading so that might be the next thing I could do. The outcome of the test was least surprising; On average, M1’s download/upload speed were rated at 1.7Mbps and 2Mbps respectively. StarHub, on the otherhand, scored a measly speed of 250kbps (download) and 125kbps (upload)!  The result was consistent with my frustrating experience all these years, where I even had to convince Starhub about the poor data coverage in areas where I normally surf using my mobile.

So it is high time we exercise our rights as an informed customer;  No more management escalation or contract termination threats. We have to act on our talk. The message (to the poor performing vendor) could not have been clearer when we bring our business somewhere else. In this case, it’s bye bye to Starhub if they continue to slack and do not buck up. Adios!