Method and device for exception handling of Android platform

An exception handling and platform technology, applied in the field of exception handling, can solve the problems of not supporting direct printing of call stack information, unable to obtain C++ layer exception information, unable to collect C++ layer exception information, etc., so as to achieve unified processing and improve processing. performance effect

Active Publication Date: 2014-11-19
QINGDAO HISENSE MOBILE COMM TECH CO LTD
4 Cites 28 Cited by

AI-Extracted Technical Summary

Problems solved by technology

[0004] In the specific implementation, the Android platform generally includes the JAVA layer and the C++ layer. During the running of the program, if an exception occurs in the JAVA layer, the JAVA layer can directly print the call stack information according to the exception, thereby obtaining the JAVA layer based on the call stack information. Layer exception...
View more

Method used

Apply the embodiment of the present invention, when Android platform detects abnormal data in C ++ layer, the abnormal data of C ++ layer is converted into the abnormal data of JAVA layer, and the abnormal data of JAVA layer after collecting conversion is uploaded to server. The embodiment of the present invention converts the abnormal data of the C++ layer into the abnormal data of the JAVA layer, and submits it to the JAVA layer for unified collection, so no matter whether an exception occurs in the JAVA layer or an exception occurs in the C++ layer, the JAVA layer can receive and capture the abnormal data , realize the unified processing of abnormal data collection, and improve the processing performance of the Android platform....
View more

Abstract

The embodiment of the invention provides a method and device for exception handling of an Android platform. The Android platform comprises a JAVA layer and a C++ layer. The method comprises the steps that in the operation process of a certain program on the JAVA layer, when abnormal data of the C++ layer are detected, the abnormal data of the C++ layer are converted into abnormal data of the JAVA layer; the converted abnormal data of the JAVA layer are collected; the abnormal data of the JAVA layer are stored in the Android platform; operation of the program is ended. According to the method and device for exception handling of the Android platform, when it is detected that the C++ layer is abnormal on the Android platform, the abnormal data of the C++ layer are converted into the abnormal data of the JAVA layer, and then the abnormal data of the JAVA layer are collected.

Application Domain

Fault responseSpecific program execution arrangements

Technology Topic

Computer hardwareException handling

Image

  • Method and device for exception handling of Android platform
  • Method and device for exception handling of Android platform
  • Method and device for exception handling of Android platform

Examples

  • Experimental program(3)

Example Embodiment

