Method, device, computer device and storage medium for copying and pasting clipboard content

By customizing the HookClipboardManager service and HookActivity, the system's clipboard service method is rewritten, and the inheritance relationship of the Activity is modified through bytecode editing, which solves the problem of cumbersome cutting board operation and the inability to modify third-party SDK controls in the existing technology, and realizes a safe and simplified copy-paste function of cutting board content.

CN115202905BActive Publication Date: 2025-06-24PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210904421.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-29
Publication Date
2025-06-24
Estimated Expiration
2042-07-29

AI Technical Summary

Technical Problem

In the prior art, when copying and pasting clipboard contents, there are problems with cumbersome operations and inability to modify the controls and model compatibility in integrated third-party SDKs.

Method used

By customizing the HookClipboardManager service and HookActivity, the system clipboard service method is rewritten to store and obtain content, avoid copying to the system clipboard, and change all classes inherited from the system Activity to inherit from the HookActivity through bytecode editing.

Benefits of technology

It realizes copying and pasting content without copying to the system clipboard, ensuring the security of in-app data, simplifying operations, and solving the compatibility issues of third-party SDKs and models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115202905B_ABST
    Figure CN115202905B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, computer device and storage medium for copying and pasting clipboard content. The method includes: customizing a HookClipboardManager service that inherits from the system clipboard service, creating a HookActivity that inherits from the system Acitivity, and changing all classes that inherit from the system Activity to inherit from the HookActivity; during the program running stage, automatically obtaining the HookClipboardManager service of the HookActivity, calling the HookClipboardManager service to save the copied content of the current application in the application memory, and pasting the copied content in the application memory to the current page. The present invention can ensure the data security within the application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information security technology, and particularly to a method, device, computer device and storage medium for copying and pasting clipboard content. Background Art

[0002] Currently, the content in enterprise WeChat or DingTalk and other APPs (abbreviation of Application) can be copied and pasted onto the system clipboard, and other APPs can paste the content in the clipboard into their applications. For example, for Android applications, each page corresponds to a system android.app.Activity class (hereinafter referred to as Activity). In the page, if you want to copy a piece of text, you can obtain the ClipboardManager (system clipboard service) by calling the getSystemService method of Activity (getSystemService is an API (Application Program Interface) of Android, which obtains the corresponding Object according to the incoming NAME and then converts it into the corresponding service object). Since ClipboardManager is at the system level, the copied content can also be obtained by external APPs.

[0003] For applications with relatively high security requirements, this copy and paste behavior is prohibited. Therefore, a clipboard capability with the following functions needs to be implemented:

[0004] 1. The content copied by this application cannot be pasted into other applications;

[0005] 2. The content copied by this application can be pasted into this application;

[0006] 3. The content copied by external applications can be pasted into this application.

[0007] In order to implement the above clipboard function, the existing technology is to change all the controls with text copy functions in the system one by one into self-implemented controls, and then intercept the long-press menu bar of the corresponding controls, and change the copy function in the menu from copying to the system clipboard to copying to this application. The defects of this solution include:

[0008] 1. All relevant controls in the existing project need to be replaced with new custom controls. Each time new development is added, it is also necessary to pay attention to replacing the use of custom controls to display text, and the operation is relatively cumbersome;

[0009] 2. Only the controls in the source code can be modified, and the controls in the integrated third-party SDK cannot be modified;

[0010] 3. There are compatibility issues with the menu customization of the control for different models and need to be adapted. Summary of the Invention

[0011] The present invention provides a method, device, computer device and storage medium for copying and pasting clipboard content, aiming to solve the technical problems existing in the existing methods of copying and pasting clipboard content, such as cumbersome operations, inability to modify the controls in the integrated third-party SDK, and compatibility with different models.

[0012] To solve the above technical problems, the technical solution adopted by the present invention is as follows:

[0013] A method for copying and pasting clipboard content includes:

[0014] In the coding stage of the program, customize a HookClipboardManager service that inherits from the system clipboard service ClipboardManager, and override the setPrimaryClip method and getPrimaryClip method in the HookClipboardManager service to save the content originally copied to the system clipboard in the application memory; where setPrimaryClip is used to copy clipboard content and getPrimaryClip is used to obtain clipboard content.

[0015] Create a HookActivity that inherits from the system Acitivity, and override the getSystemService method of the HookActivity to change the acquisition of ClipboardManager to HookClipboardManager.

[0016] In the compilation stage of the program, use the transform task to find all classes that inherit from the system Activity, and change all classes that inherit from the system Activity to classes that inherit from HookActivity.

