- Download Android Studio at Android Homepage.
- Extract to any folder you want, i.e. {installation home}
- Open terminal at {installation home}
./bin/studio.sh
- Follow instruction to install Android Studio (
custom option
recommended)
- If your computer supports GPU (especially NVIDIA), install GPU driver for optimizing AVD (Android Virtual Device) perfomance.
sudo ubuntu-drivers autoinstall
- If you can not start Android Emulator, with error
/dev/kvm device permission denied
, then run these commands:
sudo apt install qemu-kvm
sudo adduser $USER kvm
sudo chown $USER /dev/kvm
- Open File → Settings → Plugins in Android Studio
- Install theme you want. Recommend:
One Dark Theme
,Hiberbee Theme
,Material Theme
On active widow emulator, press ALT + SPACE
, select always on top
- Colorize logcat:
sudo snap install logcat-colorize
adb shell logcat | logcat-colorize
Colorize adb shell
- Only supported for devices with file-system writable
- Copy all text below and paste in one shot to adb shell
echo >> /system/etc/mkshrc
echo -e "# Colorize: bluelul.com\nif (( USER_ID )); then PS1='$'; else PS1='#'; fi" >> /system/etc/mkshrc
echo -e "PS4='[\$EPOCHREALTIME] '; PS1='\${|" >> /system/etc/mkshrc
echo -e "local e=\$?" >> /system/etc/mkshrc
echo -e "(( e )) && REPLY+=\"\033[01;31m\$e\033[00m|\"" >> /system/etc/mkshrc
echo -e "return \$e" >> /system/etc/mkshrc
echo -e "}\033[01;33m\$HOSTNAME\033[00m:\033[01;34m\${PWD:-?}\033[00m'\"\$PS1 \"" >> /system/etc/mkshrc
echo >> /system/etc/mkshrc
echo "alias ls='ls --color'" >> /system/etc/mkshrc
echo "alias ll='ls -l --color'" >> /system/etc/mkshrc
echo "alias lah='ls -lah --color'" >> /system/etc/mkshrc
- Exit adb shell (
Ctrl-D
) and access adb shell again to update changes
- Copy all content of bluelulAndroid.xml to clipboard
- Open File → Settings (
Ctrl + Alt + S
) in Android Studio, then Editor → Live Templates - Press
+
button on the right (or pressAlt + Insert
) and chooseTemplate Group
- Input
AndroidBluelul
or any name you want - Press
Ctrl + V
to add all copied templates to this group
logt
: assign TAGlogi
: log infologe
: log errorlogd
: log debug
find
: bind XML component in layout to Java objectfindquick
: bind XML component in layout to Java object without declaring
btnclick
: set OnClick Listener to button object (non-lambda style)btnclickquick
: set OnClick Listener to button object (lambda style + non pre-declared)button.setOnClickListener(v -> {})
: set OnClick Listener to button object (lambda style)
textView.setText(valueStr)
: change content of TextView object
editText.setText(valueStr)
: change content of TextView objecteditText.length()
: get text lengtheditText.setError("show error")
: trigger error in EditText objecttextchangewatch
: handle text change event
editText.setText(valueStr)
: change content of TextView objecteditText.length()
: get text lengtheditText.setError("show error")
&&editText.setErrorEnabled(true)
: show error in TextInputLayout objecteditText.setErrorEnabled(false)
: hide error in TextInputLayout objecttextchangewatch
: handle text change event
radioGroup.getCheckedRadioButtonId()
: return Resource ID of checked radio button (e.g. R.id.radioButton), return -1 if no button checked
swact
: switch to another activityloadintent
: load input argument of activity after being createdoverridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out)
: swipe left to new activity, run after triggering activityoverridePendingTransition(R.anim.trans_right_in, R.anim.trans_right_out)
: swipe right to previous activity, run after triggering activity
Note: layout-related code should be placed on onViewCreated
method, and use view.findViewById
instead of this.findViewById
fragreplace
: Replace fragment to frame layoutfragadd
: Add (overlay) fragment to frame layout
call
: dial a phone numbersms
: compose a SMS message to a phone numberweb
: browse a websitemail
: compose an email
clipman
: declare ClipboardManager objectclipcopytext
: copy plain text to clipboardclippastetext
: paste plain text from clipboardclipcopyintent
: copy intent to clipboardclippasteintent
: paste intent from clipboard and run intentclipcopyrawuri
: copy raw uri to clipboardclippasteuri
: paste uri from clipboard
res2uri
: parse URI from Resource ID
toast
: make new toasttoast.setGravity(Gravity.CENTER | Gravity.TOP, 0, 0)
: change toast position
snack
: make snackbar with buttonsnacktext
: make new snackbar (for notification)
- Fill white color to icon of layout component:
app:tint="@color/white"
- Round button:
app:cornerRadius="100dp"
- Only-contain-icon button:
app:iconGravity="textStart"
app:iconPadding="0dp"
- List-item can't be click after contain buttons: add
android:focusable="false"
to all buttons and clickable components - Hide spell check but keep autocomplete for EditText:
android:inputType="_current_input_type_|textPersonName"
Templates are stored in /quickcode folder
double back to exit
: press back button 2 times to exit appfloating action button expandable
: press the(+)
fab to expand more fabslistview simple
: make simple listview (only text, single choice, multiple choice)listview card
: make card listview (1 item contains: avatar image, main name text, sub name text)listview order
: make food order listview (1 food item contains: image, name, description, price, count number, add button, remove button (long press to empty all))landview linearlayout adapt
: re-arrange layout when phone orientation change between landscape (horizonal) and portrait (vertical) by changing orientation of linearlayouts
- Default protectionLevel of permissions with low risk to other apps, system or user
- Automatic granted to requested app, without prompting the user
- User allows permission before installing app
- Higher than
Normal
- Permissions with high risk to private user data accessing or device controlling, e.g. get location, write contact, answer phone call, etc.
- Only granted after asking the user
- Higher than
Dangerous
- Only granted to apps installed under the folder
/system/priv-app
- Apps installed in
/system/priv-app
will havePrivileged
level - Read more about system app behaviour
- Method 1: hot install
- Get the right to write to read-only /system folder: the usual way
- Install app.apk to Android OS:
adb install app.apk
- Upload app.apk to device/emulator:
adb push app.apk /system/priv-app
- Reboot device/emulator:
adb reboot
Note
: to uninstall, first remove /system/priv-app/app.apk, then reboot and uninstall as normal app
- Method 2: build with OS
- Place app in /system/priv-app
- Build app along with your custom Android OS
- Flash this OS to your device
- Higher than
Privileged
- Only granted to app signed with OEM system certificate
- Elevate an app with Signature right by signing this app with
platform signature
, issued by device manufacturer (OEM) - Read more about system app behaviour
- Method 1: sign by public & private key (the easiest way)
- Get platform.x509.pem (public key) and platform.pk8 (private key)
- For Android Emulator: download from aosp-mirror, or get files directly from /sign folder in this repo
- For custom device: get files from
build/target/product/security/
in android source code folder
- Install
apksigner 0.9
withapksigner_0.9-1_all.deb
file in /sign folder in this repo
sudo apt install -y fastjar jarwrapper sudo dpkg -i apksigner_0.9-1_all.deb
- Sign your app with given public & private key:
apksigner sign --key platform.pk8 --cert platform.x509.pem --out `pwd`/sign.apk unsign.apk
- Get platform.x509.pem (public key) and platform.pk8 (private key)
- Method 2: sign by keystore
- Get platform.x509.pem (public key) and platform.pk8 (private key), as in Method 1
- Get keytool-importeypair from github repo, or from /sign folder in this repo
- Generate your keystore file
sudo chmod 777 keytool-importkeypair.sh ./keytool-importkeypair.sh -k key.keystore -p android -pk8 platform.pk8 -cert platform.x509.pem -alias platform
- Grant an App the System Uid (Optional): in the tag in AndroidManifest.xml file, add the attribute
android:sharedUserId="android.uid.system"
- Use keystore file to sign your app in one of below ways:
- On Android Studio, clicking on 'Build--> Generate Signed Bundle / APK' (alias: platform, password: android)
- Install
apksigner
(as in Method 1), then run this command:
apksigner sign --ks key.keystore --ks-pass pass:android --out `pwd`/sign.apk unsign.apk
- On Android Studio, using signingConfig in your app's .gradle
signingConfigs { config { storeFile file("key.keystore") storePassword 'android' keyAlias 'platform' keyPassword 'android' } } buildTypes { release { signingConfig signingConfigs.config } }
- Method 3: build with OS
- Place app in /system/priv-app to prevent being uninstalled by user (optional, but prefer)
- Add LOCAL_CERTIFICATE := platform to the app's Android.mk
- Build app along with your custom Android OS
- Flash this OS to your device
- Old synonym for
Signature|Privileged
, deprecated in API level 23 - Accessed by signed app or privileged app
- The easiest way to achieve is by elevating privileged right with Method 1 (hot install to /system/priv-app)
- Old synonym for
Privileged
, deprecated in API level 23
- System apps are apps installed in
/system/priv-app
and/system/app
in Android device file system - User apps are apps installed from Play Store, adb install, or directly installed by user from apk files, located in
/data
in Android device file system - Apps installed in
/system/priv-app
will havePrivileged
protection level - Apps installed in
/system/app
are the same as User apps but can not uninstalled by user. Therefore manufacturer's default apps (bloatware) are usually installed in/system/app
- Signed apps are apps signed by
platform signature
, issued by device manufacturer
Install method | Can be uninstalled | Can be disabled |
---|---|---|
User app | yes | no need |
Signed User app | yes | no need |
System app | no | yes |
Signed System app | no | no |
System app is stored in read-only /system
location, lead to:
- System apps can be updated just like user apps, but the update is never integrated into the original rom --> able to roll back to the version that existed when the rom was first installed
- System apps cannot be moved to SD and always take up some internal space --> to get more user app space, uninstall updates of system apps, instead of these apps themselves
- System apps cannot be deleted in a full factory reset, unlike user apps
- Start emulator with
-writable-system
to modify system files:
cd ~/Android/Sdk/emulator
./emulator -list-avds
./emulator -writable-system -avd Nexus_4_API_27 -no-snapshot-load -qemu
- Leverate permission to modify system:
adb root
# For Android 8
adb disable-verity
# For Android 10 emulator only
adb shell avbctl disable-verification
adb reboot
adb root
adb remount
Create
|------------- finish data binding, allocate resources
Start
|------------- visible to user
Resume
|-------------------- running
Pause
|------------- freezing: transition to next activity
, new app partially cover
Stop
|------------- hiding: dive into Back Stack
, Recent App pressed
, Home pressed
, new app fully cover
Destroy
|------------- free all resources: pop out of Back Stack
, kill app