重点 (Top highlight)

Android’s underlying kernel is based on Linux, but it has been customized to suit Google’s directions. There is no support for the GNU libraries and it does not have a native X Windows system. Inside the Linux kernel are found drivers for the display, camera, flash memory, keypad, WiFi and audio. The Linux kernel serves as an abstraction between the hardware and the rest of the software on the phone. It also takes care of core system services like security, memory management, process management, and the network stack.

Android的基础内核基于Linux,但已针对Google的指示进行了自定义。 不支持GNU库,它没有本机X Windows系统。 在Linux内核中可以找到显示器,相机,闪存,小键盘,WiFi和音频的驱动程序。 Linux内核是电话上的硬件和其余软件之间的抽象。 它还负责核心系统服务,例如安全性,内存管理,进程管理和网络堆栈。

Installing apps on your Android device is an absolute breeze. Just search for the app on the Play Store and click on the Install button. You can install it either as system apps or as user apps.

在您的Android设备上安装应用程序绝对是一件轻而易举的事。 只需在Play商店中搜索该应用,然后单击“安装”按钮即可。 您可以将其安装为系统应用程序或用户应用程序。

什么是系统应用程序? (What is System App?)

In simple words “The App which came as pre-installed or as a system.img (AOSP system image as an android OS), called system App. System apps can easily access some platform(app-framework) level API call”.

简而言之,“该应用是作为预安装的或作为system.img(作为Android操作系统的AOSP系统映像)提供的,称为系统App。 系统应用程序可以轻松访问某些平台(应用程序框架)级的API调用”。

System apps are pre-installed apps in the system partition with your ROM. In other words, a system app is simply an app placed under /system/app folder on an Android device.

系统应用程序是ROM在系统分区中的预安装应用程序。 换句话说,系统应用程序就是放置在Android设备上/ system / app文件夹下的应用程序。

/system/app is a read-only folder. Android device users do not have access to this partition. Hence, users cannot directly install or uninstall apps to/from it.

/ system / app是只读文件夹。 Android设备用户无权访问此分区。 因此,用户无法直接从中安装或卸载应用程序。

Apps such as camera, settings, messages, Google Play Store, etc. come pre-installed with the phone and manufacturers do not generally provide an option to remove such apps as this might impact the functioning of your device. If you want to remove a system app you need to root your device first.

手机预装了相机,设置,消息,Google Play商店等应用,制造商通常不提供删除此类应用的选项,因为这可能会影响设备的功能。 如果要删除系统应用程序,则需要先对设备进行root用户操作。

什么是非系统APP? (What is a Non-System APP?)

Non-system/third-party/User apps are apps downloaded from Google Play Store or sideloaded with an APK file.

非系统/第三方/用户应用程序是从Google Play商店下载的应用程序,或侧载有APK文件的应用程序。

A non-system app is installed under /data/app folder and has read, write privileges. If there are apps that you have installed but you no longer use, you can simply uninstall them to free up storage space.

非系统应用程序安装在/ data / app文件夹下,并且具有读取和写入权限。 如果有已安装但不再使用的应用程序,则只需卸载它们即可释放存储空间。