[0017] In the running stage of the program, automatically obtain the HookClipboardManager service of the HookActivity, call the setPrimaryClip method in the HookClipboardManager service to save the copied content of the current application in the application memory, and call the getPrimaryClip method to paste the copied content in the application memory to the current page.

[0018] The technical solution adopted in the embodiments of the present invention further includes: The customizing a HookClipboardManager service that inherits from the system clipboard service ClipboardManager further includes:

[0019] Add the getSystemPrimaryClip method to the HookClipboardManager. The getSystemPrimaryClip method is used to call the original system method to obtain the content of the system clipboard.

[0020] The technical solution adopted in the embodiment of the present invention further includes: creating a HookActivity that inherits from the system Acitivity, and specifically overriding the getSystemService method of the HookActivity as follows:

[0021] In the HookAcitivity, define a getSystemService method with the same name as android.app.Acitvity. The input parameter of the getSystemService method is the system service name;

[0022] When using the getSystemService method to obtain the ClipboardManager service, determine whether the input system service name is the clipboard service. If it is, return the HookClipboardManager service; if the input system service name is other services except the clipboard service, normally call the getSystemService method of the parent class.

[0023] The technical solution adopted in the embodiment of the present invention further includes: specifically changing all classes that inherit from the system Activity to inherit from the HookActivity as follows:

[0024] Use the transform task to find all classes that inherit from the system Activity, and perform bytecode editing on all classes that inherit from the system Activity to change them to inherit from the HookActivity. Among them, the bytecode editing of all classes that inherit from the system Activity includes:

[0025] When compiling a program installation package, use the gradle plugin for building, execute the javac command on the Java source file to obtain the compiled bytecode file;

[0026] Register a transform task in the gradle plugin. In the transform task, obtain the input bytecode file through the passed-in TransformOutputProvider parameter;

[0027] Using the Javassit framework, perform bytecode editing processing on the bytecode file according to a predetermined rule to obtain a processed bytecode file, output the processed bytecode file to a gradle build task, and merge the output bytecode files to obtain a merged dex file;

[0028] Package the dex file with related resources to generate an application installation package.

[0029] The technical solution adopted in the embodiment of the present invention further includes: the specific implementation of saving the copied content of the current application in the application memory by calling the setPrimaryClip method in the HookClipboardManager service and pasting the copied content in the application memory to the current page by calling the getPrimaryClip method is as follows:

[0030] When the user performs a copy operation on any page within the current application, automatically obtain the HookClipboradManager service by using the getSystemService method of HookActivity, and call the setPrimaryClip method to save the copied content of the current application in the application memory;

[0031] When the user performs a paste operation on any page within the current application, automatically call the getSystemService method of HookAcitvity to obtain the HookClipboradManager service, and call the getPrimaryClip method to paste the copied content in the application memory to the current page.

[0032] The technical solution adopted in the embodiment of the present invention further includes: the above-mentioned saving the copied content of the current application in the application memory by calling the setPrimaryClip method in the HookClipboardManager service and pasting the copied content in the application memory to the current page further includes:

[0033] Call the system's registerActivityLifecycleCallbacks method to monitor the page state of the current application, and judge whether the current application has switched from the background to the foreground according to the page state. If so,

[0034] Call the getSystemPrimaryClip method of the HookClipboardManager service to obtain the content of the system clipboard, and call the setPrimaryClip method to synchronize the obtained clipboard content to the HookClipboardManager within the current application, so that the clipboard content of external applications can be copied and pasted into the current application.

[0035] The technical solution adopted in the embodiment of the present invention further includes: The specific method of calling the registerActivityLifecycleCallbacks method of the system to monitor the page state of the current application is as follows:

[0036] Call the registerActivityLifecycleCallbacks method provided by the system to monitor the status callbacks of all pages;

[0037] Create a counter variable count. When the system calls back onActivityStart, the counter is incremented by 1. When the system calls back onActivityStop, the counter is decremented by 1;

[0038] When the system calls back onActivityStop, if the counter is 0, it means that the page of the current application is in an invisible state, and the current application has entered the background; when the system calls back onActivityStart, if the counter is 1, it means that the page within the current application is in a visible state, and the current application has switched from the background to the foreground.

[0039] Another technical solution adopted in the embodiment of the present invention is: A clipboard content copy and paste device, including:

