Thursday, December 26, 2019

Root Pixel2 with Magisk



Root steps
  1. head to Google's firmware download page for Pixel devices and select your model from the menu on the right.
  2. Unzip the file, original rom
  3. Looking for "image-walleye" or "image-taimen"
  4. Looking for "boot.img"
  5. Put "boot.img" to phone
  6. Install Magisk Manager app. Tap "Install" then "Patch boot image File"\
  7. Magisk Manager app should generate file "patched_boot.img". Copy file to computer
  8. Restart device to boot loader mode "adb reboot bootloader"
  9. Refresh boot img by command "fastboot flash boot "PATH_TO_PATCHED_BOOT.IMG"
  10. Relaunch device "Fastboot reboot" and magick manager. Should see Magisk SU



Put back factory boot.img for receive system OTA

  1. Restart device to boot loader mode
  2. Refresh boot img by command "fastboot flash boot "PATH_TO_FACTORY_BOOT.IMG"
  3. Relaunch device with "Fastboot reboot" 



Thursday, May 17, 2018

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')
}

Wednesday, May 16, 2018

system app on Android O+

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



   

             
 


Friday, October 24, 2014

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

Thursday, September 25, 2014

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

Wednesday, August 27, 2014

Android setting file


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

Map Uid and permission

/data/system/package.xml

Thursday, May 8, 2014

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

Thursday, March 27, 2014

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

create static JAVA lib jar for other APK reference

static_java_library 和 java_library不同點:
1. java_library 編譯完會output到 ANDROID_ROOT/out/target/product/generic/system/framework,而static_java_library不會。
2. 當APK reference到java_library時,不會把jar source編譯進APK。但是static_java_library會編譯進去, 所以執行該APK的機器不需要有static_java_library存在。
3. 編譯兩種library的方法一樣,只差在make file

Make file example:

ifneq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),)
LOCAL_PATH := $(call my-dir)
# the library
# ============================================================
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_MODULE_TAGS := optional
# This is the target being built.
LOCAL_MODULE:= com.mylib.staticlibrary
include $(BUILD_STATIC_JAVA_LIBRARY)
# the documentation
# ============================================================
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files) $(call all-subdir-html-files)
LOCAL_MODULE:= mystaticlibraryDoc
LOCAL_DROIDDOC_OPTIONS := com.mylib.staticlibrary
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_DROIDDOC_USE_STANDARD_DOCLET := true
include $(BUILD_DROIDDOC)
endif # JAVA_SUPPORT

Friday, March 14, 2014

custom JAVA library JAR in Android devices

Use custom library JAR in Android devices(Kitkat)
1. Create "MySystemLib"folder under AOSP_ROOT/device/sample/frameworks/MySystemLib
2. Put JAR source code in  AOSP_ROOT/device/sample/frameworks//MySystemLib
    Should include forder "java", Android.mk, com.my.internal.lib.xml
 
    Android.mk:
ifneq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
            $(call all-subdir-java-files)
LOCAL_MODULE_TAGS := optional
# This is the target being built.
LOCAL_MODULE:= com.my.internal.lib
include $(BUILD_JAVA_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files) $(call all-subdir-html-files)
LOCAL_MODULE:= LauncherFacadeInterface
LOCAL_DROIDDOC_OPTIONS := com.sprint.internal.idinterface
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_DROIDDOC_USE_STANDARD_DOCLET := true
include $(BUILD_DROIDDOC)
endif # JAVA_SUPPORT

3. "make  com.my.internal.lib" or "mm -B"
4.  com.my.internal.lib.jar is generated in 'out/target/product/generic/system/framework'
5. Put com.my.internal.lib.jar  in /system/framework in android devices
6. Put com.my.internal.lib.xml in /system/framework/etc/permission in android devices
7.  Reboot device to refresh system lib
8. Declare lib in manifest.xml
   
            android:name="com.my.internal.lib"
             />

Friday, March 7, 2014

ClassLoader in Android