[0059] Example one:
[0060] Reference figure 1 , Shows a step flow chart of the first embodiment of an exception handling method for the Android Android platform of the present invention. The Android Android platform may include a JAVA layer and a C++ layer, and specifically may include the following steps:
[0061] Step 101: During the running process of a program in the JAVA layer, when abnormal data in the C++ layer is detected, convert the abnormal data in the C++ layer into abnormal data in the JAVA layer;
[0062] In a specific implementation, the platform on which the Android system is installed may be a mobile phone, a computer, and other devices.
[0063] In the Android platform, it can be divided into the JAVA layer of the application written in JAVA code, such as the Framework layer, and the C++ layer of the virtual machine written in C++ code, such as the Native layer. The operation of the application program written by JAVA depends on the JAVA virtual machine. The JAVA virtual machine can facilitate the operation of JAVA application programs on different systems and models of machines. For efficiency reasons, the JAVA virtual machine is generally written in C++ language. Of course, it can also be written in C language or other languages, which is not limited in the embodiment of the present invention.
[0064] At present, based on the implementation principle of exception capture at the JAVA layer, a complete exception capture function is integrated on the Android platform. Through the implementation principle of exception capture at the JAVA layer, abnormal data can be acquired when the program is running.
[0065] It should be noted that the C++ layer cannot directly obtain abnormal data information. Therefore, in the embodiment of the present invention, the abnormal data of the C++ layer can be converted into the abnormal data of the JAVA layer, and then the abnormal data can be obtained by the JAVA layer.
[0066] Step 102: Collect abnormal data of the converted JAVA layer;
[0067] In the embodiment of the present invention, the abnormal data of the JAVA layer after conversion from the abnormal data of the C++ layer is collected in the JAVA layer.
[0068] Step 103: Save the abnormal data of the JAVA layer in the Android platform;
[0069] In a preferred embodiment of the present invention, the step 103 may include the following sub-steps:
[0070] Sub-step S11, obtaining the program name and current time of the program running on the Android platform;
[0071] Sub-step S12, saving the abnormal information in a file named by the program name and the current time;
[0072] In sub-step S13, the file is compressed.
[0073] In a specific implementation, the acquired abnormal information is stored in the program name of the current program and the file named at the current time. At the same time, the file can be compressed so as to be saved in the local Android platform.
[0074] Of course, in actual applications, other rules may also be used to save the abnormal information, which is not limited in the embodiment of the present invention.
[0075] In a preferred embodiment of the present invention, the method may further include the following steps:
[0076] Step S21, query whether to upload the abnormal data of the JAVA layer to the abnormal information file server; if so, perform sub-step S42;
[0077] Step S22, upload the abnormal data of the JAVA layer to the abnormal information file server.
[0078] In the embodiment of the present invention, after the abnormal data is collected, the user may be prompted whether to upload the abnormal information to the server. If the user agrees to upload, the abnormal data is uploaded to the abnormal information file server for the developer to analyze. In specific implementation, the parameter information of the terminal with abnormal data, such as the terminal model, version number, system information, etc., can also be uploaded to the server together.
[0079] Of course, in a specific implementation, the collected abnormal data can also be uploaded to the server, or the collected abnormal data can be uploaded at intervals, which is not limited in the embodiment of the present invention.
[0080] Step 104: Stop the running of the program.
[0081] When the program is abnormal, the running of the program can be suspended. If the user needs to run the program again, the program can be refreshed to restart. Or, when the program is abnormal, you can directly exit the program and a dialog box will pop up to prompt the user to exit the program.
[0082] In the specific implementation, the C++ layer cannot directly obtain the abnormal data information. At present, the Android platform integrates the perfect JAVA layer exception capture function. Through the realization principle of the JAVA layer exception capture, the JAVA layer abnormal data can be detected when the program is running. Of access. Therefore, in the embodiment of the present invention, the abnormal data of the C++ layer can be converted into the abnormal data of the JAVA layer, and then the abnormal data can be obtained directly through the exception, so as to realize the unified processing of the abnormal data of the JAVA layer and the abnormal data of the C++ layer. , Improve the system processing performance of the Android platform.

Example Embodiment

