2018年5月17日 星期四

Add Stub module on Android studio

1. Create java library module, not Android library.
    apply plugin: 'java'
    Write stub code in this module

2. Add reference Stub in build.gradle in app module

android {

allprojects {
                   gradle.projectsEvaluated {
                     tasks.withType(JavaCompile) {
                       doFirst {
                         options.fork = true
                         options.compilerArgs.add("-Xbootclasspath/p:$project.rootDir/stub/build/libs/stub.jar")
                       }
                     }
                   }
                  }
}
dependencies {
compileOnly project(':stub')
}

2018年5月16日 星期三

system app on Android O+

1. push APK on /system/priv-app/
2. chomd +r XXX.apk
3. create permission file on /etc/permissions/
4. permission file name should be "privapp-permissions-PACKAGE_NAMW.xml"
5. permission file content depends APK.  Example:



   

             
 

2014年10月24日 星期五

Run AOSP in Nexus devices

1. Download AOSP 
2. Download driver from Google's Nexus driver page.
3. unzip those drivers and put *.sh to root folder of AOSP
4. run each *.sh. Should get extract files to ./vendor
5.
$ source ./build/envsetup.sh
6. lunch. then choose flavor. (aosp_hammerhead-userdebug)
$ lunch
7. go to root folder of AOSP then make -j4
$ make -j4
8. Device goes to ‘’fast boot” mode. 
$ adb reboot bootloader
9. Go to ./out/target/product/hammerhead
$ cd ./out/target/product/hammerhead

10. flash real devices
$ fastboot -w flashall

2014年9月25日 星期四

AOSP Keys convert to Eclipse KeyStore

 AOSP put keys in build/target/product/security 

testkey -- a generic key for packages that do not otherwise specify a key.
platform -- a test key for packages that are part of the core platform.
shared -- a test key for things that are shared in the home/contacts process.

media -- a test key for packages that are part of the media/download system.

Example of "Platform"
javakeystore(jks)算是pkcs12的部分
但由於jkssunproprietaryformat
所以openssl沒法處理jks 要先把他轉成pkcs12再用keytool來轉

首先要先把 private key (pkcs8) DER format轉成PEM format
#openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out platform.pem


然後要把private key public key 轉成pkcs12. 輸入之後會跳出提示"輸入密碼"
#openssl pkcs12 -export -in platform.x509.pem -inkey platform.pem -out platform.pkcs12


最後用keytool把他轉成jks. 如不輸入 "srcstorepass"或"deststorepass" 輸入之後會跳出提示"輸入密碼"
#keytool -importkeystore -srckeystore platform.pkcs12 -srcstoretype pkcs12   -destkeystore platform.jks -deststoretype JKS [-srcstorepass PASSWORD -deststorepass PASSWORD]


verify that the key has been added to the keystore.
#keytool -list -v -keystore .keystore



ref: ALLSTART's BLOG

2014年8月27日 星期三

Android setting file


Android launch by default app
/data/system/users/0/package-restrictions.xml

Map Uid and permission

/data/system/package.xml

2014年5月8日 星期四

Android partition backup

Partition info can be found in "/dev/block/...". But it is not readable, most of devices have readable info in "/dev/block/platform/msm_sdcc.1/by-name".

Backup:
dd if=/dev/block/platform/msm_sdcc.1/by-name/recovery of=/sdcard/Backup/recovery-backup.img

Restore:
dd if=/dev/zero of=/dev/block/platform/msm_sdcc.1/by-name/recovery
dd if=/sdcard/Backup/recovery-backup.img of=/dev/block/platform/msm_sdcc.1/by-name/recovery

2014年3月27日 星期四

Compile APK with static java lib or java lib in AOSP

1. Create a folder("Myproject") under ANDROID_ROOT/packages/apps/
2. Before compile APK. Make sure compile all reference library first.
3.1 Part of make file example with local_java_library
 
     LOCAL_JAVA_LIBRARIES := com.sample.mylocallib

3.2 Part of make file example with local_static_java_library
   
    LOCAL_STATIC_JAVA_LIBRARIES := com.sample.mystaticlib
    LOCAL_PROGUARD_ENABLED := disabled

4. Proguard will remove unreferenced code by default. So if APK want keep all code, it may need to set proguard disabled. Or enable proguard and keep class in proguard setting
 
     Make file example:
     LOCAL_PROGUARD_ENABLED := custom
     LOCAL_PROGUARD_FLAG_FILES := proguard.flags

     proguard.flags example:
     -keep class com.sample.mystaticlib.** { *; }
     -keep interface com.sample.mystaticlib.interface.** { *; }

5. If get error "can't find xxxx/classes.jar" when compile APK. It may add classpath in make file
   
   Make file example:
    LOCAL_CLASSPATH := out/target/common/obj/JAVA_LIBRARIES/libmyinterface_intermediates/classes.jar