PathClassLoader:
Load class from Android system. So those classes have to be registered in system. They may be a installable APK. And the class(dex files) would storage in /data/dalvik-cache


        String packageName = "com.android.calculator2";
        String className = "com.android.calculator.sample.class";

        String apkSourcePath;
        apkSourcePath =getPackageManager().getApplicationInfo(packageName, 0).sourceDir;

         PathClassLoader pathClassLoader = new dalvik.system.PathClassLoader(apkSourcePath,
                    ClassLoader.getSystemClassLoader());
          Class clazz = pathClassLoader.loadClass(className);
          Method[] methods = clazz.getMethods();
          for (Method m : methods) {
                Log.i("","method name:" + m.getName());
           }


DexClassLoader:
Load class from jar, apk file. Those file is stored in accessible storage, such as internal storage or sd card. When class loader loads jar file, it will generate dex file. Then load class from dex file.

Example:
           Put  com.android.calculator.jar in /data/data/MY_APP_PACKAGE/files    

            File jarFile = new File(getFilesDir().getAbsoluteFile() + File.separator
                    + "com.android.calculator.jar");
            final File optimizedDexOutputPath =getDir("outdex", Context.MODE_PRIVATE);
            DexClassLoader dexClassLoader = new DexClassLoader(jarFile.getAbsolutePath(),
                    optimizedDexOutputPath.getAbsolutePath(),
                    null,
                    ClassLoader.getSystemClassLoader());
            Class clazz = dexClassLoader.loadClass("com.android.calculator.sample.class");
            Method[] methods = clazz.getMethods();
            for (Method m : methods) {
                Log.i("","method name:" + m.getName());
            }
            Constructor constructor = clazz.getConstructor(Context.class);
            Object instance = constructor.newInstance();

Wednesday, January 15, 2014

Start Service return type

START_NOT_STICKY
啟動之後,如果service被kill by system,service不會自動啟動,也不會自動重新傳入intent. 除非開發者有程式呼叫startService(intent)

 START_REDELIVER_INTENT
啟動之後,如果service被kill by system,service會自動啟動,也會自動重新傳入最後一個intent.

START_STICKY
啟動之後,如果service被kill by system,service會自動啟動,但不會自動重新傳入intent. 如果再kill期間,開發者有程式呼叫startService(intent), 才會傳入intent.

START_STICKY_COMPATIBILITY

啟動之後,如果service被kill by system,service不一定會自動啟動, 如果啟動的話,模式與START_STICKY一樣。

Monday, September 23, 2013

Decompile APK