[0083] Embodiment two:
[0084] Reference figure 2 , Shows a step flow chart of the second embodiment of an exception handling method for the Android Android platform of the present invention. The Android Android platform may include a JAVA layer and a C++ layer, and specifically may include the following steps:
[0085] Step 201: During the operation of a program in the JAVA layer, when abnormal data in the C++ layer is detected, convert the abnormal data in the C++ layer into abnormal data in the JAVA layer;
[0086] In a preferred embodiment of the present invention, an exception handling function corresponding to the abnormal data of the C++ layer may be registered in the Android platform; the step 201 may include the following sub-steps:
[0087] Sub-step S31, calling a preset query or setting signal processing function sigaction to obtain the abnormal data of the C++ layer;
[0088] Sub-step S32, using the exception handling function to call the JAVA local interface JNI;
[0089] Sub-step S33, using the exception handling function to call a preset JAVA layer signal capture function through the JAVA local interface JNI; the preset JAVA layer signal capture function can be used to generate JAVA layer exception data.
[0090] In the embodiment of the present invention, for the abnormal data of the C++ layer that may occur during the running of the program, a corresponding exception handling function is registered on the Android platform.
[0091] When an exception occurs in the C++ layer, obtain the exception handling function registered in the Android platform for the exception of the C++ layer, and use the exception handling function to call the JNI (Java Native Interface) of the JAVA layer and call the signal capture function of the JAVA layer , Convert the C++ layer to the abnormal data of the JAVA layer.
[0092] In the embodiment of the present invention, the LINUX signal mechanism is used to acquire and transmit abnormal data. In the LINUX signal mechanism, the signal is used to notify the program that an asynchronous event has occurred. It should be noted that the signal is used to notify a program of what event has occurred, and does not need to pass any data to the program. The program that receives the signal can have different processing methods for various signals. In the embodiment of the present invention, for the signal that needs to be processed, the program can specify a processing function, and the function is used for processing.
[0093] Specifically, first send the abnormal data captured in the C++ layer to the current program by querying or setting the signal processing sigaction() function. The program finds the corresponding exception handling function according to the abnormal data in the C++ layer, and uses the exception handling function Call the preset JAVA layer signal capture function through the JAVA local interface JNI, and run the abnormal data of the C++ layer to generate the abnormal data of the JAVA layer.
[0094] It should be noted that in the embodiment of the present invention, the abnormal data of the C++ layer can be converted into the abnormal data of the JAVA layer in other ways, and the embodiment of the present invention does not limit this.
[0095] Step 202: Collect abnormal data of the converted JAVA layer;
[0096] In a preferred embodiment of the present invention, the step 202 may include the following sub-steps:
[0097] Sub-step S41, calling a preset uncaught exception handling function UncaughtExceptionHandler to obtain the call stack information; the call stack information includes the abnormal function call relationship of the JAVA layer;
[0098] Sub-step S42, extracting abnormal data corresponding to the function call relationship from the log LOG information.
[0099] In a specific implementation, the log LOG information in the Android platform stores the function call relationship when the program is running. The call stack information can record the function call relationship of the program in operation (also called the function execution sequence). Each program thread has its own call stack information. The call stack information records the program running sequence and also records when the program is abnormal. Therefore, in the embodiment of the present invention, the call stack information can be obtained to obtain the corresponding abnormal function call relationship from the log LOG information in the Android platform.
[0100] The call stack information plays an important role in the program. Usually when debugging a program, you need to view the call stack information of the current function. The call stack information is a function call chain that reflects the function call relationship. For example, function f1 calls function f2, function f2 calls function f3, then f1→f2→f3 is one Call stack information. Specifically, there may be multiple call situations between one function and another function. For example, the call stack of function f1 to function f3 can be f1→f2→f3, or f1→f4→f5→f3. Therefore, when When the program is abnormal, detects an error, or is interrupted by a breakpoint, you can view the current call stack information of the current program.
[0101] In the embodiment of the present invention, after the abnormal data of the C++ layer is converted into the abnormal data of the JAVA layer, the uncaught exception handling function UncaughtExceptionHandler of the JAVA layer is called to obtain the call stack information, and the abnormal data of the JAVA layer in the call stack information is called The function call relationship obtains the corresponding abnormal data from the log information.
[0102] It should be noted that, in the embodiment of the present invention, the abnormal data of the JAVA layer can also be obtained in other ways, which is not limited in the embodiment of the present invention.
[0103] Step 203: If abnormal data of the JAVA layer is detected, call a preset uncaught exception handling function UncaughtExceptionHandler to obtain call stack information; the call stack information includes the abnormal function call relationship of the JAVA layer;
[0104] In the JAVA layer, the application program is written. The application program in the conceptual space provided by Android Android to developers is a loosely represented concept, and there is not much substantial representation. In the actual space of Android, you can't see the concept of application in the actual sense. Although there is an application class, it refers to the context state of the application, which is an extremely weak concept. Set the exception handling class as the default exception handling handle in the onCreate() function of the application application.
[0105] Specifically, the exception handling class is written in the JAVA layer to implement the public void uncaughtException(Thread thread, Throwable exception) of the uncaught exception handling function UncaughtExceptionHandler in the onCreate() function, and print the exception data in the uncaughtException handling function uncaughtException The call stack information is stored locally.
[0106] Step 204: Extract abnormal data corresponding to the function call relationship from the log LOG information.
[0107] When the application is running abnormal data in the JAVA layer, it will trigger the default exception handling class uncaughtException function, this function can achieve abnormal data printing and storage functions.
[0108] Step 205: Save the abnormal data of the JAVA layer in the Android platform;
[0109] Step 206: Stop the running of the program.
[0110] By applying the embodiments of the present invention, when abnormal data occurs in the C++ layer of the Android Android platform, the LINUX signal mechanism can be used to convert the abnormal data of the C++ layer into the abnormal data of the JAVA layer by using the LINUX signal mechanism and the Java local interface JNI of the Android platform, so that C++ can be printed. The call stack information of the abnormal data of the layer, and then print out the abnormal information in the log information, unify the abnormal data collection and processing of the C++ layer and the JAVA layer, and improve the system processing performance of the Android platform.
[0111] It should be noted that the embodiments of the present invention can not only capture exceptions for JAVA applications in the terminal, but also can be applied in other occasions where the C++ layer and the JAVA layer are combined.
[0112] In order to enable those skilled in the art to further understand the embodiments of the present invention, specific examples are used for description below.
[0113] Reference image 3 The illustrated schematic diagram of the process of capturing and collecting exceptions on the Android platform of the present invention may specifically include the following steps:
[0114] 1. Detect abnormal data in the JAVA layer;
[0115] 2. Detect abnormal data in the C++ layer;
[0116] 3. Obtain, according to the abnormal data of the C++ layer, the exception handling function registered in the Android exception of the Android, and the abnormal data corresponding to the C++ layer;
[0117] 4. Call the JAVA local interface JNI with the exception handling function;
[0118] 5. The abnormal handling data function uses the JAVA local interface JNI to call the JAVA layer signal capture function;
[0119] 6. The JAVA layer signal capture function runs according to the abnormality of the C++ layer and converts it into the abnormal data of the JAVA layer;
[0120] 7. Call the exception handling function of the JAVA layer;
[0121] 8. Use the exception handling function of the JAVA layer to print the abnormal call stack information of the JAVA layer;
[0122] 9. Print log LOG information according to the abnormal call stack information;
[0123] 10. Read the log LOG information to obtain the abnormal data of the JAVA layer and C++ layer, and store it in the corresponding file for compression processing;
[0124] 11. Ask whether to upload abnormal information to the abnormal information file server; if yes, go to step 12; if not, go to step 13;
[0125] 12. Upload abnormal data to the abnormal information file server;
[0126] 13. Exit the program.
[0127] In the embodiment of the present invention, the principles of abnormal capture and collection of the Android Andorid platform are summarized as follows:
[0128] 1. Abnormal data capture for JAVA layer;
[0129] 1. Write the exception handling class in the JAVA layer to implement the public void uncaughtException(Thread thread, Throwable exception) function of the UncaughtExceptionHandler, print the abnormal call stack information in the uncaughtException function and store it locally, and kill the exception. Application of data. Set the exception handling class as the default exception handling handle in the onCreate() function of the application application.
[0130] 2. When abnormal data occurs in the JAVA layer during the running of the application, the uncaughtException function of the default exception handling class will be triggered, which implements the printing and storage of abnormal data.
[0131] 2. Abnormal data capture for C++ layer;
[0132] 1. Using the LINUX signal mechanism, first use the LINUX mechanism to query or set the signal processing function sigaction() function, and specify the abnormal signal that needs to be captured to set the exception processing function for the abnormal data. Mainly complete the registration process of the corresponding processing of abnormal data.
[0133] 2. In practice, because JAVA syntax can directly obtain call stack information through exception data, that is, the JAVA layer can directly obtain call stack information through exception data, but the C++ layer does not support direct printing of call stack information.
[0134] 3. Use JAVA local interface JNI call to solve the problem that the C++ layer does not support direct printing of the call stack information. When abnormal data occurs in the C++ layer, the LINUX signal mechanism will send a signal to the current process. If the signal is registered in step 1, , It will call the registered exception handling function, the local interface JNI is used in the exception handling function, the JAVA layer signal capture function is called through the exception code of the C++ layer, the JAVA layer signal capture processing function, and the runtime exception is generated, which is provided to the JAVA layer exception capture use.
[0135] 4. The C++ layer abnormal data capture uses the LINUX signal mechanism and the JNI of the Android platform to convert the C++ abnormal data into the JAVA layer abnormal data, thereby unifying the collection and processing of the C++ and JAVA layer abnormal data.
[0136] 3. Abnormal collection;
[0137] 1. First, print the call stack information of the calling JAVA layer. This call stack information includes the abnormal data of the JAVA layer and the abnormal data of the JAVA layer converted from the abnormal data of the C++ layer; secondly, print the abnormal data in the log information of the system. Function call relationship; finally, read the log LOG information of the Android platform, store the log LOG information in a file named according to the program name + time, and compress it.
[0138] 2. Ask the user whether he agrees to upload the file storing the abnormal data to the designated server. When the user agrees to upload to the designated server, upload the file of the abnormal data.
[0139] Applying the embodiment of the present invention, when the Android platform detects abnormal data in the C++ layer, the abnormal data in the C++ layer is converted into the abnormal data in the JAVA layer, and the converted abnormal data in the JAVA layer is collected and uploaded to the server. The embodiment of the present invention converts the abnormal data of the C++ layer into the abnormal data of the JAVA layer and submits it to the JAVA layer for unified collection. Therefore, the JAVA layer can receive and capture the abnormal data regardless of the abnormality of the JAVA layer or the C++ layer. , Realize the unified processing of abnormal data collection, and improve the processing performance of the Android platform.
[0140] It should be noted that, for the sake of simple description, the method embodiments are all expressed as a series of action combinations, but those skilled in the art should know that the embodiments of the present invention are not limited by the described sequence of actions, because According to the embodiments of the present invention, certain steps may be performed in other order or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

