發表文章

目前顯示的是 2月, 2018的文章

抓取網路裝置名稱

圖片

抓取系統Memory大小

圖片

一張圖說明dos2unix指令功能

圖片

git全域設定,局部設定與移除/取消設定

git分為全域設定和局部設定(Repo內) 忽略空白處變化,如果是寫python的話就不能忽略空白處變化 基於讓每個環境都有一致的呈現結果,我也不建議忽略空白處變化 git config --global apply.whitespace nowarn 有些git下載回來設定檔裡面有no-fast-forward的設定,會阻止我們用force push修改以前的修正 git config branch.master.mergeoptions "--no-ff" 如果想拿掉某個config就用unset來取消設定 git config --unset branch.master.mergeoptions 若主要是在ubuntu中開發, 而偶爾會在windows上開發,建議windows部份設定忽略檔案的屬性改變,以及讓git自動轉換換行字元(CRLF->LF) 非常不建議同一份git目錄在windows開發又搬移到linux上開發, 因為會有換行/權限/等等的問題 git config --global core.fileMode false # In Windows/Mac, push/pull convert the line feed git config --global core.autocrlf true # In Ubuntu/Linux,convert CRLF to LF while push git config --global core.autocrlf input Ref:https://help.github.com/articles/dealing-with-line-endings/ Windows  CRLF => \r\n Linux LF \n Mac CR \r 檢查文件是否混合兩種換行方法,若有就會拒絕commit, 因為換行會成script無法正確的parsing,所以我會建議設定這個 git config --global core.safecrlf true 如果檔案被拒絕,可以用dos2unix將檔案的換行符號換成unix的LF 如果你修改了上面這些設定,請確保你的git目錄內的檔案都是一致的 git rm --cac

產生編譯日期(Build Date)並自動加入APP內