普通应用和系统应用之间的区别 (Difference between the normal app and system app)

  1. A System application is NOT an application that is signed by the OS’s platform signatures. This is a common mistake believed by many and we shall come to this later on. A System application is merely an application that is placed under /system/app folder in an Android device. An application can only be installed in that folder if we have access to the OS’s ROM (system.img). The application is placed under /app folder after the ROM has been extracted. A device which loads the custom ROM will have the new System application added. The benefit of a System application is that the application cannot be removed from the device (cannot be uninstalled by the user). This is only because /system/app is a read-only folder. A non-System application is an ordinary application, which will be installed under /data/app folder, and which is read-write. A user can uninstall such applications normally from the Settings application. One can check if an application is a System application or not using “ApplicationInfo.FLAG_SYSTEM”. If the constant returns true, then the application in question is a System application.

    系统应用程序不是由操作系统的平台签名签名的应用程序。 这是许多人都相信的常见错误,我们将在稍后讨论。 系统应用程序仅仅是位于Android设备中/ system / app文件夹下的应用程序 。 如果我们可以访问操作系统的ROM(system.img),则只能将应用程序安装在该文件夹中。 提取ROM后,该应用程序将放置在/ app文件夹下。 加载自定义ROM的设备将添加新的系统应用程序。 系统应用程序的好处是无法从设备中删除该应用程序(用户无法将其卸载)。 这仅是因为/ system / app是只读文件夹。 非系统应用程序是普通应用程序,它将安装在/ data / app文件夹下,并且是可读写的。 用户可以从“设置”应用程序正常卸载此类应用程序。 可以使用“ ApplicationInfo.FLAG_SYSTEM”检查应用程序是否为系统应用程序 。 如果常量返回true,则说明该应用程序是系统应用程序。

  2. Permission: System apps are granted the ability to request certain system-only permissions that are never available to user apps. This is not the same as root/sudo/su permissions. One example that I know of and use daily is the ability to reset the missed call notification counter. I have Go Dialer, which is a replacement for the stock dialer and contact app (how you make phone calls). When I miss a call, android lets me know that with a notification. However, Go Dialer is not allowed to reset this counter, even though it asks for that permission when you install the app. Android 2.2 and earlier let user apps reset it, but made this permission system-only accessible permission for android 2.3

    权限:系统应用程序被授予请求某些特定于系统的权限的能力,这些权限永远不会对用户应用程序可用。 这是一样的根/须藤/苏权限。 我知道并每天使用的一个示例是重置未接来电通知计数器的功能。 我有Go Dialer,它可以代替股票拨号器和联系人应用程序(拨打电话的方式)。 当我错过来电时,Android会通过通知告知我。 但是,即使Go Dialer在安装应用程序时要求该许可,也不允许重置该计数器。 Android 2.2及更早版本允许用户应用重置它,但为Android 2.3设置了仅系统可访问的权限

  3. Updates: System apps can be updated just like user apps, but the update is never integrated into the original rom. That is, system apps have the unique ability to roll back to the version that existed when the rom was first installed.

    更新:系统应用程序可以像用户应用程序一样进行更新,但是更新从未集成到原始rom中。 也就是说,系统应用程序具有独特的功能,可以回滚到首次安装rom时存在的版本。

  4. Moved to SD: Android lets users move user apps from internal memory to the sd card. System apps cannot be moved and always take up some internal space. Most (all?) devices, though, have internal user apps on a different partition, so uninstalling a system app would not give you any more user app space (other than the Dalvik-cache being removed).

    移至SD: Android允许用户将user应用程序从内部存储器移至SD卡。 系统应用程序无法移动,并且始终占用一些内部空间。 但是,大多数(所有?)设备在不同的分区上都具有内部用户应用程序,因此,卸载系统应用程序不会给您更多的用户应用程序空间(除了要删除的Dalvik缓存外)。

To see the complete list of user apps in android device type below command on terminal:

要查看android设备中用户应用的完整列表,请在终端上键入以下命令:

adb shell pm list packages -3

To see the complete list of installed system apps type below command on the terminal:

要查看已安装系统应用程序的完整列表,请在终端上键入以下命令:

adb shell pm list packages -s

Note: Make sure adb installed and android device connected to the computer.

注意:确保已安装adb,并且android设备已连接到计算机。

系统应用程序相对于用户应用程序的优势 (Advantages of System apps over User apps)

Google provides limited permissions on user apps. We cannot use various permissions, especially at the system level. With system apps, we can get additional permissions for our application. For example, we want to make an application that is able to install other applications (like the Google Play Store), we can get INSTALL_PACKAGES permission. We can also restart our Android device with REBOOT permissions. In addition, we can set the time on our Android system with SET_TIME permissions.

