Monday, July 4, 2011

Android Kill Self-process

I came across a line of source code written by some others today, and it gives me a behavior I have never thought about. The whole application (simplified version) consists of two activities. A user first launches up the main activity and clicks a button in this activity. This starts the second activity. The user then clicks a button in the second activity, and this line is called:


I thought the whole application will be killed and the system will go back to home screen but it does not. Instead the application goes back to main activity and calls its onCreate() again. I am surprised, and then I did a test. I added finish() in main activity after startActivity(). This time, killing the process just closed the whole application.

I tried to search for the reason of this behavior but I cannot find out the answer. Normally, processes are managed by Android system and one should not handle them himself. I believe this behavior is because some resource is not freed yet when the process is killed, and the system thinks the application should relaunch (or it thinks the application is still launching for the first time?).

Sunday, May 29, 2011

Some Notes about GINA

GINA (Graphical Identification and Authentication) is a component which works with Winlogon to provide secure authentication and interactive logon services for Windows before Windows Vista. GINA is implemented as a replaceable dynamic link library (DLL), so that one can customize it by writing his own DLL. For GINA basics, please read them here. Below I would like to make some notes about problems I met while developing a customized GINA. I will expand the list when I find something new.
  1. Do not call WlxSasNotify() to notify Winlogon for a SAS (Secure Attention Sequence, normally Ctrl+Alt+Del) in a thread different from the GINA thread. In my case, I post a message using PostMessage() SendMessage() to the SAS dialog box and call WlxSasNotify() there. Otherwise, the machine failed to shut down after recovering from hibernate.
  2. Normally, Winlogon will capture a SAS appearance and call appropriate GINA functions. If you are replacing it with something else (so you are not triggering SAS manually), I have found that Winlogon may fail to call those GINA functions and results in halting between logon and logoff/locked states. Therefore you should notify Winlogon using WlxSasNotify(). However, you cannot just call WlxSasNotify() in anywhere, otherwise you may trigger some other abnormal behavior. After trial and error, I found that only calling WlxSasNotify() from the dialog box gives out normal results.
Update: Using PostMessage() will trigger another bug (cannot shut down after recovering from standby)

Sunday, April 3, 2011

Static Class Member Variables in C++

Recently when I tried to write a class with static member functions and variables, I found a strange linking error. No matter how I tried, the linker did not seem to be able to link those static member variables properly. After some searching, it seems to be a common compiler "feature" of C++....

In order to define the variable, define it outside the class definition, but the declaration is still inside the class.