[0040] Program coding module: Used to customize a HookClipboardManager service that inherits from the system clipboard service ClipboardManager during the coding stage of the program, and override the setPrimaryClip method and getPrimaryClip method in the HookClipboardManager service to change the content originally copied to the system clipboard to be stored in the application memory; where setPrimaryClip is used to copy the clipboard content, and getPrimaryClip is used to obtain the clipboard content;

[0041] Class creation module: Used to create a HookActivity that inherits from the system Acitivity, and override the getSystemService method of HookActivity to change the acquisition of ClipboardManager to HookClipboardManager;

[0042] Bytecode compilation module: used to find all classes that inherit from the system Activity during the compilation stage of the program, and change all classes that inherit from the system Activity to classes that inherit from HookActivity;

[0043] Copy and paste module: used to automatically obtain the HookClipboardManager service of HookActivity during the running stage of the program, call the setPrimaryClip method in the HookClipboardManager service to save the copied content of the current application in the application memory, and call the getPrimaryClip method to paste the copied content in the application memory to the current page.

[0044] Another technical solution adopted by the embodiments of the present invention is: a computer device, the computer device includes:

[0045] A memory storing executable program instructions;

[0046] A processor connected to the memory;

[0047] The processor calls the executable program instructions stored in the memory to execute the clipboard content copy and paste method as described above.

[0048] Another technical solution adopted by the embodiments of the present invention is: a storage medium storing program instructions executable by a processor, and the program instructions are used to execute the above-mentioned clipboard content copy and paste method.

[0049] In the clipboard content copy and paste method, device, computer device and storage medium of the embodiments of the present invention, the system Activity in the program is changed to a custom HookClipboradManager object, bytecode editing is performed on all classes that inherit from the system Activity, and they are changed to classes that inherit from HookActivity. The HookClipboradManager object is not a system object. Therefore, the content in the application will not be copied to the system clipboard but saved in the application memory, so that the copied content in the application memory can only be pasted on any page within the application, thus ensuring the data security within the application. When performing bytecode editing, the present invention will automatically process all codes, without caring about the logic of historical codes or newly added codes, and the controls in the third-party SDK can also be modified to take effect. There is no model compatibility problem and no need for adaptation. While ensuring the data security within the application, the operation is simpler. Description of the Drawings

[0050] Figure 1It is a schematic flowchart of the clipboard content copy and paste method according to the first embodiment of the present invention;

[0051] Figure 2 It is a schematic flowchart of the clipboard content copy and paste method according to the second embodiment of the present invention;

[0052] Figure 3 It is a schematic diagram of the section code editing process according to the embodiment of the present invention;

[0053] Figure 4 It is a schematic flowchart of the clipboard content copy and paste method according to the third embodiment of the present invention;

[0054] Figure 5 It is a schematic structural diagram of the clipboard content copy and paste device according to the embodiment of the present invention;

[0055] Figure 6 It is a schematic structural diagram of the computer device according to the embodiment of the present invention;

[0056] Figure 7 It is a schematic structural diagram of the storage medium according to the embodiment of the present invention. Detailed Embodiments

[0057] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0058] The terms "first", "second", and "third" in the present invention are only used for descriptive purposes, and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first", "second", and "third" may explicitly or implicitly include at least one of such features. In the description of the present invention, the meaning of "a plurality" is at least two, such as two, three, etc., unless otherwise specifically defined. All directional indications (such as up, down, left, right, front, back...) in the embodiments of the present invention are only used to explain the relative positional relationship and movement conditions between components in a specific posture (as shown in the drawings). If the specific posture changes, the directional indications will also change accordingly. In addition, 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 is not limited to the listed steps or units, but may optionally further include steps or units not listed, or may optionally further include other steps or units inherent to these processes, methods, products, or devices.

[0059] References to "embodiments" in this specification mean that a particular feature, structure, or characteristic described in connection with the embodiments can be included in at least one embodiment of the invention. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0060] Please refer to Figure 1 , which is a schematic flowchart of the clipboard content copy and paste method according to the first embodiment of the present invention. The clipboard content copy and paste method according to the first embodiment of the present invention includes the following steps:

[0061] S100: In the coding stage of the program, customize a HookClipboardManager service that inherits from the system clipboard service ClipboardManager, and override the setPrimaryClip method and getPrimaryClip method in the HookClipboardManager service to change the content originally copied to the system clipboard to be stored in the application memory; where setPrimaryClip is for copying clipboard content and getPrimaryClip is for obtaining clipboard content;

[0062] S110: Create a HookActivity that inherits from the system Acitivity, and override the getSystemService method of HookActivity to change the acquisition of ClipboardManager to HookClipboardManager;