Google对用户应用程序提供了有限的权限。 我们不能使用各种权限,尤其是在系统级别。 使用系统应用程序,我们可以获得应用程序的其他权限。 例如,我们要制作一个能够安装其他应用程序的应用程序(例如Google Play商店),我们可以获得INSTALL_PACKAGES权限。 我们还可以使用REBOOT权限重新启动我们的Android设备。 此外,我们可以使用SET_TIME权限在Android系统上设置时间。

To see more lists of permissions on our Android device, please type the command below the computer terminal.

要查看我们的Android设备上的更多权限列表,请在计算机终端下方输入命令。

adb shell pm list permissions -g

如何制作系统应用程序? (How to make system apps?)

The mandatory thing to do with our application is to add android: sharedUserId = “android.uid.system” in the application tag in AndroidManifest.xml.

我们的应用程序必须执行的操作是添加android: sharedUserId =“ android.uid.system” 在AndroidManifest.xml的application标签中。

Image for post

Then build the APK of our Android project that is ready. After that, just place the APK file in the directory / system / app / or for Android versions of KitKat and above, it can go to the / system / priv-app / director

然后构建我们准备好的Android项目的APK。 之后,只需将APK文件放在目录/ system / app /中,或者将Android文件安装到KitKat及更高版本中,即可将其转到/ system / priv-app / director

The first is to use a signing key. Signing key consists of 2 files, namely certificate (.pem) and private key (.pk8). The signing key here must be the same as the one used for signing our Android ROM. SO signing key is always specific to OEM’S(Samsung, Nokia etc.) And as I explained above, that system apps use permissions at the system level, so potentially people will create dangerous malware for Samsung devices. So keep it a secret for the trusted developer.

第一种是使用签名密钥。 签名密钥包含2个文件,即证书(.pem)和私钥(.pk8)。 此处的签名密钥必须与用于签署我们的Android ROM的密钥相同。 SO签名密钥始终特定于OEM'S(三星,诺基亚等)。如上所述,系统应用程序使用系统级别的权限,因此潜在的人们可能会为三星设备创建危险的恶意软件。 因此,对于可信任的开发人员来说,要保密。

But if we have our own custom ROM, or then we can actually get our Android ROM signing key. We can sign the APK we can use the method below. The signapk.jar file can be found here.

但是,如果我们有自己的自定义ROM,则实际上可以获取我们的Android ROM签名密钥。 我们可以使用以下方法对APK进行签名。 您可以在此处找到signapk.jar文件。

java -jar signapk.jar certificate.pem key.pk8 file-name.apk file-name-signed.apk

Then install the name-file-signed.apk on your Android device as usual. The Android system will automatically recognize it as system apps because it has the same signing key as the ROM and then places it in the partition / system.

然后像往常一样在您的Android设备上安装name-file-signed.apk。 Android系统会自动将其识别为系统应用程序,因为它具有与ROM相同的签名密钥,然后将其放置在分区/系统中。

There are two ways to create system apps:

有两种创建系统应用程序的方法:

  1. Have source code

    有源代码
  2. Have .apk Only

    仅具有.apk

Step 1 Create a folder inside packages/apps/ First, create a folder for your app ( Let say MyTestApp) inside packages/apps/ of your android AOSP downloaded source code. Then create a Android.mk file inside the folder(MyTestApp), and in last copy your app source code inside the folder(MyTestApp) as for example following folder and file

步骤1packages / apps /内创建一个文件夹首先,在您的android AOSP下载源代码的packages / apps /内为您的应用创建一个文件夹(假设为MyTestApp)。 然后在文件夹(MyTestApp)内创建一个Android.mk文件,最后在文件夹(MyTestApp)内复制您的应用程序源代码,例如,跟随文件夹和文件

  • assets,

    资产,
  • build,

    建立,
  • res,

    RES,
  • src and

    src和
  • AndroidManifest.xml etc

    AndroidManifest.xml等

Step 2 open Android.mk file and add folowing code Snippet

