Go to file
yyh 2849a0a1e7 Description:add permission check
Feature or Bugfix:Bugfix
Bunary Source:No

Signed-off-by: yyh <yangyinghua1@huawei.com>
2024-11-15 17:56:41 +08:00
.gitee detect pattern 2024-08-20 03:39:37 +00:00
adapter code fix 2024-09-28 10:10:40 +08:00
etc/init fix:Code format 2024-10-15 17:34:30 +08:00
figures Signed-off-by: LVB8189 <lvbai1@huawei.com> 2022-08-09 15:43:07 +08:00
framework fix UT failed 2024-11-15 14:47:06 +08:00
interfaces !983 去重pastedata获取的MIME types 2024-11-13 08:39:24 +00:00
profile 剪切板动态启停优化 2023-04-28 10:21:05 +08:00
services Description:add permission check 2024-11-15 17:56:41 +08:00
test/fuzztest fix crash 2024-11-12 20:47:37 +08:00
utils/native/include fix:add share option judgement 2024-10-18 19:33:31 +08:00
.gitattributes fix:Code format 2024-10-15 17:34:30 +08:00
.gitignore 补充测试TDD用例 2023-08-09 17:40:56 +08:00
BUILD.gn add entries and delay getter 2024-08-28 18:07:32 +08:00
bundle.json add entries and delay getter 2024-08-28 18:07:32 +08:00
CODEOWNERS Description:处理告警 2023-07-06 14:30:39 +08:00
LICENSE 提交剪贴板代码 2022-03-09 13:23:51 +08:00
OAT.xml update resources 2024-06-18 11:11:32 +08:00
pasteboard.gni fix code check 2024-08-31 20:10:19 +08:00
pasteboardEvent.yaml cde检测问题修改以及Copyright时间调整 2023-03-30 10:21:43 +08:00
README_ZH.md alert modification 2024-01-18 06:38:19 +00:00
README.md alert modification 2024-01-18 06:38:19 +00:00

pasteBoardService

Introduction

As a functional component of the stray subsystem, the clipboard service provides the ability to manage the system clipboard and supports the system copy and paste functions. The system clipboard supports package text, hypertext, URIs and other content operations.

picture 1 Subsystem Architecture Diagram

The clipboard service provides functions that support application developers to use clipboard-related services conveniently and efficiently. Its main components include clipboard management client and clipboard service. The clipboard management client is responsible for clipboard interface management, providing clipboard northbound JS API to applications; creating clipboard data on the application framework side, requesting clipboard SA to perform clipboard creation, deletion, query, text conversion, configuration, etc. The clipboard service is responsible for clipboard event management, manages the life cycle of clipboard SA (startup, destruction, multi-user, etc.); executes application requests, notifies clipboard data management, and returns the results to the clipboard management client.

Directory Structure

/foundation/distributeddatamgr/pasteboard
├── etc         # Configuration files for the processes contained in the component
├── figures     # Framework diagram
├── framework   # innerKit interface
├── interfaces  # The interface code provided by the component externally
│   └── kits    # Interface provided to the application
├── profile     # Configuration files for system services contained in the component
├── services    # clipboard service implementation
│    └── core   # Core code implementation
│    └── test   # native test code
│    └── zidl   # Cross-process communication code implementation
├── utils       # Tests or services use mocked data
└──README.md    # Instructions for use

illustrate

Interface Description

list 1 PasteBoard open main method

interface name

describe

createHtmlData(htmlText: string): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_HTML for HTML type data

createWantData(want: Want): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_WANT for data of type want

createPlainTextData(text: string): PasteData

Create a PasteData object of type MIMETYPE_TEXT_PLAIN for plain text data

createUriData(uri: string): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_URI for data of type URI

createHtmlTextRecord(htmlText: string): PasteDataRecord;

Create a PasteDataRecord object of type RecordMIMETYPE_TEXT_HTML for hypertext type data

createWantRecord(want: Want): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_WANT for data of type want

createPlainTextRecord(text: string): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_PLAIN for plain text data

createUriRecord(uri: string): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_URI for data of type URI

getSystemPasteboard(): SystemPasteboard

Get system clipboard

list 2 SystemPasteboard open main method

interface name

describe

on(type:'update', callback: () => void): void;

Callback called when the open pasteboard content changes

off(type: 'update', callback?: () => void): void