[0063] S120: In the compilation stage of the program, use the transform task to find all classes that inherit from the system Activity, and change all classes that inherit from the system Activity to inherit from HookActivity;

[0064] S130: In the running stage of the program, automatically obtain the HookClipboardManager service of HookActivity, call the setPrimaryClip method in the HookClipboardManager service to save the copied content of the current application in the application memory, and call the getPrimaryClip method to paste the copied content in the application memory to the current page.

[0065] Based on the above, the clipboard content copy and paste method of the first embodiment of the present invention changes the system Activity in the program to a custom HookClipboradManager object, performs bytecode editing on all classes inherited from the system Activity, and changes them to classes inherited from HookActivity. The HookClipboradManager object is not a system object, so the content within the application will not be copied to the system clipboard but saved in the application memory, enabling the copied content in the application memory to be pasted only on any page within the application, and other applications cannot paste the copied data in this application, thus ensuring the data security within the application.

[0066] Please refer to Figure 2 , which is a schematic flowchart of the clipboard content copy and paste method of the second embodiment of the present invention. The clipboard content copy and paste method of the second embodiment of the present invention includes the following steps:

[0067] S200: In the coding stage of the program, customize a HookClipboardManager (clipboard service) that inherits from ClipboardManager (system clipboard service), and override the setPrimaryClip (copy clipboard content) and getPrimaryClip (get clipboard content) methods in HookClipboardManager, and add a getSystemPrimaryClip (get system clipboard content) method to change the content originally copied to the system clipboard to be stored in memory;

[0068] In this step, define 4 methods in HookClipboardManager, namely setPrimaryClip (copy clipboard content), getPrimaryClip (get clipboard content), setSystemPrimaryClip (call the original system method to copy system clipboard content), and getSystemPrimaryClip (call the original system method to get system clipboard content). By overriding the setPrimaryClip and getPrimaryClip methods and adding the getSystemPrimaryClip method, the content originally copied to the system clipboard is changed to be saved in memory, enabling the copied content to be pasted only within the application.

[0069] S210: Create a class that inherits from the system Activity and name it HookActivity. Override the getSystemService method of HookActivity to change the acquisition of the system clipboard service ClipboardManager to the custom HookClipboardManager.

[0070] In this step, in HookAcitivity, define a getSystemService method with the same name as android.app.Acitvity. The input parameter of this method is the system service name. When the calling party uses the getSystemService method to obtain the system clipboard service ClipboardManager, determine whether the input system service name is the clipboard service. If it is, return the custom HookClipboardManager of the present invention; if the input system service name is other services except the system clipboard service, normally call the getSystemService method of the parent class.

[0071] S220: In the compilation stage of the program, use the transform task to find all classes that inherit from the system Activity, and perform bytecode editing on all classes that inherit from the system Activity to change them to classes that inherit from HookActivity.

[0072] In this step, introduce a transform task in the compilation stage. Through this task, collect all the compiled bytecodes in the program and use Javassist (bytecode editing framework) to call the relevant interfaces to change the content in the bytecodes. Specifically, during the bytecode editing transform process, insert a subtask ActivityTransform to handle the inheritance relationship of Activity classes. Through this task, parse all the input class files to obtain the parent class relationship of the class files, and determine whether the parent class of the input class file is the system's android.app.Acitvity class. If it is, edit the parent class bytecode of this class to the custom HookActivity.

[0073] Specifically as Figure 3 shown, it is a schematic diagram of the bytecode editing process of an embodiment of the present invention, and its bytecode compilation process includes:

[0074] S221: When compiling an apk (program installation package), use the gradle plugin for building, execute the javac command on the Java source file, and obtain the compiled class (class is bytecode) file.

[0075] S222: Register a transform task in the gradle plugin. In the transform task, obtain the input class files through the passed-in TransformOutputProvider parameter;

[0076] S223: Use the open-source Javassit framework to perform bytecode editing processing on the class files according to the predetermined rules to obtain the processed class files, output the processed class files to the gradle build task, and merge the output class files to obtain the merged dex file;

[0077] Among them, performing bytecode editing processing on the class files according to the predetermined rules specifically includes: changing the method call of a certain class to the method call of another class, or changing the inheritance relationship of the class to a custom inheritance relationship, etc.; after the transform task is executed, the bytecode is processed into the desired result, and then it is output to the gradle build task, and the output class files are merged, and the merged product is the dex file.

[0078] S224: Package the dex file with related resources such as pictures to generate an apk file.

