Exploring the bottom layer of Android to fix bugs (2): Android system removes pre-installed APPs

First of all, I will provide the following blogger’s blog posts, which can provide guidance for understanding, solving, and thinking about relevant knowledge points.

  1. How to pre-install third-party applications on Android system and collection of frequently asked questions
  2. android Android.mk attribute description and preset system app operation instructions
  3. How to remove system native apk in Android

Method 1 to cancel the preset APK:

In fact, it is the link 3 above, but this method has limitations. It is more suitable for a single Android system project and directly deletes the relevant APK code in Android.mk (source link 3 below)

However, in many cases and in practice, many companies use repo to pull codes for many projects, and among projects A, B, C, D, and E, the APK may need to be retained for projects A and C, while the rest need not be retained. For this APK, you need to refer to the company’s demand list.

Method 2 to cancel the preset APK:

(The picture below quotes the blogger’s blog post from Learning Link 2, which is very helpful)

is also a commonly used method. According to the above special description, we need macro control, that is: add conditional judgment in the Android.mk file, A and C projects include If this macro has a yes value, the APK will be retained (this APK will be preset). If the other BDEs do not set this macro or set it to a no value, they will not preset this APK (the macro is written in the var.mk of the project).

Think about it and write it: Take Calendar.APK as an example below

1. If you don’t know the package name, you can use the decompilation tool to check the package name first.

First, you need to know whether to preset the package name of this APK, so that you can better position and judge whether it is successful later. The jadx decompilation tool is used here. You can search online for how to use it. I will briefly talk about it here. Download (unzip) jadx to any path, drag the target apk file to the bin directory of jadx, open the terminal and execute jadx -gui apk name

D:\jadx\bin>jadx -gui Calendar.apk

After decompiling, you can see the package name in AndroidManifest.xml or others.

2. Add macros to var.mk under the required projects, that is, under projects A and C

Example path device\xxx\xxxx\project name\var.mk

To write the name of the macro, you need to check the company's regulatory documents. For example, company name_software name...

宏示例:宏名称=yes

3. Add judgment under Android.mk to determine whether to execute statements (create folders, copy apk, etc.)

Android.mk will execute it no matter what project it is, so whether you execute the apk operation depends on whether your own macros exist and whether the values ​​correspond.

Example path vendor/xxxx/packages/xxxx/Calendar/Android.mk

ifeq($(XXXXXXX),yes)
    $(warning mkdir -p $(PRODUCT_OUT)/system/preloadapp/$(LOCAL_MOULE)/)
    $(shell mkdir -p $(PRODUCT_OUT)/system/preloadapp/$(LOCAL_MOULE)/)
    $(warning Aron -------- cp $(LOCAL_PATH)/$(LOCAL_MOULE)/$(PRODUCT_OUT)/system/preloadapp/$(LOCAL_MOULE)/$(LOCAL_MOUDLE).apk)
    $(shell cp $(LOCAL_PATH)/$(LOCAL_MOULE).apk $(PRODUCT_OUT)/system/preloadapp/$(LOCAL_MOULE)/$(LOCAL_MOULE).apk)
endif

3. Add the APK under the main.mk of the project that needs to be prefabricated (usually it may already exist, check it)

Calendar needs to be included

PRODUCT_PACKAGES +=\

Calendar\

...

4. Do not add macros to other projects that do not need to be preset (usually no modifications are made, there are no macros by default, and the preset APK is not executed)

Extra:

If you need to replace an existing APK, such as Calendar, I only need one, for example, to replace Google's APK, add the following statement in Android.mk:

ifeq($(strip $(XXXXXX)),yes)
LOCAL_OVERRIDES_PACKAGES :=Calender 
else
LOCAL_OVERRIDES_PACKAGES :=CalendarGoogle 

5. Verify whether the APK is preset

You can use the adb command to check the phone's package name or see if there is a generated APK in the out directory.

adb command: connect the mobile phone to the computer and detect the mobile phone using adb devices

Then enter the adb shell pm list packages command to display a list of package names of all applications installed on the device.

Check if there is an APK package name in the list

Check the out directory (after compilation, the out directory in the Android source code does not exist at the beginning, it is automatically generated by the system after we perform the compilation operation)

The path is: out/target/product/project name/app (or other app folder)

The following four paths store the APK (you can choose, it can be set in the Android.mk file)

  • system/app/: This directory stores some system-level applications. Applications in this directory can obtain relatively high permissions and cannot be uninstalled, such as Phone , Contacts, etc.
  • system/priv-app/ : This directory is a directory that has appeared since Android 4.4. It stores some system core applications and can obtain files lower than system/app/ Applications with higher permissions cannot be uninstalled, such as: Setting, SystemUI, etc.
  • vendor/app/ : This directory stores some applications from the manufacturer, and the applications cannot be uninstalled.
  • data/app/: Some third-party applications stored in this directory can be uninstalled.

Guess you like

Origin blog.csdn.net/m0_59558544/article/details/134085902