本文提供給在AOSP內編譯APP, 自動產生編譯日期(Build Date)並自動加入APP內 緣由: 某些板子用的AOSP在產生OTA檔案時會固定的APP編譯後的檔案時間,因此無法 網路上用APP內的classes.dex日期 來取,所以有額外需求要產生build date。這方法的進階應用是自動抓取目前的APP git資訊並加入生成build檔案,可以用來協助研發人員判讀使用的版本,可參考我之前的 文章 抓取git commit資訊。 Android.mk內加入下面的define和call,用來自動產生build date檔,並放入APP Assets中 define generate-build-date   $(info $(LOCAL_PACKAGE_NAME) build date ... $(shell date "+%y%m%d %H%M%S") $(shell mkdir -p $(dir $(1)); LC_TIME=en_US.UTF-8 date "+%y%m%d %H:%M:%S" > $(1) && chmod $(2) $(1))) endef $(call generate-build-date,$(LOCAL_PATH)/assets/builddate,0644) 上面這裡使用的build date時間格式是"年月日 時:分:秒" $ date "+%y%m%d %H:%M:%S" 170119 09:31:11 另外在APP程式碼中加入 final static String UNDEFINED_BUILD_DATE = "UndefinedBuildDate"; private String mBuildDate = UNDEFINED_BUILD_DATE; private void initAppBuildDate() {     try {         mBuildDate = loadBuildDateFromAsset();     } finally {         if (mBuildDate == null || mBuildDate.t

設置Logcat預設大小(Android 5以後)

Android 5.0之後採用logd作為logcat處理界面,先前在kernel設置logcat預設大小的方式,已經無法正確生效。 在LogBuffer::init()內可以看到logd設置logcat大小的方法 system/core/logd/LogBuffer.cpp void LogBuffer::init() {     static const char global_tuneable[] = "persist.logd.size";     static const char global_default[] = "ro.logd.size"     unsigned long default_size = property_get_size(global_tuneable); 板子自帶logcat大小,在系統Property中"ro.logd.size" 全域logcat大小,可設置系統Property "persist.logd.size" 各自logcat大小,可設置系統Property   "persist.logd.size.main"   "persist.logd.size.radio"   "persist.logd.size.events"   "persist.logd.size.system"   "persist.logd.size.crash"   "persist.logd.size.security"   "persist.logd.size.kernel" 上面的名稱定義在 system/core/liblog/logger_name.c static const char *LOG_NAME[LOG_ID_MAX] = {     [LOG_ID_MAIN] = "main",     [LOG_ID_RADIO] = "radio",     [LOG_ID_EVENTS] = "events&qu

掃描自身所有的port是否可以連接

掃描自身所有的port是否可以連接 netcat -z -n -v localhost 1-65535 2>&1 | grep succeeded 來源:https://www.digitalocean.com/community/tutorials/how-to-use-netcat-to-establish-and-test-tcp-and-udp-connections-on-a-vps

Ubuntu設定ADB連接USB裝置

Ubuntu設定ADB連接USB裝置 SUBSYSTEM=="usb", ATTRS{idVendor}=="1004",MODE="0666" https://www.ibm.com/developerworks/cn/linux/l-cn-udev http://nathan-inlinux.blogspot.tw/2012/11/ubuntuadbusb.html

AOSP的repo轉成git

移除AOSP編譯暫存檔案,repo的管理資料,以及各個repo用的各個git目錄 實務上,我個人會比較建議用git clean -df和git reset --hard HEAD每個,來清除暫存檔案 rm -rf out rm -rf .repo find ./ -type d -name .git |  xargs -i rm -rf {} 備份.gitignore到家目錄的bak.gitignore rm -rf ~/bak.gitignore mkdir ~/bak.gitignore find ./ -name .gitignore  | sort > ~/bak.gitignore/gitignorelist.txt find ./ -name .gitignore | xargs -i cp --parents {} ~/bak.gitignore/ 檢查一下拷貝的檔案數目是否正確 wc -l ~/bak.gitignore/gitignorelist.txt find ~/bak.gitignore/ -type f | sort | wc -l 將所有檔案加入git git init git add -A -f git commit -m "init repo" 然後再把~/.bak.gitignore內備份的gitignore加回去 cp ~/.bak.gitignore / . find ./ -type f -name .gitignore | xargs -i git add {} git commit -m ".gitignore recovered" 轉換好之後需要編譯看看是否有問題,我自己最常遭遇的就是build system內部有自動打patch或者重置到某個commit的指令,而因為我們把repo和原本的git都刪除了,會造成那些script失效,需視狀況在進行調整。

Android CPU設置效能模式

1. 暴力方法 先查看是否有幾個cpu device ls -l  /sys/devices/system/cpu/ 一般來說預設是interactive,不過也有些是設定成userspace 用cat即可看原始設定cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 要調整成performance,以第一個CPU為例: echo performance >l; /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 查看是否有套用 cat /proc/msp/pm_cpu 原本CPU頻率可能是動態跳動的,用performance就會固定最高頻率 CPU: freq = 1200000(kHz), current volt = 955(mv) CPU: AVS = On, hpm offset = 0 hpm target = 0x11c Tsensor: temperature = 60 degree CPU: Temp Control is Quit 2. Android 7.0之後支援sustained performance模式 https://source.android.com/devices/tech/power/performance 可以在裝置容許的狀況(溫度控管)下長時間提高效能的模式, 前提當然是裝置要支援... 用PowerManager.isSustainedPerformanceModeSupported()來取得支援 然後在APP中設定Window.setSustainedPerformanceMode(true) 底層實作的參考: http://solring-blog.logdown.com/posts/776364-android-powermanager-powerhint

小程式:從列表中移除

來源資料, 只看第一個 1 2 3 2 2 3 3 2 3 4 2 3 要刪除的內容 1 3 結果會得到 2 4 使用方法 process test.txt rmlist.txt result.txt debug原始載入資料 process test.txt rmlist.txt result.txt 1 debug載入資料第一欄 process test.txt rmlist.txt result.txt 2 #include <vector> #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <sstream> using namespace std; int DEBUG = 0; string outpath = "result.txt"; int main(int argc, char** argv) {     cout << argc << endl;     if (argc <= 2) return -1;     cout << "long list:" << argv[1] << endl;     cout << "remove list:" << argv[2] << endl;     if (argc > 3) outpath = argv[3];     cout << "output file:" << outpath << endl;     if (argc > 4) DEBUG = atoi(argv[4]);     ifstream rdf(argv[1], ifstream::in);     ifstream rmf(argv[2], ifstream::in);     ofstream outf(ou

簡單的Android.mk運行解析

平常的一個編譯Shared library的Android.mk會像下面這樣 LOCAL_PATH := $(call my-dir) #   呼叫my-dir這個定義, 將變數LOCAL_PATH設置為當前Android.mk所在的目錄 include $(CLEAR_VARS) #   引入CLEAR_VARS這個mk檔案, 用來重置/清除編譯系統內定的變數群 LOCAL_MODULE := hello-jni #   指定準備要編譯的模組名稱, 整個要編譯的workspace不能有相同的模組名稱 LOCAL_SRC_FILES := hello-jni.c #   指定編譯模組時使用的程式碼檔案 include $(BUILD_SHARED_LIBRARY) #   引入BUILD_SHARED_LIBRARY mk檔案, 指定編譯模組成為動態函數庫(.so) 這些實際上使用的都是makefile語法來處理,只是AOSP內有很多方便的基礎定義,所以看起來和makefile不一樣 :=是將變數設值的意思, 使用變數要寫$(變數名稱),呼叫函數也是寫$(函數名稱) 呼叫函數用法是$(<function-name> <arguments>) 像是$(info Print a hello world)就會將Print a hello world印在螢幕上 $(warning show your warning message)會將show your warning message印在錯誤輸出上 $(error show your error message)會將show your error message印在錯誤輸出上,然後結束執行 參考: https://www.gnu.org/software/make/manual/html_node/Make-Control-Functions.html $(call XXXX)是呼叫某個定義,可以帶入多組參數,參數用逗號分隔 在makefile中用法是$(call <expression>,<parm1>,<parm2>,<parm3>,...) expression裡面可以寫很複雜得判斷,而後面的param系

Get the large file size

#define _LARGEFILE64_SOURCE #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> int main(int argc, char** argv) {     int fd;     off64_t pos;     if (argc <= 1) return -1;     printf("%d %s\n", argc, argv[1]);     fd = open(argv[1], O_RDONLY);     if (-1 == fd) {         printf("open failed\n");         return -1;     }     pos = lseek64(fd, 0, SEEK_END);     printf("size = %ld\n", pos);     close(fd);     return 0; }

git bare的branch轉換成一般git

將bare的git repository轉換成一般的git repository