[0079] S230: During the program running stage, when the user performs a copy operation on any page within the current application, automatically obtain the HookClipboardManager service of HookActivity and call the setPrimaryClip method to save the copied content of the current application in the application memory;

[0080] In this step, during the program running stage, when any control within the program performs a copy operation, it will automatically call the getSystemService method of HookAcitvity to obtain the HookClipboradManager service, and then call the setPrimaryClip method to perform the data copy operation.

[0081] S240: When the user performs a paste operation on any page within the current application, automatically obtain the HookClipboardManager service of HookActivity and call the getPrimaryClip method to paste the copied content in the application memory to the current page;

[0082] In this step, when a paste operation is performed at another text input point within the program, the getSystemService method of HookAcitvity is automatically called to obtain the HookClipboradManager service, and the getPrimaryClip method is called to obtain the copied content in the application memory, and then the copied content is pasted at the text input point.

[0083] Based on the above, the clipboard content copy and paste method of the second embodiment of the present invention changes the system Activity in the program to a custom HookClipboradManager object, performs bytecode editing on all classes inherited from the system Activity, and changes them to classes inherited from HookActivity. The HookClipboradManager object is not a system object. Therefore, the content within the application is not copied to the system clipboard but is saved in the application memory, enabling the copied content in the application memory to be pasted only on any page within this application, and other applications cannot paste the copied data in this application, thus ensuring the data security within the application. When performing bytecode editing, the present invention will automatically process all code, without caring about the logic of historical code or newly added code, and the controls in the third-party SDK can also be modified and take effect, without any model compatibility issues and without the need for adaptation. While ensuring the data security within the application, the operation is simpler.

[0084] Please refer to Figure 4 , which is a schematic flowchart of the clipboard content copy and paste method of the third embodiment of the present invention. The clipboard content copy and paste method of the third embodiment of the present invention includes the following steps:

[0085] S300: Call the system's registerActivityLifecycleCallbacks method to monitor the page state of the current application, and determine whether the current application has switched from the background to the foreground based on the page state. If so, execute S201;

[0086] In this step, registerActivityLifecycleCallbacks is an interface in the application. After registration, the life cycles of all activities in the application will be monitored, and some special requirements can be implemented in the interface methods. In the embodiments of the present invention, the registerActivityLifecycleCallbacks method is used to listen to the page state of the current application. If the page state of the current application changes from an invisible state to a visible state, it means that the current application has switched from the background to the foreground, and the system will call the corresponding function to inform the developer. For example, the onStart function is called when the page is visible, and the onStop function is called when the page is invisible. If all pages in an application are in an invisible state, it means that the application has entered the background; if all pages in the application then become visible, it means that the application has switched from the background to the foreground.

[0087] Specifically, the code for listening to the page state is as follows:

[0088] 1) Call the registerActivityLifecycleCallbacks method provided by the system to listen to the status callbacks of all Activities (pages);

[0089] 2) Create a counter variable count. When the system calls back onActivityStart, the counter is incremented by 1. When the system calls back onActivityStop, the counter is decremented by 1;

[0090] 3) When the system calls back onActivityStop, if the counter is 0, it means that the application has entered the background; when the system calls back onActivityStart, if the counter is 1, it means that the application has entered the foreground.

[0091] S310: Determine whether there is new content in the system clipboard (ClipboardManager). If so, execute S302;

[0092] S320: Call the getSystemPrimaryClip (obtaining the system clipboard service) method of the custom HookClipboardManager to obtain the system clipboard content, and call the setPrimaryClip method to synchronize the obtained clipboard content to the HookClipboardManager in the current application, so as to copy and paste the clipboard content of the external application into the current application.

[0093] Based on the above, the clipboard content copy and paste method of the third embodiment of the present invention listens to the page state of the current application. When the page state of all pages in the current application changes from an invisible state to a visible state, it calls the getSystemPrimaryClip method of the custom HookClipboardManager to obtain the system clipboard content, and calls the setPrimaryClip method to synchronize the obtained clipboard content to the HookClipboardManager in the current application, so as to copy and paste the clipboard content of an external application into the current application, thereby realizing the copy and paste function of copying and pasting the clipboard content of an external application into the present application.

[0094] In an optional implementation manner, it is also possible to upload the result of the clipboard content copy and paste method to the blockchain.

