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

Ubuntu好用command

1. 將grep出來的文字replace
grep -rl matchstring somedir | xargs sed -i 's/string1/string2/g'
ex: grep -rl 'ABCD' * |xargs sed -i 's/ABCD/HEF/g'

2.將^M的換行符號拿掉
(1) sed  "s/\r//" dos_file  > dos_file_linux
(2) sed -i 's/\x0D$//' filename.txt

3. mount iso
sudo mount -t auto -o loop xxx.iso /mnt/iso

4. 安裝deb
 dpkg -i abc.deb

5. 轉換PNG到PPM
 (1) apt-get install netpnm
 (2) pngtopnm sample.png > linuxlogo.pnm
 (3) pnmquant 224 linuxlogo.pnm > linuxlogo224.pnm
 (4) pnmtoplainpnm linuxlogo224.pnm > linuxlogo_clut224.ppm

PS. 如果要取代原linux logo, replace driver/vide/logo下的原圖檔.

5. copy folder to server
scp -r folder_name user@10.109.109.109:/home/user_name/folder_name
ex: scp -r TVBox favoritepili@10.109.109.109:/home/favoritepili/

6. Download file from server
scp -r user@10.109.109.109:/home/user/folder /home/user
ex: scp -r favoritepili@10.109.109.109:/home/favoritepili/TVBox /home/favoritepili

7. unload driver
sduo modprobe -r vboxpci

8. list module
(1) lsmod | grep vbox
(2) modprobe -l | grep vbox

9. load module
modprobe vboxdrv

2011年11月7日 星期一

Edit default android property value

更改預設property value.

方法一:
在makefile中加入"ADDITIONAL_BUILD_PROPERTIES"

ex:
in product_name.mk (device/product_name/product_name.mk)

...
ADDITIONAL_BUILD_PROPERTIES += \
    ro.debuggable=1
...
---------------------------------------------------------------

in my_product_name.mk (不同的product)
...
ADDITIONAL_DEFAULT_PROPERTIES := \
     ro.debuggable=1
...


side effect:
因為我在進行建立不同的product tree,可以有不同的product在同一份code base裡,
但我在實驗中發現,利用ADDITIONAL_BUILD_PROPERTIES, ADDITIONAL_DEFAULT_PROPERTIES,
會影響到全部的product.


所以加個判斷:

ifeq ($(TARGET_PRODUCT),my_produce_name)
ADDITIONAL_DEFAULT_PROPERTIES += \
        ro.allow.mock.location=1
endif


PS. ADDITIONAL_BUILD_PROPERTIES是指增加property到out/target/product/product_name/system/build.prop,
ADDITIONAL_DEFAULT_PROPERTIES是增加property到out/target/product/product_name/root/default.prop.

方法二
修改 build/core/Makefile
TARGET_PRODUCT_DIR=device/$(TARGET_PRODUCT)
$(INSTALLED_BUILD_PROP_TARGET): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
...
if [ -f $(TARGET_PRODUCT_DIR)/system.prop ]; then \
                        cat $(TARGET_PRODUCT_DIR)/system.prop >> $@; \
                else \
                        cat $(TARGET_DEVICE_DIR)/system.prop >> $@; \
                fi
...
原本的寫法,build.prop是去cat device/product_name/system.prop,還有一些default值.
我是把它改成先以current product path下判斷是否有system.prop,如果沒有就抓device path下的 system.prop

PS. $(INSTALLED_BUILD_PROP_TARGET): 就是out/target/product/product_name/system/build.prop

方法三:
在makefile 裡加:

PRODUCT_PROPERTY_OVERRIDES += \
        persist.service.adb.enable=1

ifeq ($(TARGET_PRODUCT),my_product_name)
ADDITIONAL_DEFAULT_PROPERTIES += \
        ro.allow.mock.location=1
endif


這樣就只會生效current product.