android: howto dump logcat to file

adb logcat *:I -d >log.txt

*:I    all tags' log level above 'Info'
-d > log.txt    dump to file log.txt


DDMS is not reliable esp. for showing very frequent log display.
If frequent log analysis is required, I use adb logcat dump instead.


android: toggle stagefright

'build.prop' has a property for that.

# system props for the MM modules

#setprop media.stagefright.enable-player false
can turn off the stagefright and makes media player runs with opencore.


android: link third party static libraries with PREBUILT_STATIC_LIBRARY

You have to declare each library as LOCAL_MODULE.
And each LOCAL_SRC_FILES should have only one .a file.


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := foo
LOCAL_SRC_FILES := libfoo.a




include $(CLEAR_VARS)

LOCAL_LDLIBS := -llog -ldl


Now libbar.so will be built with third party library libfoo.a.

For the details, see ndk docs(ANDROID-MK.html and PREBUILTS.html).

p.s. You can NOT link static library to built a new static library in ndk.


PBKDF2 & symmetric crypto(such as AES)

PBKDF2(Password-Based Key Derivation Function)

salt + password -> key

salt: randomly generated #
password: passphrase
PBKDFS hashes password multiple times with salt to derive a key value.


data + (IV + key) -> encrypted data
encrypted data + (IV + key) -> data


android: activity's onResume vs onWindowFocusChanged

From activity.java onResume's comment:

Called after onRestoreInstanceState, onRestart, or onPause, for your activity to start interacting with the user. This is a good place to begin animations, open exclusive-access devices (such as the camera), etc.

Keep in mind that onResume is not the best indicator that your activity is visible to the user; a system window such as the keyguard may be in front. Use onWindowFocusChanged to know for certain that your activity is visible to the user (for example, to resume a game).

Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.


android: How to see the routing table and dns in adb shell

For checking DNS server addresses, you can use getprop, such
| # getprop net.dns1
or, if you'd like to know the values which dhcp server
| # getprop dhcp.tiwlan0.dns1
You also can see dhcp supply default gateway value:
| # getprop dhcp.tiwlan0.gateway
You might see all property values if you exec 'getprop'
without arguments.
If you'd like to see live routing table, the easiest(but
complicated to understand) way is to see /proc/net/route.
| # cat /proc/net/route
| Iface Destination     Gateway         Flags   RefCnt  Use     Metric  Mask            MTU     Window  IRTT
| tiwlan0       0020A8C0        00000000        0001    0       0       0       00FFFFFF        0       0       0
| tiwlan0       00000000        0120A8C0        0003    0       0       0       00000000        0       0       0
The Destination '00000000' means, of course, default route
and Gateway value '0120A8C0' means '' in
decimal('' in reverse), so you can know what is
default gateway address is.


linux: (link) changing network adapter priority

In short: Network card priority is decided by calculated routing speed so you cannot manually change it easily. However, you can set an adapter never to be a default network connection by setting 'Use this connection only for resources on its network' at 'System->Preferences->Network Connections->Edit->IPv4 Setting->Routes...'.


linux: how to setup your linux as internet gateway(Ubuntu 9.10)

There are many posts about this topic however some of them are quite old.
Here's the simple instruction of doing it.

0. Prerequisites

Linux machine with 2 network adapters.
A Laptop usually have two network adapters: one for LAN, one for Wi-fi.

Below, I have two adapters connected to:

  eth1: connected to private network
  wlan1: connected to internet

1. turn on ip forward functionality

open /etc/sysctl.conf
uncomment(or change if set to 0) net.ipv4.ip_forward = 1
$sysctl -p /etc/sysctl.conf

you can check whether it is correctly set or not with
$cat /proc/sys/net/ipv4/ip_forward

2. setup ip forwarding & masquerading

Reminder: wlan1 is to internet, eth1 is to intranet(local network)

$iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
$iptables -A FORWARD -i eth1 -j ACCEPT

Simply done.

Now change gateway of your local network pc to linux machine's IP address and you can use internet from your local network pc via linux gateway.

3. troubleshooting

If you cannot access internet from your local network pc, check linux machine's routing table.

$ip ro dev wlan1 proto kernel scope link src metric 2 dev eth1 proto kernel scope link src metric 1
default via dev eth1

As above, if eth1(private network) is set as default route, change default route to wlan1(internet) by:
$ip ro change default via xxx.xxx.xxx.xxx dev wlan1
$ip ro flush cache

where xxx.xxx.xxx.xxx is your wlan1(internet accessible adpater) gateway.