[0095] Specifically, corresponding digest information is obtained based on the result of the clipboard content copy and paste method. Specifically, the digest information is obtained by performing a hashing process on the result of the clipboard content copy and paste method, such as being processed using the sha256s algorithm. Uploading the digest information to the blockchain can ensure its security and fairness and transparency to users. Users can download the digest information from the blockchain to verify whether the result of the clipboard content copy and paste method has been tampered with. The blockchain referred to in this example is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithms. Blockchain, in essence, is a decentralized database, a string of data blocks generated by using cryptographic methods. Each data block contains information about a batch of network transactions, which is used to verify the validity of the information (anti-counterfeiting) and generate the next block. The blockchain can include a blockchain underlying platform, a platform product service layer, and an application service layer, etc.

[0096] Please refer to Figure 5 , which is a schematic structural diagram of the clipboard content copy and paste device according to the embodiment of the present invention. The clipboard content copy and paste device 40 according to the embodiment of the present invention includes:

[0097] The program coding module 41: is used to customize a HookClipboardManager service that inherits from the system clipboard service ClipboardManager during the coding stage of the program, and rewrite the setPrimaryClip method and the getPrimaryClip method in the HookClipboardManager service to change the content originally copied to the system clipboard to be stored in the application memory; where setPrimaryClip is used to copy the clipboard content, and getPrimaryClip is used to obtain the clipboard content;

[0098] Class creation module 42: used to create a HookActivity that inherits from the system Acitivity, override the getSystemService method of HookActivity, and change the acquisition of ClipboardManager to HookClipboardManager;

[0099] Bytecode compilation module 43: used to find all classes that inherit from the system Activity during the compilation stage of the program, and change all classes that inherit from the system Activity to classes that inherit from HookActivity;

[0100] Copy and paste module 44: used to automatically obtain the HookClipboardManager service of HookActivity during the running stage of the program, call the setPrimaryClip method in the HookClipboardManager service to save the copied content of the current application in the application memory, and call the getPrimaryClip method to paste the copied content in the application memory to the current page.

[0101] The clipboard content copy and paste device according to the embodiment of the present invention changes the system Activity in the program to a custom HookClipboradManager object, performs bytecode editing on all classes that inherit from the system Activity, and changes them to classes that inherit from HookActivity. The HookClipboradManager object is not a system object, so the content in the application will not be copied to the system clipboard but saved in the application memory, so that the copied content in the application memory can only be pasted on any page within the application, and other applications cannot paste the copied data in this application, thus ensuring the data security within the application. When the present invention performs bytecode editing, it will automatically process all codes, without caring about the logic of historical codes or newly added codes, and the controls in the third-party SDK can also be modified and take effect, without compatibility problems with different models and without the need for adaptation. While ensuring the data security within the application, the operation is simpler.

[0102] Please refer to Figure 6 , which is a schematic structural diagram of a computer device according to an embodiment of the present invention. The computer device 50 includes:

[0103] A memory 51 storing executable program instructions;

[0104] A processor 52 connected to the memory 51;

[0105] The processor 52 is used to call the executable program instructions stored in the memory 51 and perform the following steps: In the encoding stage of the program, a HookClipboardManager service that inherits from the system clipboard service ClipboardManager is customized, and the setPrimaryClip method and the getPrimaryClip method are overridden in the HookClipboardManager service to change the content originally copied to the system clipboard to be stored in the application memory; where setPrimaryClip is to copy the clipboard content and getPrimaryClip is to obtain the clipboard content; a HookActivity that inherits from the system Acitivity is created, and the getSystemService method of the HookActivity is overridden to change the obtaining of ClipboardManager to HookClipboardManager; in the compilation stage of the program, the transform task is used to find all classes that inherit from the system Activity and change all classes that inherit from the system Activity to classes that inherit from HookActivity; in the running stage of the program, the HookClipboardManager service of HookActivity is automatically obtained, the setPrimaryClip method in the HookClipboardManager service is called to save the copied content of the current application in the application memory, and the getPrimaryClip method is called to paste the copied content in the application memory to the current page.

[0106] Among them, the processor 52 can also be called a CPU (Central Processing Unit, central processing unit). The processor 52 may be an integrated circuit chip with the ability to process signals. The processor 52 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0107] In the computer device according to the embodiment of the present invention, the system Activity in the program is changed to a custom HookClipboradManager object, and bytecode editing is performed on all classes inherited from the system Activity to be changed to classes inherited from HookActivity. Since the HookClipboradManager object is not a system object, the content in the application will not be copied to the system clipboard but is saved in the application memory, so that the copied content in the application memory can only be pasted on any page within the application, and other applications cannot paste the copied data in this application, thus ensuring the data security within the application. When performing bytecode editing, the present invention will automatically process all codes without caring about the logic of historical codes or newly added codes, and the controls in the third-party SDK can also be modified to take effect, without any model compatibility problems and without the need for adaptation. While ensuring the data security within the application, the operation is simpler.

