System attribute simulation method and device based on Android simulator and electronic equipment
By initializing and mounting the target attribute directory on the Android emulator, the problem of complex acquisition of system attributes by the Android emulator is solved, simple and efficient system attribute simulation is achieved, and the compatibility and operation efficiency of Android applications are improved.
Patent Information
- Application Number
- CN202510322479.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-18
- Publication Date
- 2025-07-18
AI Technical Summary
In the prior art, the Android emulator has a complex method when obtaining system attributes, making it difficult to effectively simulate Android system attributes in non-Android systems, resulting in compatibility issues, especially when running Android game applications, which cannot provide matching game functions.
After the Android emulator is started, initialize the system attribute file in the target attribute directory, determine whether the target Android application needs to simulate the system attributes, and mount the target attribute directory to the preset directory, so that the target Android application can read the system attributes from the target attribute directory, and at the same time clear the system attribute cache in the cache space.
It realizes simple and efficient simulation of system properties on the Android emulator, ensuring that the target Android application can read customized system properties, improving compatibility and running efficiency, and reducing development and testing time.
Smart Images

Figure CN120335929A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a method, device, electronic device, and computer-readable storage medium for simulating system properties based on an Android emulator. Background Art
[0002] An Android emulator is emulator software that can simulate the Android system in a non-Android system (such as a Windows system or a Linux system). It simulates the Android system running environment in the non-Android system, enabling users to run and use Android applications in the non-Android system. Due to the significant differences between the Android emulator and the real Android device, the Android emulator faces many compatibility challenges. For example, for game applications based on the Android system, game functions matching the system properties generally need to be provided according to the system properties of the Android emulator. Therefore, to run game applications properly on the Android emulator, the Android emulator needs to simulate the corresponding game system properties.
[0003] In the related art, system properties are obtained by manually parsing files in the / dev / __properties__ directory. However, since the system property files in the / dev / __properties__ directory are usually in binary format, which means they cannot be directly read and written using a text editor, the method for obtaining system properties is relatively complex.
[0004] Based on this, a method is needed to simulate system properties on the Android emulator so that Android applications can obtain the corresponding system properties on the Android emulator, thereby ensuring the proper operation of Android applications on the Android emulator. Summary of the Invention
[0005] This application provides a method, device, electronic device, and computer-readable storage medium for simulating system properties based on an Android emulator to solve the problem of the relatively complex acquisition of system properties in the above-mentioned related art.
[0006] In a first aspect, an embodiment of this application provides a method for simulating system properties based on an Android emulator, and the method includes:
[0007] After the Android emulator is started, initialize the target system property file in the target property directory;
[0008] Start the target Android application on the Android emulator, and determine whether it is necessary to simulate the system properties of the Android emulator based on the target system property file for the target Android application;
[0009] If so, mount the target attribute directory under a preset attribute directory, so that the target Android application reads system attributes from a target system attribute file under the target attribute directory during the running of the target Android application in the Android emulator;
[0010] Clear the system attribute cache in the target cache space in the Android emulator;
[0011] Run the target Android application on the Android emulator.
[0012] In a second aspect, an embodiment of the present application provides a system attribute simulation device based on an Android emulator. The device includes:
[0013] An initialization module, configured to initialize a target system attribute file under a target attribute directory after the Android emulator is started;
[0014] A judgment module, configured to start the target Android application on the Android emulator, and judge whether system attribute simulation of the Android emulator needs to be performed based on the target system attribute file for the target Android application;
[0015] A processing module, configured to, if so, mount the target attribute directory under a preset attribute directory, so that the target Android application reads system attributes from a target system attribute file under the target attribute directory during the running of the target Android application in the Android emulator;
[0016] A clearing module, configured to clear the system attribute cache in the target cache space in the Android emulator;
[0017] A running module, configured to run the target Android application on the Android emulator.
[0018] In a third aspect, an embodiment of the present application provides an electronic device. The electronic device includes:
[0019] A memory and a processor, the memory and the processor are coupled;
[0020] The memory is used to store one or more computer instructions;
[0021] The processor is configured to execute the one or more computer instructions to implement the system attribute simulation method based on an Android emulator according to any one of the first aspects above.
[0022] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which one or more computer instructions are stored. The characteristics are that the instructions are executed by a processor to implement the system attribute simulation method based on an Android emulator according to any one of the first aspects above.
[0023] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which when executed by a processor implements the system property simulation method based on an Android emulator according to any one of the above first aspects.
[0024] Compared with the prior art, the present application has the following advantages:
[0025] For the system property simulation method based on an Android emulator provided by the present application, first, after the Android emulator is started, the target system property file in the target property directory is initialized, so as to realize the customization of system properties; the target Android application is started on the Android emulator, and it is judged whether the Android emulator needs to perform system property simulation based on the target system property file for the target Android application; if so, the target property directory is mounted under the preset property directory, so that during the running of the target Android application, the target Android application reads system properties from the target system property file in the target property directory, so that customized system properties can be read, and thus customized system property simulation for the target Android application on the Android emulator can be realized; the system property cache in the target cache space in the Android emulator is cleared; the target Android application is run on the Android emulator, so that the method for the Android emulator to simulate system properties is simpler and more efficient. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:
[0027] Figure 1 It is a schematic diagram of the processing flow of the system properties of the prior art;
[0028] Figure 2 It is one of the schematic diagrams of the flow of the system property simulation method based on an Android emulator provided by one embodiment of the present application;
[0029] Figure 3 It is the second of the schematic diagrams of the flow of simulating system properties based on an Android emulator provided by one embodiment of the present application;
[0030] Figure 4 It is the schematic diagram of the structure of the system property simulation device based on an Android emulator provided by one embodiment of the present application;
[0031] Figure 5 It is the schematic diagram of the hardware structure of the electronic device provided by one embodiment of the present application.
[0032] Through the above-mentioned drawings, specific embodiments of the present application have been shown, and will be described in more detail hereinafter. These drawings and the written description are not intended to limit the scope of the concept of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by reference to specific embodiments. Detailed Embodiments
[0033] In order to make the objectives, advantages and features of the present application clearer, the present application will be clearly and completely described below with reference to the accompanying drawings and specific embodiments. In the following description, many specific details are set forth in order to fully understand the present application. However, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art without making creative efforts fall within the scope of protection of the present application.
[0034] It should be noted that in the description of the present application, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance, as well as a specific order or sequence. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to specific circumstances. In addition, in the description of the present application, unless otherwise specified, the term "plurality" means two or more. The term "and / or" describes the association relationship of associated objects and indicates that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after. The terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0035] To facilitate the understanding of the technical solution of the present application, relevant concepts involved in the present application will be introduced first.
[0036] An Android emulator is a simulator software that can simulate the Android system in a non-Android system (such as a Windows system or a Linux system). It simulates the Android system running environment in the non-Android system, enabling users to run and use Android applications in the non-Android system.
[0037] Next, the prior art related to the present application and the problems existing in the prior art will be described:
[0038] Due to the significant differences between Android emulators and real Android devices, Android emulators face many compatibility challenges. For example, for game applications based on the Android system, it is generally necessary to provide game functions that match the system properties according to the system properties of the Android emulator. Therefore, to run game applications normally on an Android emulator, the emulator needs to simulate the corresponding game system properties.
[0039] In the related art, taking Android game applications as an example, Figure 1 is a schematic diagram of the processing flow of the system properties of the prior art. As Figure 1 shown, after the processing flow starts, Android emulator developers first communicate with the game party to negotiate the optimal performance mode after the game application is launched. Subsequently, the developers reverse-analyze the system properties on which the game application depends to enable the optimal performance mode and configure the system property file. After the system property file configuration is completed, regression testing is performed to ensure that no new problems are introduced or existing functions are affected. If the regression testing fails, the system property file needs to be reconfigured until the regression testing passes. After the regression testing passes, the system property file is sent from the server for system property configuration, and a pop-up window is used to remind the user to restart the Android emulator for the system property configuration to take effect. As described above, during the process of system property configuration, i.e., simulation, stubs are inserted at certain positions in the Android emulator system, and then the property configuration file is sent to solve the problem of simulating system properties on the Android emulator.
[0040] The following are two common stub insertion positions: First, when the Zygote process in the Android emulator operating system starts, the system property file is read, and the final modifier of the corresponding Field field in the android.os.Build class is removed, so that the value of the corresponding Field field in the android.os.Build class can be dynamically modified according to the content of the read system property file. Exemplarily, taking the following code as an example, the value of the corresponding Field field board in the android.os.Build class is dynamically modified.
[0041] String board = props.get("ro.product.board"); / / Obtain the value of ro.product.board from the system property file
[0042] if (board!= null) Build.BOARD = board; / / If board is not null, assign the value of board to Build.BOARD
[0043] Among them, Zygote is the starting point of all application processes in the Android operating system. The android.os.Build class is a core class in the Android system framework, which is used to provide device- and system-related property information. In Java, the java.util.Properties class provides a mechanism to process system property files, which usually contain configuration information in the form of key-value pairs. props.get() is usually used to obtain the value corresponding to a specified key from the system properties file.
[0044] Second, by using int__system_property_get(const char*name,char*value), given the system property name name, read the property value corresponding to the system property name name from the system property file. Among them, __system_property_get is a low-level C function in the Android system, which is used to directly access the key-value pairs in the system property storage area to obtain the value of the specified key.
[0045] However, the above two instrumentation positions may obtain untrue system property values. To obtain more real system property values, usually the method of manually parsing the files in the / dev / __properties__ directory is adopted to obtain system property values. However, since the system property files in the / dev / __properties__ directory are usually in binary format, the simulation cannot be solved by using conventional file replacement. It is necessary to generate the files to be forged for replacement by referring to the process of the init process initializing system properties, resulting in a relatively complex implementation of this acquisition method.
[0046] To solve the problems existing in the above related technologies, the present application provides a system property simulation method based on an Android emulator, a system property simulation device corresponding to the method, an electronic device capable of implementing the system property simulation method based on the Android emulator, and a computer-readable storage medium. The following provides embodiments to elaborate on the above method, device, electronic device, and computer-readable storage medium in detail.
[0047] To make the objectives and technical solutions of this application clearer and more intuitive, the following will, in conjunction with the accompanying drawings and embodiments, provide a detailed description of the method provided in the embodiments of this application. It should be understood that the specific embodiments described herein are only used to explain this application and are not used to limit this application. It can be understood that the following several embodiments can exist independently, and when there is no conflict between the embodiments provided in this application, the following embodiments and the features in the embodiments can be combined with each other. For the same or similar content, it will not be repeated in different embodiments. In addition, the sequence of steps in the following method embodiments is only an example and is not strictly limited. In some cases, the steps shown or described can be executed in a different order than this.
[0048] This application provides a method, apparatus, electronic device, and computer-readable storage medium for simulating system attributes based on an Android emulator. Specifically, the method for simulating system attributes based on an Android emulator in one embodiment of this application can be executed by a computer device, where the computer device can be a terminal or a server, etc. The terminal can be a smart phone, a tablet computer, a laptop computer, a touch screen, a game console, etc. The terminal can also include a client, and the client can be a game application client, a browser client with a game program, or an instant messaging client, etc. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and big data and artificial intelligence platforms.
[0049] Next, in conjunction with Figure 2 , a method for simulating system attributes based on an Android emulator provided in one embodiment of this application will be described. Figure 2 FIG. is one of the flow diagrams of the method for simulating system attributes based on an Android emulator provided in one embodiment of this application.
[0050] As Figure 2 shown, the method for simulating system attributes based on an Android emulator includes steps S101-105:
[0051] S101. After the Android emulator is started, initialize the target system attribute file in the target attribute directory.
[0052] S102. Start the target Android application on the Android emulator, and determine whether it is necessary to simulate the system attributes of the Android emulator based on the target system attribute file for the target Android application.
[0053] S103. If so, mount the target attribute directory under the preset attribute directory, so that during the running of the target Android application on the Android emulator, the target Android application reads system attributes from the target system attribute file under the target attribute directory.
[0054] S104. Clear the system attribute cache in the target cache space in the Android emulator.
[0055] S105. Run the target Android application on the Android emulator.
[0056] Next, the above steps S101 - S105 will be described in detail:
[0057] As mentioned above, the target attribute directory refers to the storage area for storing custom system attributes during debugging or testing, such as the / dev / temp / __properties__ directory. The target system attribute file refers to the specific system attribute file stored under the target attribute directory.
[0058] In the embodiment of the present application, when starting the target Android application on the Android emulator, it is judged whether the Android emulator needs to perform system attribute simulation based on the target system attribute file for the target Android application.
[0059] An optional implementation manner is that the target system attribute file contains the application package name. A possible implementation manner of step S102, "judging whether the Android emulator needs to perform system attribute simulation based on the target system attribute file for the target Android application", includes steps S1021 - S1022:
[0060] S1021. Judge whether the application package name contained in the target system attribute file matches the application package name of the target Android application.
[0061] S1022. If they match, it is determined that the Android emulator needs to perform system attribute simulation based on the target system attribute file.
[0062] In the embodiment of the present application, during the process of starting the target Android application through the Android emulator, the system configuration file will be automatically read first. This file contains some key configuration information about the device and the system, such as whether to start simulated attributes, the package name matching conditions, and the specific simulated system attribute values.
[0063] For example, an example of the system configuration file is as follows:
[0064] #package_name=com.XXX.app
[0065] product_name=SimulatedProductName
[0066] build_version = 12.0
[0067] After reading the above system configuration file, the application checks whether the package name of the target Android application (such as com.XXX.app) matches the package name specified in the system configuration file. It can be seen that there is a package name in the example system configuration file that matches the package name of the target Android application, so the package name is determined to be a match. In the case where the package name is determined to be a match, the Android emulator is controlled according to the attributes in the system configuration file to perform system attribute simulation.
[0068] As mentioned above, the preset attribute directory is a global attribute directory, which is the core storage area of Android system attributes and is used to store system attributes accessible to all processes. For example, the / dev / __properties__ directory is the only authoritative source of system attributes in the Android system.
[0069] In the embodiment of the present application, in the case where it is determined that the Android emulator needs to perform system attribute simulation based on the target system attribute file for the target Android application, before the Android emulator runs the target Android application (that is, after the icon of the target Android application is clicked and the Android emulator system is about to start the target Android application but fails to open the application interface. Taking the time point when the Android emulator system calls the public void onCreate() function of the Application of the target Android application as the judgment time point, the time before calling the public void onCreate() function of the target Android application is determined as the time before the Android emulator runs the target Android application), the target attribute directory is mounted under the preset attribute directory, so that during the process of the Android emulator running the target Android application, the target Android application reads system attributes from the target system attribute file under the target attribute directory. Exemplarily, the mount command is used to replace the / dev / __properties__ directory with the / dev / temp / __properties__ directory. This means that a different file system or directory is mounted at the position of / dev / __properties__, which can temporarily replace the original system attribute file, thereby overwriting the content of the original / dev / __properties__ directory. This enables the target Android application to read the system attribute values from the target system attribute file under the target attribute directory when accessing system attributes, rather than reading data from the original system attribute file. In this way, the system attributes obtained by manually interpreting / dev / __properties__ are the system attributes obtained from the new system attribute file mounted after replacing the / dev / __properties__ directory using the mount command.
[0070] It should be noted that in the embodiments of the present application, replacing the / dev / __properties__ directory with the mount command can not only ensure that the system property values read by various acquisition functions are consistent, but also does not affect the normal operation of other Android applications and the entire Android emulator operating system on the Android emulator.
[0071] In the Android emulator system, there is a caching mechanism for system properties in the C standard library, that is, libc. This means that once a certain system property is read, the system property will be cached. If the system property is read multiple times subsequently, the property value of the system property can be directly obtained from the cache instead of being reread from the system property file each time. This caching mechanism can greatly improve system performance. In the embodiments of the present application, since the / dev / __properties__ directory is replaced with the mount command, the system property files under the / dev / __properties__ directory have changed, that is, some system property values in the system property files before and after the change may be inconsistent. In order to make the newly mounted system property file under the / dev / __properties__ directory, that is, the target system property file, take effect immediately, and in order to avoid the system property values read from the cache being inconsistent with the system property values read from the new system property file, it is necessary to clear the system property cache in the cache.
[0072] Next, in combination with Figure 3 , Figure 3 FIG. 2 of the flowchart of simulating system properties based on an Android emulator provided by one embodiment of the present application is used to further illustrate the process of simulating system properties based on an Android emulator on the PC side. As Figure 3 shown, start the Android emulator deployed on the PC side (that is, Figure 3In the Android system startup process, initialize the / dev / temp / __properties__ directory. After the Android emulator starts, it initializes the / dev / temp / __properties__ directory to facilitate custom modification of system properties in the / dev / temp / __properties__ directory during the subsequent process of running the target Android application through the Android emulator, enabling the Android emulator to successfully simulate certain system properties. After the Android emulator starts successfully, start the application, that is, run the target Android application on the Android emulator. Next, read the system property configuration file and determine whether there is a package name in the property configuration file that matches the target Android application. If not, the target Android application starts successfully; if so, it is necessary to mount the / dev / temp / __properties__ target to the / dev / __properties__ target and clear the system property cache in the memory, then the target Android application starts successfully.
[0073] According to the above Figure 3 The process of simulating system properties by the Android emulator as shown has the following advantages: 1. Without affecting the normal startup of the Android emulator, different system properties can be configured for different target Android applications; 2. It only takes 10 minutes at the fastest from the completion of the solution development to reaching the user's machine; 3. The user can complete simulating properties by restarting the emulator; 4. Using package name matching as a prerequisite for the currently launched Android application, the system properties of the Android emulator are only simulated when the package names match, which ensures that no unknown risks are introduced to other target Android applications.
[0074] The system property simulation method based on the Android emulator provided by the embodiments of this application first initializes the target system property file in the target property directory after the Android emulator starts, which can achieve customization of system properties. Start the target Android application on the Android emulator and determine whether it is necessary to simulate the system properties of the Android emulator based on the target system property file for the target Android application. If so, mount the target property directory to the preset property directory so that the target Android application reads system properties from the target system property file in the target property directory during the process of running the target Android application, so that custom system properties can be read, and thus customized system property simulation of the Android emulator can be achieved for the target Android application. Clear the system property cache in the target cache space in the Android emulator. Run the target Android application on the Android emulator, which can make the method of the Android emulator simulating system properties simpler and more efficient.
[0075] Based on the above embodiments, the system property simulation method based on an Android emulator provided in the embodiments of the present application will be further described below.
[0076] An optional implementation manner is that the system property simulation method based on an Android emulator provided in the embodiments of the present application further includes the following step S106:
[0077] S106. In response to receiving an update file for system properties, update the target system property file based on the update file.
[0078] In the embodiments of the present application, during the running of a target Android application on an Android emulator, dynamically updating part of the code or the system of the target Android application is called a hot update system (i.e., the update file for system properties). The hot update system will regularly pull the following changed hot update files at each preset time interval, such as 10 minutes. Among them, the changed hot update files refer to the files that are dynamically downloaded and applied during the running of a target Android application on an Android emulator to fix problems, add new functions, or update resources. These files usually contain small-scale modifications (i.e., "changes") to the existing target Android application code or resources and can be deployed without republishing the entire application package. During the first startup of the target Android application on the Android emulator, the system configuration file will be read first. Only when the package name matching the target Android application is found in the system configuration file, will system property simulation be performed on the target Android application, and then the target Android application will be started.
[0079] An optional implementation manner is that the specific implementation manner of the above step S101 "initialize the target system property file in the target property directory" includes S1011:
[0080] S1011. Obtain a first property file from the Android device and write the first property file into the target system property file in the target property directory.
[0081] In the embodiments of the present application, the first property file is a property file associated with the Android device and the Android system running in the Android device. For example, the SELinux rule file can be parsed through the LoadPropertyInfoFromFile function in the init module, and the parsed target file can be written into the / dev / temp / __properties__ file.
[0082] An optional implementation manner is that before step S102 "mount the target property directory under the preset property directory", the system property simulation method based on an Android emulator provided in the embodiments of the present application further includes step S107:
[0083] S107. Separate the memory space of the target system property file from the memory space corresponding to the preset system property file in the preset property directory.
[0084] In the embodiment of the present application, unshare can be used to separate the memory space of the target system property file from the memory space corresponding to the preset system property file in the preset property directory, which is convenient for modifying only the content in the memory space of the target system property file to avoid modifying the content in the memory space corresponding to the preset system property file in the preset property directory, so that the content in the memory space corresponding to the preset system property file in the preset property directory remains unchanged.
[0085] An optional implementation manner is to clear the system property cache in the target cache space of the Android emulator. The system property simulation method based on the Android emulator provided in the embodiment of the present application further includes the following step S108:
[0086] S108. Initialize the structure of the system properties in the target cache space.
[0087] In the embodiment of the present application, the application can obtain system properties from the structure related to system properties through the exported function of libc. If the structure of system properties in libc is not re-initialized, using the libc exported function to obtain system properties will obtain the system properties before simulation, and it cannot be guaranteed that the system properties obtained by different methods are consistent.
[0088] An optional implementation manner is to clear the system property cache in the target cache space of the Android emulator. The system property simulation method based on the Android emulator provided in the embodiment of the present application further includes the following step S109:
[0089] S109. Add a target global variable for indicating whether to refresh the system property cache in the system property underlying access interface, and share the target global variable to the control mechanism corresponding to the target cache space.
[0090] An optional implementation manner, the system property simulation method based on the Android emulator provided in the embodiment of the present application further includes the following step S110:
[0091] S110. In response to the acquisition instruction for the original target system property of the Android emulator, control to obtain the system property value corresponding to the target system property through the thread local variable mechanism.
[0092] In the embodiments of the present application, when it is necessary to obtain the original value (instead of the cached value or the processed value) of the target system property, a specific key can be passed through the Thread-Local Storage (TLS), so as to directly obtain the system property value corresponding to the target system property from the original property storage area of the system, that is, the preset property directory.
[0093] Next, the system property simulation method based on the Android emulator provided by the embodiments of the present application will be further described, including the following steps S201-S207.
[0094] S201. During the process of starting the Android emulator through the PC side, after the PropertyInit function is executed in the SecondStageMain function of system / core / init / init.cpp, insert the Property_init_ext function.
[0095] As mentioned above, during the startup process of the Android emulator, the init process is the first user-space process to start in the Android system and is responsible for initializing various system services and properties. The SecondStageMain function defined in the system / core / init / init.cpp file is the second-stage startup function of the init process and is responsible for completing most of the initialization work, including starting services, mounting file systems, initializing the property system, etc. Inserting the Property_init_ext function after the SecondStageMain function executes the PropertyInit function can achieve the extension or customization of the property system. Among them, the Property_init_ext function is a function used to initialize the property system. It will set some initial system properties and prepare the property server so that other processes can access and modify these system properties.
[0096] S202. Initialize the / dev / temp / __properties__ file.
[0097] As mentioned above, in the Android emulator, the Property System is a key component for managing system-level configuration parameters and status information. These properties can be shared among different processes and can be accessed and modified through command-line tools such as getprop and setprop.
[0098] Exemplarily, in property_init_ext(), the / dev / temp / __properties__ file is initialized. The example code for initializing the / dev / temp / __properties__ file is as follows:
[0099] void property_init_ext(){
[0100] mkdir("dev / temp", S_IRWXU|S_IXGRP);
[0101] mkdir("dev / temp / __properties__", S_IRWXU|S_IXGRP|S_IXOTH);
[0102] }
[0103] In the above example code, int mkdir(const char*pathname, mode_t mode) is a system call function used to create a new directory in the file system. Among them, pathname points to the string of the directory path to be created. mode specifies the permission mode of the newly created directory. Among them, the meaning of the code mkdir("dev / temp", S_IRWXU|S_IXGRP) is that the directory path to be created is / dev / temp, and the permission mode of this directory is that the owner can read, write, and execute this directory, and group users can execute this directory. The meaning of the code mkdir("dev / temp / __properties__", S_IRWXU|S_IXGRP|S_IXOTH); is that the directory path to be created is mkdir("dev / temp / __properties__", S_IRWXU|S_IXGRP|S_IXOTH), and the permission mode of this directory is that the owner can read, write, and execute this directory, and group users and other users can execute this directory.
[0104] 203. The SELinux rule file extracted from the Android real device is read and set into the file under the / dev / temp / __properties__ directory.
[0105] As mentioned above, an Android real device refers to a physical device that actually exists and can run the Android operating system, such as a smartphone, a tablet computer, or other Android-based hardware devices. Different from an Android emulator, an Android real device is an actual hardware device with complete hardware functions and performance.
[0106] As mentioned above, the SELinux rule files refer to the core configuration files used to define the security policies of the Android system on the Android real device. These files control resources such as processes, files, and network ports in the Android system, as well as the access permissions of each resource, ensuring the security of the Android system. As an operating system based on the Linux kernel, the Android system inherits and optimizes the SELinux mechanism to adapt to the characteristics of mobile devices.
[0107] Next, an exemplary description is given of the SELinux rule files extracted from the Android real device.
[0108] ro.product.system.brand u:object_r:build_prop:s0exact string
[0109] / / Indicates the brand information of the device; u:object_r:build_prop:s0 defines the SELinux type of this system property as build_prop, indicating that this is a property related to system configuration; exact string indicates that the value of this property must be an exactly matching string.
[0110] ro.product.system.device u:object_r:build_prop:s0exact string
[0111] / / Indicates the specific model of the device; u:object_r:build_prop:s0 defines the SELinux type of this system property as build_prop, indicating that this is a property related to system configuration; exact string indicates that the value of this property must be an exactly matching string.
[0112] ……
[0113] ro.system.build.date u:object_r:build_prop:s0exact string
[0114] / / Indicates the build date of the system image (such as "2023-10-05"); u:object_r:build_prop:s0 defines the SELinux type of this system property as build_prop, indicating that this is a property related to system configuration; exactstring indicates that the value of this property must be an exactly matching string.
[0115] ro.system.build.fingerprint u:object_r:build_prop:s0 exact string
[0116] / / Represents the unique fingerprint information of the system, usually including information such as brand, model, build version, etc.; u:object_r:build_prop:s0 defines the SELinux type of this system property as build_prop, indicating that this is a property related to system configuration; exact string indicates that the value of this property must be an exactly matching string.
[0117] ……
[0118] In the embodiment of the present application, the SELinux rule file of the Android real machine is obtained, and the SELinux rule file is written into the file in the / dev / temp / __properties__ directory. In this way, the file in the / dev / temp / __properties__ directory initializes or extends the Android property system by simulating the Android real machine. Specifically, the LoadPropertyInfoFromFile function in the init module can be used to parse the SELinux rule file, and the parsed target file is written into the / dev / temp / __properties__ file. The / dev / temp / __properties__ is empty when it is just created. After executing "writing the SELinux rule file into the / dev / temp / __properties__ directory", this file has the target system property file, and then the system properties will be written into this target system property file.
[0119] S204. Insert a stub in the SpecializeCommon function of frameworks / base / core / jni / com_android_internal_os_Zygote.cpp, read the configuration file to determine whether the current application needs to simulate system properties. When it is necessary to simulate system properties, first use unshare to separate the shared memory of the current namespace, and then re-initialize, and mount the / dev / temp / __properties__ file to the / dev / __properties__ file.
[0120] As mentioned above, in the Android system, Instrumentation is a technical means used to insert additional logic or monitoring points at key positions in the code. Instrumentation can be used to collect runtime data, analyze performance, debug problems, or implement specific functional extensions.
[0121] The SpecializeCommon function is located in the file frameworks / base / core / jni / com_android_internal_os_Zygote.cpp and is an important function during the initialization process of the Zygote process. Zygote is one of the core components of the Android system and is responsible for creating and managing all application processes. Instrumenting in the SpecializeCommon function means inserting additional logic at a critical stage of Zygote initialization, and it can be used to monitor the behavior of Zygote, modify its default configuration, or inject specific functions into subsequent application processes.
[0122] In the embodiment of this application, instrumenting is performed in the SpecializeCommon function of frameworks / base / core / jni / com_android_internal_os_Zygote.cpp, specifically inserting a piece of code for reading a property configuration file to determine whether a target Android application needs to simulate system properties. The example code is as follows.
[0123]
[0124] / / TEMP_FAILURE_RETRY is a macro used to handle temporary I / O errors. The mount function is used to mount / dev / temp / __properties__ to / dev / __properties__. MS_BIND indicates a bind mount, and MS_REC indicates a recursive mount. If the mount fails, the error is reported through the fail_fn callback function and the function returns.
[0125] __system_properties_abandon(); / / Abandon the old system properties.
[0126] __system_properties_init(); Initialize the new system properties.
[0127] }
[0128] The main purpose of the above example code is to perform instrumentation in the SpecializeCommon function of frameworks / base / core / jni / com_android_internal_os_Zygote.cpp, inserting a section of code for reading a configuration file to determine whether the target Android application needs to simulate system properties. When determining whether the current target Android application needs to simulate system properties, the unshare system call is used to create an independent mount namespace / dev / __properties__ in the Zygote process, so that the current process no longer shares the same memory area with the parent process (Zygote), avoiding the impact of property simulation on other processes. Subsequently, the above namespace / dev / __properties__ is initialized, so that after separating the namespaces, the property system is re-initialized to customize and set the simulated system properties in the independent shared memory area / dev / __properties__ without affecting other processes. Subsequently, the specific system property directory dev / temp / __properties__ is mounted into the namespace dev / __properties__, thereby achieving isolation and protection of system properties, ensuring that only authorized processes can access or modify these key properties and improving the security of the system. In this way, the customization of system property simulation for the Android emulator can be completed for the target Android application.
[0129] S205. Clear the system property data cache in memory, re-initialize the structures related to system properties in libc, and ensure that the system properties obtained by libc come from / dev / temp / __properties__.
[0130] In the embodiment of this application, during the process of re-initializing the property system (Property System) in the Android emulator system, the cached system property values in libc are cleared to ensure that the old cached data will not be used when reading system properties subsequently, and ensure that the system property data obtained from libc always comes from the / dev / temp / __properties__ shared memory area. The operation of clearing the system property cache usually involves the following operations: calling an internal clearing function or directly operating on the relevant structures of libc and marking the cache as invalid.
[0131] S206. Determine whether there is a system property cache in CachedProperty.h. If so, a global variable needs to be added in system_properties_api.cpp to indicate whether the cache needs to be refreshed, and this global variable is exposed for use in CachedProperty.h.
[0132] In the embodiment of the present application, the caching mechanism in the Android emulator system CachedProperty.h is designed to improve performance. By caching frequently accessed property values in the CachedProperty.h memory, direct access to the shared memory area (such as / dev / temp / __properties__) can be reduced, thus accelerating the reading speed. However, when the property system changes (such as re-initialization, switching namespaces, or simulating system properties), if the cache is not updated in time, it may result in reading old and inconsistent data, and this inconsistency may lead to abnormal application behavior or security issues. To ensure the consistency of the property cache, a global variable can be introduced in system_properties_api.cpp to mark whether the cache needs to be refreshed. At the same time, expose this variable to CachedProperty.h for use, so that the cache can be emptied in time and the latest property values can be reloaded when needed.
[0133] S207. When the original property needs to be obtained, adopt the thread-local variable mechanism and pass the corresponding key value to obtain the original system property.
[0134] In the embodiment of the present application, when the original system property needs to be obtained, the property value of a specific system property is passed through a thread-local variable, so as to directly obtain the property value from the original property storage area of the system.
[0135] In the embodiment of the present application, for the target Android application, whether it reads the system properties by parsing the files under / dev / __properties__ by itself or reads the system properties through the libc exported function, it can ensure that the system property values simulated by the Android emulator are read and the read system property values are consistent.
[0136] Next, in combination with two specific examples, an exemplary description is given of using the system property simulation method based on the Android emulator provided in the embodiment of the present application to solve the problem that the Android emulator runs the target Android application incorrectly due to obtaining incorrect system properties.
[0137] Example 1: Problem: Solve the problem that the advertisement of the target Android application "XXX1 Game" does not display.
[0138] Analyze the root cause of the problem: Through reverse engineering tools, it is found that when the "XXX Advertising Platform" is initialized, a lot of device information is uploaded to the server to distribute different advertising resources for different devices. This SDK obtains the value of ro.build.fingerprint by manually interpreting the files in the / dev / __properties__ directory. Therefore, the above method needs to be used to return the value of ro.build.fingerprint of an Android real device for this game.
[0139] Design and develop a solution:
[0140] Content of the app-device-prop-android12.config file:
[0141] com\.mudamuda\.idlewow / etc / mount-configs / device-proper.config
[0142] Content of the dev_properties.config file:
[0143] ro.build.expect.bootloader=slide-r-1.2-9152146
[0144] ro.build.fingerprint=google / oriole / oriole:13 / TQ1A.221205.011 / 9244662:user / rel ease-keys
[0145] ro.build.flavor=oriole-user
[0146] In this way, the value of ro.build.fingerprint of the Android real device is written into the dev_properties.config file. By reading the dev_properties.config file, the value of ro.build.fingerprint of the Android real device can be obtained, so that the advertisement can be normally displayed on the Android emulator later. After passing the test, hotfix is performed. It took about 4 hours from the start of analysis to reaching the user's machine. The user only needs to restart the emulator to complete the repair and display the advertisement normally.
[0147] Example 2: Requirement: Enable the high-quality graphics function of the target Android application "XXX2 Game".
[0148] After communicating with the game party, it is concluded that the model that needs to configure the emulator during game operation is "XXA12pro". The game will match this model and enable a high - quality graphics mode after hitting it.
[0149] Design and develop a solution:
[0150] Content of the app - device - prop - android12.config file:
[0151] com.xindong.torchligh / etc / mumu - configs / device - prop - config s / xiaomi14pro.conf
[0152] Content of the XXX12pro.config file:
[0153] ro.product.board=shennong
[0154] ro.product.brand=XXXA
[0155] ro.product.device=shennong
[0156] ro.product.model=23116PN5BC
[0157] ro.product.manufacturer=XXXA
[0158] ro.product.name=shennong
[0159] After passing the test, hotfix is performed. It took about 4 hours from the start of analysis to reaching the user's machine. The user only needs to restart the emulator to enable the high - quality graphics mode of the game.
[0160] Next, the system property simulation device based on the Android emulator provided in this application will be described. The system property simulation device based on the Android emulator described below can be mutually referred to the system property simulation method based on the Android emulator described above.
[0161] Figure 4 It is a schematic structural diagram of the system property simulation device based on the Android emulator provided in one embodiment of this application. As Figure 4 shown, the system property simulation device 400 based on the Android emulator includes: an initialization module 401, a judgment module 402, a processing module 403, a clearing module 404, and a running module 405.
[0162] An initialization module, which is used to initialize the target system property file in the target property directory after the Android emulator is started;
[0163] A judgment module, which is used to start the target Android application on the Android emulator and judge whether the Android emulator needs to perform system property simulation based on the target system property file for the target Android application;
[0164] A processing module, which is used to, if so, mount the target property directory under a preset property directory, so that the target Android application reads system properties from the target system property file in the target property directory during the process of running the target Android application on the Android emulator;
[0165] A clearing module, which is used to clear the system property cache in the target cache space of the Android emulator;
[0166] A running module, which is used to run the target Android application on the Android emulator.
[0167] An optional implementation manner, the initialization of the target system property file in the target property directory includes:
[0168] Obtain a first property file from the Android device and write the first property file into the target system property file in the target property directory;
[0169] Wherein, the first property file is a property file associated with the Android device and the Android system running in the Android device.
[0170] An optional implementation manner, the target system property file contains an application package name; the judgment of whether the Android emulator needs to perform system property simulation based on the target system property file for the target Android application includes:
[0171] Judge whether the application package name contained in the target system property file matches the application package name of the target Android application;
[0172] If they match, it is determined that the Android emulator needs to perform system property simulation based on the target system property file.
[0173] An optional implementation manner, before mounting the target property directory under a preset property directory, the method further includes:
[0174] Perform a separation process on the memory space of the target system property file and the memory space corresponding to the preset system property file in the preset property directory.
[0175] An optional implementation manner, the method of clearing the system property cache in the target cache space of the Android emulator further includes:
[0176] Initialize the structure of the system properties in the target cache space.
[0177] An optional implementation manner, the method of clearing the system property cache in the target cache space of the Android emulator further includes:
[0178] Add a target global variable in the system property underlying access interface to indicate whether to refresh the system property cache, and share the target global variable to the control mechanism corresponding to the target cache space.
[0179] An optional implementation manner, the method further includes:
[0180] In response to an acquisition instruction for the original target system properties of the Android emulator, control to obtain the system property value corresponding to the target system properties through the thread local variable mechanism.
[0181] An optional implementation manner, the method further includes:
[0182] In response to receiving an update file for the system properties, update the target system property file based on the update file.
[0183] The system property simulation device based on the Android emulator provided in this embodiment can be used to execute the technical solutions of the above-mentioned embodiments of the system property simulation method based on the Android emulator. The implementation principle and technical effects are similar, and will not be elaborated here.
[0184] Figure 5 The hardware structure schematic diagram of the electronic device provided in one embodiment of the present application is as Figure 5 shown. The electronic device 500 in this embodiment includes: a processor 501 and a memory 502; wherein
[0185] The memory 502 is used to store computer execution instructions;
[0186] The processor 501 is used to execute the computer execution instructions stored in the memory to implement each step executed by the system property simulation method based on the Android emulator in the above embodiments. For details, please refer to the relevant descriptions in the foregoing method embodiments.
[0187] Optionally, the memory 502 can be either independent or integrated with the processor 501.
[0188] When the memory 502 is independently provided, the electronic device further includes a bus 503 for connecting the memory 502 and the processor 501.
[0189] One embodiment of the present application further provides a computer-readable storage medium. Computer-executable instructions are stored in the computer-readable storage medium. When the processor executes the computer-executable instructions, the technical solutions corresponding to the system property simulation method based on the Android emulator in any of the above embodiments executed by the above electronic device are implemented.
[0190] One embodiment of the present application further provides a computer program product. The program product includes: a computer program. The computer program is stored in a readable storage medium. At least one processor of the electronic device can read the computer program from the readable storage medium. Executing the computer program by at least one processor causes the electronic device to execute the technical solutions corresponding to the system property simulation method based on the Android emulator in any of the above embodiments.
[0191] Although the present application is disclosed above in preferred embodiments, it is not intended to limit the present application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the protection scope of the present application should be determined by the scope defined by the claims of the present application.
[0192] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be other division methods. For example, multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of the device or module can be in an electrical, mechanical or other form.
[0193] The integrated modules implemented in the form of software function modules as described above can be stored in a computer-readable storage medium. The above software function modules are stored in a storage medium and include several instructions for causing an electronic device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to execute some steps of the methods described in various embodiments of the present application.
[0194] It should be understood that the above-mentioned processor may be a Central Processing Unit (CPU), or may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in combination with the invention can be directly embodied as being completed by the execution of a hardware processor, or can be completed by a combination of hardware and software modules in the processor.
[0195] The memory may include high-speed RAM memory, and may also include non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk, or an optical disc, etc. The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience in representation, the bus in the drawings of this application is not limited to only one bus or one type of bus.
[0196] The above-mentioned storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disc. The storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0197] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the above-mentioned method embodiments; and the foregoing storage medium includes: various media such as ROM, RAM, magnetic disks, or optical discs that can store program codes.
[0198] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than limiting them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A system property simulation method based on an Android emulator, characterized in that The method includes: After the Android emulator is started, initialize the target system property file in the target property directory; Start the target Android application on the Android emulator, and determine whether the Android emulator needs to perform system property simulation based on the target system property file for the target Android application; If so, mount the target property directory under the preset property directory, so that the target Android application reads system properties from the target system property file in the target property directory during the running of the target Android application on the Android emulator; Clear the system property cache in the target cache space in the Android emulator; Run the target Android application on the Android emulator.
2. The method according to claim 1, wherein The initialization of the target system property file in the target property directory includes: Obtain a first property file from the Android device, and write the first property file into the target system property file in the target property directory; Wherein, the first property file is a property file associated with the Android device and the Android system running in the Android device.
3. The method according to claim 1, wherein The target system property file contains the application package name; The determination of whether the Android emulator needs to perform system property simulation based on the target system property file for the target Android application includes: Determine whether the application package name contained in the target system property file matches the application package name of the target Android application; If they match, it is determined that the Android emulator needs to perform system property simulation based on the target system property file.
4. The method according to claim 1, wherein Before mounting the target property directory under the preset property directory, the method further includes: Perform a separation process on the memory space of the target system property file and the memory space corresponding to the preset system property file under the preset property directory.
5. The method according to claim 1, wherein For the clearing of the system property cache in the target cache space in the Android emulator, the method further includes: Initialize the structure of the system properties in the target cache space.
6. The method according to claim 1, characterized in that, For the clearing of the system property cache in the target cache space in the Android emulator, the method further includes: Add a target global variable for indicating whether to refresh the system property cache in the system property underlying access interface, and share the target global variable to the control mechanism corresponding to the target cache space.
7. The method according to claim 1, characterized in that, The method further includes: In response to an acquisition instruction for the original target system properties of the Android emulator, control to obtain the system property value corresponding to the target system properties through the thread local variable mechanism.
8. The method according to claim 1, characterized in that, The method further includes: In response to receiving an update file for the system properties, update the target system property file based on the update file.
9. A system property simulation device based on an Android emulator, characterized in that, The device includes: An initialization module, used to initialize the target system property file in the target property directory after the Android emulator is started; A judgment module, used to start the target Android application on the Android emulator and judge whether the Android emulator needs to perform system property simulation based on the target system property file for the target Android application; A processing module, configured to, if so, mount the target attribute directory under a preset attribute directory, so that during the process of running the target Android application in the Android emulator, the target Android application reads system attributes from a target system attribute file under the target attribute directory; A clearing module, configured to clear the system attribute cache in a target cache space in the Android emulator; A running module, configured to run the target Android application on the Android emulator.
10. An electronic device, characterized in that, The electronic device includes: A processor; and A memory, configured to store a data processing program, after the electronic device is powered on and runs the program through the processor, execute the Android emulator-based system attribute simulation method according to any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, A data processing program is stored, and the program is run by a processor to execute the Android emulator-based system attribute simulation method according to any one of claims 1-8.