Callback called when the content of the pasteboard is closed

clear(callback: AsyncCallback): void

clear clipboard

clear(): Promise;

clear clipboard

getPasteData(callback: AsyncCallback<PasteData>): void

Get system clipboard data object

getPasteData():Promise<PasteData>

Get system clipboard data object

hasPasteData(callback: AsyncCallback<boolean>:void;

Check if there is content in the pasteboard

hasPasteData(): Promise<boolean>

Check if there is content in the pasteboard

setPasteData(data: PasteData, callback: AsyncCallback<void>:void;

Write PasteData to the pasteboard

setPasteData(data: PasteData): Promise<void>

Write PasteData to the pasteboard

list 3 PasteData open main method

interface name

describe

addHtmlRecord(htmlText: string): void;

Add the HTML text record to the PasteData object and update the MIME type to PasteData#MIMETYPE_TEXT_HTML in the DataProperty.

addWantRecord(want: Want): void;

Add want record to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_WANT in DataProperty

addRecord(record: PasteDataRecord): void;

Add PasteRecord to paste data object and update MIME type in data attribute

addTextRecord(text: string): void;;

Add plain text records to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_PLAIN in DataProperty

addUriRecord(uri: string): void;

Add URI record to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_URI in DataProperty

getMimeTypes(): Array<string>

MIME type of everything on the pasteboard

getPrimaryHtml(): string;

HTML text of the main record in the PasteData object

getPrimaryWant(): Want;

The want of the main record in the PasteData object

getPrimaryMimeType(): string;

The MIME type of the main record in the PasteData object

getPrimaryUri(): string;

URI of the main record in the PasteData object

getProperty(): PasteDataProperty;

Get the properties of the clipboard data object

getRecordAt(index: number): PasteDataRecord;

records based on the specified index

getRecordCount(): number;

Number of records in PasteData object

hasMimeType(mimeType: string): boolean;

Checks if data of the specified MIME type exists in the DataProperty

removeRecordAt(index: number): boolean;

Delete records based on specified index

replaceRecordAt(index: number, record: PasteDataRecord): boolean;

Replace the specified record with a new record

list 4 PasteDataRecord open main method

interface name

describe

convertToText(callback: AsyncCallback<string>): void;

Convert PasteData to text content

convertToText(): Promise<void>

Convert PasteData to text content

list 5 PasteDataProperty Parameter Description

name

type

illustrate

additions{[key:string]}

object

Additional property data key-value pair

mimeTypes

Array

Distinct MIME types for all records in PasteData

tag

string

User-defined labels for PasteData objects

timestamp

number

Timestamp indicating when the data was written to the system clipboard.

localOnly

boolean

Check if PasteData is set for local access only.

Instructions for use

Clipboard module usage example

// import module
import pasteboard from '@ohos.pasteboard'
//text copy
console.log('Get SystemPasteboard')
var systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.clear()
        
var textData = 'Hello World!'
console.log('createPlainTextData = ' + textData)
var pasteData = pasteboard.createPlainTextData(textData)
        
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
        
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
        
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
        
console.log('Checks the pasteboard content')
assert.equal(pasteData.getPrimaryText(), textData)
        
console.log('Checks there is a MIMETYPE_TEXT_PLAIN MIME type of data')
assert.equal(pasteData.hasMimeType(MIMETYPE_TEXT_PLAIN), true)
assert.equal(pasteData.getPrimaryMimeType(), MIMETYPE_TEXT_PLAIN)

//clipboard change listener
console.log('Off the content changes')
var systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.off(contentChanges)
systemPasteboard.clear()
        
var textData = 'Hello World!'
console.log('createUriData = ' + textData)
var pasteData = pasteboard.createUriData(textData)
        
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
        
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
        
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
        
console.log('On the content changes')
systemPasteboard.on(contentChanges)
        
console.log('Removes the Record')
assert.equal(pasteData.removeRecordAt(0), true)
        
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
        
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 0)
        
console.log('Checks there is  no content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), false)
        
var textDataNew = 'Hello World!-New'
console.log('createUriData = ' + textDataNew)
var pasteData = pasteboard.createUriData(textDataNew)
        
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
        
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
        
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
        
console.log('Checks the pasteboard content')
assert.equal(pasteData.getRecordAt(0).plainText, textDataNew)

Distributed Data Management subsystem

distributeddatamgr_pasteboard