[0108] Please refer to Figure 7 , Figure 7Schematic structural diagram of the storage medium according to an embodiment of the present invention. The storage medium according to the embodiment of the present invention stores program instructions 61 capable of implementing the following steps: In the encoding stage of the program, a HookClipboardManager service that inherits from the system clipboard service ClipboardManager is customized, and the setPrimaryClip method and the getPrimaryClip method are overridden in the HookClipboardManager service to change the content originally copied to the system clipboard to be stored in the application memory; where setPrimaryClip is to copy the clipboard content and getPrimaryClip is to obtain the clipboard content; a HookActivity that inherits from the system Acitivity is created, and the getSystemService method of the HookActivity is overridden to change the acquisition of ClipboardManager to HookClipboardManager; in the compilation stage of the program, the transform task is used to find all classes that inherit from the system Activity and change all classes that inherit from the system Activity to classes that inherit from HookActivity; in the running stage of the program, the HookClipboardManager service of HookActivity is automatically obtained, the setPrimaryClip method in the HookClipboardManager service is called to save the copied content of the current application in the application memory, and the getPrimaryClip method is called to paste the copied content in the application memory to the current page. Among them, the program instructions 61 can be stored in the above storage medium in the form of a software product, including several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods according to various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program instructions, or terminal devices such as computers, servers, mobile phones, and tablets.

[0109] In the storage medium according to the embodiments of the present invention, by changing the system Activity in the program to a custom HookClipboradManager object, bytecode editing is performed on all classes inherited from the system Activity, and they are changed to classes inherited from HookActivity. The HookClipboradManager object is not a system object. Therefore, the content within the application is not copied to the system clipboard but is saved in the application memory, enabling the copied content in the application memory to be pasted only on any page within the application, and other applications cannot paste the copied data in this application, thereby ensuring the data security within the application. When performing bytecode editing in the present invention, all codes are automatically processed without the need to concern about the logic of historical codes or newly added codes, and the controls in the third-party SDK can also be modified to take effect. There is no problem of device model compatibility and no need for adaptation. While ensuring the data security within the application, the operation is simpler.

[0110] In several embodiments provided by the present invention, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For example, the division of units is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components 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 an indirect coupling or communication connection through some interfaces, devices, or units, and can be in electrical, mechanical, or other forms.

[0111] In addition, each functional unit in various embodiments of the present invention can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units. The above is only the implementation manner of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or equivalent process transformation made by using the specification and drawings of the present invention, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present invention.

Claims

1. A clipboard content copy and paste method, characterized in that, Including: During the coding stage of the program, customize a HookClipboardManager service that inherits from the system clipboard service ClipboardManager, and override the setPrimaryClip method and getPrimaryClip method in the HookClipboardManager service to save the content originally copied to the system clipboard into the application memory; where setPrimaryClip is used to copy clipboard content, and getPrimaryClip is used to obtain clipboard content; Create a HookActivity that inherits from the system Acitivity, and override the getSystemService method of HookActivity to change the acquisition of the system clipboard service ClipboardManager to the customized HookClipboardManager; During the compilation stage of the program, use the transform task to find all classes that inherit from the system Activity, and change all classes that inherit from the system Activity to classes that inherit from HookActivity; During the running stage of the program, automatically obtain the HookClipboardManager service of HookActivity, call the setPrimaryClip method in the HookClipboardManager service to save the copied content of the current application in the application memory, and call the getPrimaryClip method to paste the copied content in the application memory to the current page.

2. The clipboard content copy and paste method according to claim 1, characterized in that, The customizing a HookClipboardManager service that inherits from the system clipboard service ClipboardManager further includes: Add a getSystemPrimaryClip method in HookClipboardManager, and getSystemPrimaryClip is to call the original system method to obtain the system clipboard content.

3. The clipboard content copy and paste method according to claim 2, characterized in that, The creating a HookActivity that inherits from the system Acitivity and overriding the getSystemService method of HookActivity specifically is: In HookAcitivity, define a getSystemService method with the same name as android.app.Acitvity, and the input parameter of the getSystemService method is the system service name; When using the getSystemService method to obtain the ClipboardManager service, it is determined whether the input system service name is the clipboard service. If so, the HookClipboardManager service is returned; if the input system service name is other services except the clipboard service, the getSystemService method of the parent class is normally called.