第2步打开Android.mk文件并添加以下代码段

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)
LOCAL_CERTIFICATE := platform LOCAL_SRC_FILES
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := MyTestApp
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_PRIVILEGED_MODULE := true
LOCAL_STATIC_JAVA_LIBRARIES := libarity android-support-v4
include $(BUILD_PACKAGE)
include $(call all-makefiles-under,$(LOCAL_PATH))

save this mk file.

保存此mk文件。

Step 3 put your app name in build/target/product/ folder open core.mk file from build/target/product/ folder and add your app name(MyTestApp) inPRODUCT_PACKAGES tag at the bottom MyTestApp.Note:-for the specific vendor, you can find the path like this vendor/manufacturer/device/vendor_device.mk

步骤3将您的应用程序名称放入build / target / product /文件夹中的build / target / product /文件夹中打开core.mk文件,并在MyTestApp底部的PRODUCT_PACKAGES标签中添加您的应用程序名称(MyTestApp)。注意:-对于特定的供应商,您可以找到此供应商/制造商/设备/vendor_device.mk的路径

Now step by step procedure for .apk file Step 1 will be same like above only change is that in place of src, res folder just put your .apk file.

现在,.apk文件的分 过程 第1步将与上面相同,只是更改是在src的位置,res文件夹只是放置了.apk文件。

step 2 open Android.mk file and add folowing code Snippet

第2步打开Android.mk文件并添加以下代码段

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optional
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)LOCAL_MODULE := MyTestAppLOCAL_SRC_FILES := $(LOCAL_MODULE).apkLOCAL_MODULE_CLASS := APPSLOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
# if Apk is signed then use it. Otherwise use platform
LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT)

Step 3 will be the same as an above mention for Android source code (a)This is all about how to make an android app as a system App.

步骤3将与上述针对Android源代码的说明相同(a)这都是关于如何将android应用制作为系统应用的信息。

If you an apk file and wants to install a system app through adb commands, in that case, we have to push the .apk to the phone to the System partition. the path of the folder is /system/app or /system/priv-app (Android 4.3) using adb

如果您是一个apk文件,并且想通过adb命令安装系统应用程序,那么在这种情况下,我们必须将.apk推送到手机的“系统”分区中。 文件夹的路径是使用adb的 / system / app/ system / priv-app (Android 4.3)

adb root
adb remount
adb push <file name> .apk / system / priv-app /
adb shell chmod 644 / system / priv-app / <file name> .apk
adb reboot

If SD card, then place your apk file in sdcard like this:

如果是SD卡,则将您的apk文件放入sdcard中,如下所示:

adb push my-app.apk /sdcard/
adb shell
su
cd /sdcard
mv my-app.apk /system/app
# or when using Android 4.3 or higher
mv my-app.apk /system/priv-app

Note: All System-Apps need to have the permissions rw-r — r — . So we can change them via adb with the change mode command like chmod 644 /path_to/your_file

注意:所有系统应用程序都需要具有权限rw-r — r —。 因此,我们可以使用chmod 644 / path_to / your_file等更改模式命令通过adb更改它们

In this article, I have written about the system apps. I will write some more useful articles subjected to android so to know about that please keep following and clapping if you liked it.

在本文中,我写了有关系统应用程序的文章。 我将写一些适用于android的更有用的文章,以便了解这一点,如果您喜欢它,请继续关注并鼓掌。

I hope you enjoyed this session. If you have any comments or questions, please join the forum discussion below!

我希望你喜欢这次会议。 如果您有任何意见或疑问,请加入下面的论坛讨论!

To have a look for other articles, PFA link:

要查看其他文章,PFA链接:

Thanks for the support :)

感谢您的支持 :)

Android Developers, AndroidPIT.com, Xyz Zyx, Android, The Funtasty Android Devs, Sundar Pichai, Elye, Medium Staff, Cesar Valiente, Google Developers

Android开发者AndroidPIT.com的Xyz ZYX安卓该Funtasty Android的离散事件桑德尔·皮蔡Elye中等职员塞萨尔巴连特谷歌开发者

翻译自: https://android.jlelse.eu/system-app-in-android-f003d418b4cc

Logo

更多推荐