Example Embodiment

[0141] Embodiment three:
[0142] Reference Figure 4 , Shows a structural block diagram of an embodiment of the device for handling exceptions on the Android Android platform of the present invention. The Android Android platform may include a JAVA layer and a C++ layer, and specifically may include the following modules:
[0143] The conversion module 401 is configured to convert the abnormal data of the C++ layer into the abnormal data of the JAVA layer when abnormal data of the C++ layer is detected during the running process of a certain program in the JAVA layer;
[0144] In a preferred embodiment of the present invention, various exception handling functions corresponding to various abnormal data in the C++ layer can be registered in the Android platform; the conversion module 401 can include the following submodules:
[0145] The function calling unit is used to call the preset query or set signal processing function sigaction to obtain the abnormal data of the C++ layer;
[0146] A function obtaining unit, configured to obtain the corresponding abnormal handling function by using the abnormal data;
[0147] The interface calling sub-module is used to call the JAVA local interface JNI by using the exception handling function;
[0148] The exception generation sub-module is used to use the exception handling function to call a preset JAVA layer signal capture function through the JAVA local interface JNI; the preset JAVA layer signal capture function is used to generate JAVA based on the C++ layer abnormal data The abnormal data of the layer.
[0149] The collection module 402 is used to collect the abnormal information of the converted JAVA layer;
[0150] In a preferred embodiment of the present invention, the collection module 402 may include the following sub-modules:
[0151] The call stack information acquisition sub-module is used to call the preset uncaught exception handling function UncaughtExceptionHandler to acquire the call stack information; the call stack information includes the function call relationship of the exception of the JAVA layer;
[0152] The first abnormal information acquisition sub-module is configured to extract abnormal data corresponding to the function call relationship from the log LOG information.
[0153] The saving module 403 is used to save the abnormal data of the JAVA layer in the Android platform;
[0154] In a preferred embodiment of the present invention, the storage module 403 may include the following sub-modules:
[0155] The program name obtaining submodule is used to obtain the program name and current time of the program running on the Android platform;
[0156] The exception information is stored in a sub-module for saving the exception information in a file named by the program name and the current time;
[0157] The file compression sub-module is used to compress the file.
[0158] In a preferred embodiment of the present invention, the device may further include the following modules:
[0159] The JAVA layer detection module is used to call the preset uncaught exception handling function UncaughtExceptionHandler to obtain call stack information when the abnormal data of the JAVA layer is detected; the call stack information includes the abnormal function call relationship of the JAVA layer;
[0160] The second abnormal information acquisition module is used to extract abnormal data corresponding to the function call relationship from the log LOG information.
[0161] In a preferred embodiment of the present invention, the device may further include the following modules:
[0162] The query submodule is used to query whether to upload the file to the preset server; if so, call the upload submodule;
[0163] The upload sub-module is used to upload the file to the preset server.
[0164] The suspension module 405 is used to suspend the running of the program.

PUM

no PUM

Description & Claims & Application Information

We can also present the details of the Description, Claims and Application information to help users get a comprehensive understanding of the technical details of the patent, such as background art, summary of invention, brief description of drawings, description of embodiments, and other original content. On the other hand, users can also determine the specific scope of protection of the technology through the list of claims; as well as understand the changes in the life cycle of the technology with the presentation of the patent timeline. Login to view more.

Similar technology patents

Roller cover

Owner:OERLIKON SOLAR AG (TRUEBBACH)

Data exception processing method and device, electronic equipment and storage medium

PendingCN114546691Aachieve unified processingsimplify complexity
Owner:BEIJING QIANXIN TECH +1

Classification and recommendation of technical efficacy words

Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products