4. The clipboard content copy and paste method according to claim 3, characterized in that The specific method of changing all classes that inherit from the system Activity to inherit from the HookActivity class is as follows: Use the transform task to find all classes that inherit from the system Activity, and perform bytecode editing on all classes that inherit from the system Activity to change them to inherit from the HookActivity class; among them, the bytecode editing of all classes that inherit from the system Activity includes: When compiling a program installation package, use the gradle plugin for building, execute the javac command on the Java source file to obtain the compiled bytecode file; Register a transform task in the gradle plugin. In the transform task, obtain the input bytecode file through the passed TransformOutputProvider parameter; Use the Javassit framework to perform bytecode editing processing on the bytecode file according to a predetermined rule to obtain the processed bytecode file, output the processed bytecode file to the gradle build task, and merge the output bytecode files to obtain the merged dex file; Package the dex file with relevant resources to generate a program installation package.

5. The clipboard content copy and paste method according to any one of claims 1 to 4, characterized in that, The specific method of calling the setPrimaryClip method in the HookClipboardManager service to save the copied content of the current application in the application memory and calling the getPrimaryClip method to paste the copied content in the application memory to the current page is as follows: When the user performs a copy operation on any page within the current application, automatically obtain the HookClipboardManager service by using the getSystemService method of HookActivity, and call the setPrimaryClip method to save the copied content of the current application in the application memory; When the user performs a paste operation on any page within the current application, automatically call the getSystemService method of HookActivity to obtain the HookClipboardManager service, and call the getPrimaryClip method to paste the copied content in the application memory to the current page.

6. The clipboard content copy and paste method according to claim 2, wherein The step of saving the copied content of the current application in the application memory by calling the setPrimaryClip method in the HookClipboardManager service and pasting the copied content in the application memory to the current page by calling the getPrimaryClip method further includes: Calling the registerActivityLifecycleCallbacks method of the system to monitor the page state of the current application, and judging whether the current application has switched from the background to the foreground according to the page state. If so, Calling the getSystemPrimaryClip method of the HookClipboardManager service to obtain the system clipboard content, and calling the setPrimaryClip method to synchronize the obtained clipboard content to the HookClipboardManager in the current application, so that the clipboard content of an external application can be copied and pasted into the current application.

7. The clipboard content copy and paste method according to claim 6, characterized in that, The step of calling the registerActivityLifecycleCallbacks method of the system to monitor the page state of the current application specifically is: Calling the registerActivityLifecycleCallbacks method provided by the system to monitor the state callbacks of all pages; Creating a counter variable count. When the system calls back onActivityStart, the counter is incremented by 1. When the system calls back onActivityStop, the counter is decremented by 1; When the system calls back onActivityStop, if the counter is 0, it means that the page of the current application is in an invisible state and the current application has entered the background. When the system calls back onActivityStart, if the counter is 1, it means that the page in the current application is in a visible state and the current application has switched from the background to the foreground.

8. A clipboard content copy and paste device, characterized in that, Including: Program coding module: used to customize a HookClipboardManager service that inherits from the system clipboard service ClipboardManager during the coding stage of the program, and override the setPrimaryClip method and the getPrimaryClip method in the HookClipboardManager service to change the content originally copied to the system clipboard to be stored in the application memory; where setPrimaryClip is to copy the clipboard content and getPrimaryClip is to obtain the clipboard content; Class creation module: used to create a HookActivity that inherits from the system Acitivity, and override the getSystemService method of HookActivity to change the acquisition of the system clipboard service ClipboardManager to the custom HookClipboardManager; Bytecode Compilation Module: Used to find all classes that inherit from the system Activity during the compilation phase of the program, and change all classes that inherit from the system Activity to classes that inherit from HookActivity; Copy and Paste Module: Used to automatically obtain the HookClipboardManager service of HookActivity during the running phase of the program, call the setPrimaryClip method in the HookClipboardManager service to save the copied content of the current application in the application memory, and call the getPrimaryClip method to paste the copied content in the application memory onto the current page.

9. A computer device, characterized in that, The computer device includes: A memory storing executable program instructions; A processor connected to the memory; The processor calls the executable program instructions stored in the memory to execute the clipboard content copy and paste method according to any one of claims 1-7.

10. A storage medium storing program instructions executable by a processor, characterized in that, The program instructions are used to execute the clipboard content copy and paste method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Shearing plate data protection method and device, computer equipment and storage medium

    CN112416622A

  • Policy-Based Application Management

    US20140033271A1