1. Change .APK to .ZIP and unzip it. There is classes.dex in the folder.
2. Download dex2jar(http://code.google.com/p/dex2jar/) to convert classes.dex to classes.
     . dex2jar.sh PATH_TO_CLASSES_DEX/classes.dex
    
    The command should generate classes_dex2jar.jar
3. Download jdgui(http://mac.softpedia.com/dyn-postdownload.php?p=48710&t=4&i=1) to unzip jar file.
    Open jdgui and choose classes_dex2.jar.jar.  All folder and java file should be browsed in JDGUI.  
    Save all source.

4. Download android-apktool(https://code.google.com/p/android-apktool/downloads/list). Choose "apktool1.5.2.tar.bz2" and "apktool-install-macosx-r05-ibot.tar.bz2"(This depends on platform).
    . apktool d PATH_TO_APK/xxx.apk
   All resource and xml file are generated in APK_NAME folder

Friday, June 14, 2013

Compile Android Apps

Command
1. make: compile all Android system
2. make [package name]: the package name can be found in packages/apps/xx/Android.mk
    or
    mmm packages/apps/Package_name
    The APK and odex will generate in out/target/product/generic/system/app/xxx.apk

3. make snod: this command will regenerate system.img
4. Remove default sign key
 
   zip –d xxx.apk META-INF/*

Put 3rd apk into system.img
1. put apk into out/target/product/generic/system/app/
2. make snod


Tuesday, May 28, 2013

Run GCM demo by app engine server

GCM api
1. Create google api project about GCM
2. Create server key. This api key will be used fot setting up server application.

Create App Engine project
1. Apply one project in app engine. Input project name and project url name.
    Peoject url name will be used in Android application.
2. Download App engine SDK for JAVA

  
Set up Server Application
1. Android SDK Manager, install Extras > Google Cloud Messaging for Android Library.
2. In a text editor, edit PATH_TO_ANDOIRD_SDK/extras/google/gcm/samples/gcm-demo-appengine/src/com/google/android/gcm/demo/server/ApiKeyInitializer.java and replace the existing text with the API key obtained above.
3. In a shell window, go to the PATH_TO_ANDOIRD_SDK/extras/google/gcm/samples/gcm-demo-appengine directory.
4. ant -Dsdk.dir=PATH_APP_ENGINE_SDK/appengine-java-sdk-1.8.0/ compile
    It will generate WebContent/. The code will be upload to App engine, so we don't need to launch server in our local side.

Upload Server Application to App Engine
1. From the appengine-java-sdk directory, run:
     bin\appcfg.cmd update PATH_TO_ANDOIRD_SDK/extras/google/gcm/samples/gcm-demo-appengine/WebContent/
2. Open http://appspot.com 
3. It should show "no devices registered" page.

Set up Android Application
  1. Using a text editor, open PATH_TO_ANDOIRD_SDK/extras/google/gcm/samples/gcm-demo-client/src/com/google/android/gcm/demo/app/CommonUtilities.java and set the proper values for the SENDER_ID and SERVER_URL constants.
  2. In a shell window, go to the gcm-demo-client directory.
  3. Use the SDK's android tool to generate the ant build files:
  4. android update project --name GCMDemo -p . --target android-16
4. ant clean debug
5. It will generate GCMDemo-debug.apk in bin/ folder
6. Install APK in devices.
7. Done.

Tuesday, June 26, 2012

Git ignore


  1. Keep your .gitignore file.
  2. Clear your GIT cache.  Don’t worry, this won’t delete any of your local files, just what GIT is tracking.
    git rm -r --cached .
  3. Add everything in your project.  Your .gitignore file will exclude what you want to ignore now and start tracking the good stuff.
    git add .
  4. Commit your changes.
    git commit -m "Now my .gitignore file works correctly!"

Tuesday, April 3, 2012

compile Android Apps

Command
1. make: compile all Android system
2. make [package name]: the package name can be found in packages/apps/xx/Android.mk
or
mmm packages/apps/Package_name
The APK and odex will generate in out/target/product/generic/system/app/xxx.apk
3. make snod: this command will regenerate system.img

Put 3rd apk into system.img
1. put apk into out/target/product/generic/system/app/
2. make snod
or
1. mkdir packages/apps/MyApp
2. vi Android.mk
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_POST_PROCESS_COMMAND:=$(shell cp -r $(LOCAL_PATH)/*.apk $TARGET_OUT)/app/)
3. make


Generate AIDL stub
1. make: compile all Android system
2. All system AIDL will convert java code in android_source/out/target/common/obj/JAVA_LIBRARIES/.....

Friday, February 17, 2012

gimap

use telnet to connect gimap.
1. openssl s_client -crlf -connect imap.gmail.com:993
2. . login xxx@gmail.com PASSWORD
3. . list "" "*"
4. use other command. such as close, store, create, delete....

Monday, January 16, 2012

Git- Can't locate Error.pm : on Mac OS X

install Git on Mac. When I put "git add -i", then show "Can't locate Error.pm in @INC ....."

I found the answer on internet as belowTamsler:

sudo perl -MCPAN -e 'install Error'

Tuesday, December 20, 2011

Add external lib in Android.mk

1. add LOCAL_STATIC_JAVA_LIBRARIES += jar'sFileName . This line must be added above "include $(BUILD_PACKAGE)"

2. add LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := pathtoyourlib.jar This line must be added after "include $(BUILD_PACKAGE)"

3. add include $(BUILD_MULTI_PREBUILT)


then compile it