2014年2月18日 星期二

android adb

一、adb連線方式
Android default adb是使用USB連線,但也可以透過ethernet或是wifi
如果要改設adb的模式
1. usb to ethernet(wifi)
in device端
$su
$setprop service.adb.tcp.port 5555
$stop adbd
$start adbd

in computer端
$adb tcpip 5555
$adb connect 192.168.0.101:5555 

2. 如果要將adb改成usb連線
in device端
$setprop service.adb.tcp.port -1 
$stop adbd 
$start adbd


二、如何啟動adbd

adb實際是透過adbd(adb daemon )在運作的,android 本身有透過property "persist.service.adb.enable"去儲存adbd的狀態,透過更改值為0或1來啟動或停止adb. 例如在init.rc中設定啟動及停止的條件

add property in init.rc
on property:persist.service.adb.enable=1 
    start adbd 
on property:persist.service.adb.enable=0 
    stop adbd

這樣就可以在 runtime中,藉由修改property 來達到改變adb狀態

三、取得adb id
$adb shell id


2013年8月9日 星期五

Android Makefile

1. build binary file to host; out/host/linux-x86/bin/xxx

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PREBUILT_EXECUTABLES := aaa
include $(BUILD_HOST_PREBUILT)


2. build prebuilt APK to system/app

include $(CLEAR_VARS)
LOCAL_MODULE := install_flash_player
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)

3. build multiple prebuilt lib to system/lib

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PREBUILT_LIBS := libflashplayer.so \
  libysshared.so
LOCAL_SHARED_LIBRARIES := libflashplayer \
 libysshared
include $(BUILD_MULTI_PREBUILT)

4. build prebuilt binary file to system/bin

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := bbb
LOCAL_MODULE := bbb
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
prebuilt_files :=
$(call add-prebuilt-files, EXECUTABLES, $(prebuilt_files))

5. build .jar

LOCAL_PATH:= $(call my-dir)
#MAKE_JAR
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_MODULE := selfthread
LOCAL_MODULE_TAGS := optional
#need these jar built first, used in code base: core, ext, framework
LOCAL_JAVA_LIBRARIES := core ext framework
include $(BUILD_JAVA_LIBRARY)
#MAKE_XML
include $(CLEAR_VARS)
LOCAL_MODULE := selfthreadxml.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)

6. execute shell script in Android make file

#one shell call shell command once, if you don't want exit shell, use ";"
#use "``", in some environment it will shoe missing separator
#example $(shell `pwd`)
PWD := $(shell pwd)/vendor/company/anymote-protocol/java
$(shell `echo $(PWD)`)
$(shell `cd $(PWD);\
make;\
cd -`)

#or in one line
$(shell `cd $(PWD);make;cd -`)

#if use target, type $mm target, but default won't execute it, example
#$mm anymote
anymote:
cd vendor/company/anymote-protocol/java;\
echo `pwd`;\
make;\
cd -

7. make order, for example, run anymote.mk, polo.mk first

LOCAL_PATH:= $(call my-dir)
include $(call all-makefiles-under, $(LOCAL_PATH))

include $(ANDROID_BUILD_TOP)/vendor/company/anymote-protocol/java/anymote.mk
include $(ANDROID_BUILD_TOP)/vendor/company/google-tv-pairing-protocol/java/polo.mk

8. what is different with all-subdir-makefiles and all-makefiles-under

all-subdir-makefiles: 表示“當前目錄下沒有需要編譯的文件,請向子目錄深入”,是告訴編譯器繼續向目錄深處遞迴的一種寫法。
all-makefiles-under: 為當前目錄下有文件需要編譯,而且在當前目錄下還有子目錄,子目錄中也有文件需要編譯,同樣也要包含告訴編譯器在編譯完當前目錄下的文件後,繼續向子目錄深入的語句。

2013年5月24日 星期五

Android Resource

How get Resource

1. getResources().getString(android.R.string.cancel);
2. Resources.getSystem().getString(android.R.string.cancel);
3. getString(android.R.string.cancel);

The first and the third ones are using "context." invisibly. So, very often (in static members or out of activity members) you can't use them directly, unless you pass context or resource as a static variable or as a parameter into your scope. But the second one

Resources.getSystem().getString(android.R.string.cancel)
You can use ABSOLUTELY EVERYWHERE in your application, even in static constants declaration! But for system resources only


GetLocals


Resources.getSystem().getassets().getLocals()
getAsset() 是從下列路徑取得,不是從frameowrks-res.apk中取得
framework/base/core/java/android/content/res/AssetManager.java
framework/base/core/jni/android_util_AssetManager.cpp
framework/base/include/utils/AssetManager.h
framework/base/libs/utils/AssetManager.cpp
framework/base/libs/utils/ResourceTypes.cpp




