2011年1月13日 星期四

修改android package name

Package Explorer視窗上

Step 1:
  1. 找出src下的package name
  2. 滑鼠右鍵, Refactor, Rename -> 修改package
Step 2:
  1. 開啟AndroidManifest.xml
  2. 找出package -> 修改package name
Step 3:
  1. 點選你的Activity (也是在Package Explorer)按下滑鼠右鍵, Source, Organize Imports
Reference:

透過Facebook分享

Eason 生日快樂

去外面吃大餐


週歲的這天
會自己下床
很棒喔

透過Facebook分享

2011年1月11日 星期二

接上usb轉rs232的線 也可以使用adb shell登入

adb shell可以登入
ls
config
cache
sdcard
acct
mnt
d
etc
system
sys
sbin
proc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev


使用adb push
會回報 read-only file system

nelsonchung@ubuntu:/media/BE60E19860E15823/Ubuntu/myandroid9.1/ap/cv7000/Src/BrakeDetect/jni$ adb push Android.mk /
failed to copy 'Android.mk' to '//Android.mk': Read-only file system

透過Facebook分享

install minicom on Ubuntu

sudo apt-get install minicom

插上usb轉rs232線
在/dev下出現一個新的裝置ttyUSB0

接著設定minicom
sudo minicom
進入設定畫面
follow here 設定

但是設定/dev/ttyUSB0都會怪怪的
設定完
存檔
再開一次minicom都會讀到/dev/tty8USB0

於是手動修改home目錄下
.minirc.dfl
pu port /dev/ttyUSB0

重新開sudo minicom就ok嚕

透過Facebook分享

函式庫的三種類型

  1. 靜態(static)
  2. 共享(shared)
  3. 動態載入(dynamically loaded)
  • 靜態函式庫
程式對函式庫內函式的呼叫動作可以在編譯過程內就解析完成。程式與靜態函式庫連結的時候,函式庫內函式的位置都能立刻決定。並且為最後的執行檔預先解析好。
  • 共享函式庫
使用共享函式庫的程式裡頭連結函式庫的參考資料。這些資料提供程式執行時,由runtime link editor使用
命名規則: 檔名開頭為lib, 檔名結尾為.so
  • 動態載入函式庫
程式可以在執行的任何時候載入並使用的函式庫。與上述差異在於,是在於程式使用它的方式,而不是編譯器或執行環境環境的使用方式。所以靜態或共享函式庫都可以作為動態載入函式庫的使用。
用途在程式模組or plug-in功能。

參考:
GCC完全指南

透過Facebook分享

SL410 省電好幫手 - cpufreq-utils (靠降頻省電)

 安裝cpufreq-utils

nelsonchung@ubuntu:~/myandroid9.1/kernel_imx/Nelson/IoControl/app$ cpufreq-info
cpufrequtils 006: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0 1
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 10.0 us.
  hardware limits: 1.20 GHz - 2.10 GHz
  available frequency steps: 2.10 GHz, 2.10 GHz, 1.60 GHz, 1.20 GHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 1.20 GHz and 2.10 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 1.20 GHz.
  cpufreq stats: 2.10 GHz:16.53%, 2.10 GHz:2.60%, 1.60 GHz:2.64%, 1.20 GHz:78.23%  (415739)
analyzing CPU 1:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0 1
  CPUs which need to have their frequency coordinated by software: 1
  maximum transition latency: 10.0 us.
  hardware limits: 1.20 GHz - 2.10 GHz
  available frequency steps: 2.10 GHz, 2.10 GHz, 1.60 GHz, 1.20 GHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 1.20 GHz and 2.10 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 2.10 GHz.
  cpufreq stats: 2.10 GHz:16.60%, 2.10 GHz:2.58%, 1.60 GHz:2.68%, 1.20 GHz:78.13%  (427283)



解壓縮後
./batterymode.sh


showcpuinfo.sh: 顯示cpu freq information
goodperformance.sh: 將cpu frequence調到最高2.10GHz (請根據showcpuinfo.sh所顯示的資料來決定)
batterymode.sh:將cpu frequence調到最低1.20GHz(請根據showcpuinfo.sh所顯示的資料來決定)

透過Facebook分享

Run shell script from C code under android

follow this

I use system to launch shell script

return message
call system. return value is 7f00

source code
#include
#include

int main(int argv, char* agrvc)
{
int ret = system("/mnt/sdcard/Hello.sh");
printf("call system. return value is %x", ret);
}

使用execv
可以正確執行到shell script

source code
#include
#include

int main(int arg, char* agrc)
{
//int ret = system("/mnt/sdcard/Hello.sh");
char *argv[]={"bash", "/mnt/sdcard/Hello.sh", NULL};
int ret = execv("/system/bin/bash", argv);

printf("call system. return value is %x", ret);
}

螢幕顯示
This is shellscript. Hello!

此外
run executable file
你可以參考此篇


透過Facebook分享

Run executable file from C code

利用exe

#include
#include

int main(int arg, char* agrc)
{
int ret = execv("/hello", (char *)NULL);

printf("call system. return value is %x", ret);
}


透過Facebook分享

2011年1月10日 星期一

Run shell script from Android AP

可以使用Runtime.exec

參考這裡寫出可以run ls的Android AP.

我將String的部份修改成
String[] cmds = { "/system/bin/bash", "/mnt/sdcard/ModuleIns.sh" };
想要執行shell script

ModulesIns.sh的內容
#!/system/bin/bash
ls 

這樣子程式run起來可以list出根目錄下的內容

改成
#!/system/bin/bash
/system/bin/insmod /mnt/sdcard/Drv.ko

01-01 00:48:16.232: WARN/System.err(3665): insmod: init_module '/mnt/sdcard/Drv.ko' failed (Operation not permitted)

有權限問題


雖然有權限問題
but, 可以執行shell script

透過Facebook分享

Get Glibc source code form gnu web site

You can follow here
http://www.gnu.org/software/libc/#CurrentStatus

get source code

git clone git://sourceware.org/git/glibc.git


do branch

cd glibc
git checkout --track -b glibc-2_11-branch origin/release/2.11/master

From here and here
得知glibc是使用wrapper routines ( user level)
ap -> system call -> system call handler( kernel level) -> service rountine


androoid bionic 則是使用 system call stub去call system call

android bionic system function:


int
system(const char *command)
{
  pid_t pid;
sig_t intsave, quitsave;
sigset_t mask, omask;
int pstat;
char *argp[] = {"sh", "-c", NULL, NULL};

if (!command) /* just checking... */
return(1);

argp[2] = (char *)command;

sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &mask, &omask);
switch (pid = vfork()) {
case -1: /* error */
sigprocmask(SIG_SETMASK, &omask, NULL);
return(-1);
case 0: /* child */
sigprocmask(SIG_SETMASK, &omask, NULL);
execve(_PATH_BSHELL, argp, environ);
    _exit(127);
  }

intsave = (sig_t)  bsd_signal(SIGINT, SIG_IGN);
quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN);
pid = waitpid(pid, (int *)&pstat, 0);
sigprocmask(SIG_SETMASK, &omask, NULL);
(void)bsd_signal(SIGINT, intsave);
(void)bsd_signal(SIGQUIT, quitsave);
return (pid == -1 ? -1 : pstat);
}


glibc system 

/* Execute LINE as a shell command.  */
int
__libc_system (line)
     const char *line;
{
  if (line == NULL)
    return 0; /* This indicates no command processor.  */

  __set_errno (ENOSYS);
  return -1;
}
weak_alias (__libc_system, system)


stub_warning (system)
#include


It's a big difference.

透過Facebook分享