2012年7月9日 星期一

重建Ubuntu MBR

Ubuntu的MBR不見了,只剩下windows的MBR
1. 準備Ubuntu LiveCD
2. 利用Ubuntu LiveCD開機
3. 進入terminal
    # cd /
    # sudo -s -H
    # mount -t ext4 /dev/sda6 /mnt      ->sda6為Ubuntu所在的磁區
    # mount -t proc proc /mnt/proc
    # mount -t sysfs /sys /mnt/sys
    # mount -o bind /dev /mnt/dev
    # chroot /mnt /bin/bash         ->切換 root到硬碟上的Ubuntu

如果不知道Ubuntu在那一個磁區,查詢硬碟上的partition資訊    
    # ls -l /dev/disk/by-label
    # fdisk -l

安裝grub2
    # aptitude install grub2 grub-pc

如果已經安裝了grub,先移除
    # apt-get pruge grub

更新grub
   # update-grub
   # grub-install /dev/sda
   # reboot
恢復原先Ubuntu的grub

如果開機後,沒有任何開機選單,只出現
  grub >  -> 這代表沒有grub menu
  grub > find /boot/grub/core.img
  grub > root (hd0, 5)    -> root (hdx, y) previous command will tell you the x, y in this case is (hd0, 5)
  grub > kernel /boot/grub/core.img
  grub > boot
  現在可以進入Ubuntu 系統

如果開機會直接進入Ubuntu,沒有menu可以選擇要那個OS
   # update-grub
  讓 grub自動建立menu.list, 檔案位置在/boot/grub/menu.list
  grub2沒有menu.list,是grub.cfg, 檔案位置在/boot/grub/grub/cfg

2012年7月6日 星期五

git 相關

git error
fatal: unable to create 'abc/.git/index.lock' File exist.
If no other git process is currently running, this probably means a git process crashed in this repository earlier, Make sure no other git process is running and remove the file manual to continue.

Solution:
remove ../.git/index.lock
ex: rm -r ./.git/index.lock

git command
1. repo sync
2. repo start new_branch . (新增 branch)
3. git branch (確認branch狀態)
4. git branch -d branch_name( 刪除branch)
5. git diff > diff.txt ( 將有修改的檔名的不同處存下來)
6. git status (顯示所有有動變的檔案)
7. git commit -a
8. git show HEAD( show上一個commit 資訊)
9. repo upload . (實際上傳到server)

如果還要修改但還沒merge
1 git add .
2. git commit --amend
3. repo upload .

切換到別的branch
git checkout branch_name

將存下的 patch加入source code 之中(打 patch)
patch -R p1 < xxx.patch --dry-run

將檔案回歸到原始(server)狀態
git checkout -- filename

新增一個檔案
git add -p file_name(只加這一個檔案,有時路徑下有很多檔案修改,但只想上傳這一個)

新增 folder
git add folder_name(先新增folder, 才會出現此folder下的檔案)
PS. 如果新增一個空資料夾,必須在此資料夾加一個隱藏檔

取得git log並格式化
git log --pretty=format:"%h%x09%an%x09%ad%x09%s"



MSVCR100D.dll missing

MSVCR100D.dll missing
MS: Miscrosoft
V: visual
C: C++
R: Redistributable

Solution
Release:
1. in VS, project properity
2. configuration > C++ Generation
3. change to Multi-thread (/MT)

Debut:
1. same with release
2. change to Multi-thread Debug (/MTd)

Windows 8 相關

metro app execute directly(直接執行metro app)
1. VS2011 tool bar :
    Project > store > create app package > Build a package to use local only
2. There is added a folder "Packages" in Project, find file "Add-AppxDevPackage.bat",
    press mouse right key then select "Run as administrator".

Trun on or off windows features ( enable .net framework 3.5)
control panel >Programs > Programs Features > Turn windows Features on or off > check or uncheck Feature.

if Enable .Net Framework 3.5, but result is fail, then.

1. mount windows 8 image (XXX.iso)
2. find file inside \sources\sxs
3. copy *.* from \sources\sxs\*.* to a temp folder, ex: c:\net35\*.*
4. execute cmd.exe as administrator. (cmd.exe in c:\windows\system32\cmd.exe,  按右鍵,run as administrator)
5. type command in cmd.exe
    c:\windows\system32> Dism.exe /online /enable-feature /featurename:NetFX3 /All /Source:c:\net35 /LimitAccess
6. The result : The operation completed successfully.

Search files
搜尋含有特定文字的檔案.
ex: 'ABC' in *.txt