未验证 提交 fdffdb40 编写于 作者: O openharmony_ci 提交者: Gitee

!5387 add XTS of DataAbility access DataShare

Merge pull request !5387 from zhoujun62/my_xts_acts
......@@ -28,6 +28,7 @@ group("ability_runtime") {
"actscalldataabilitytest:ActsCallDataAbilityTest",
"actscalldataabilitytest:ActsCallDataAbilityTest",
"actscalltest:actscalltest",
"actsdataabilityaccessdatasharetest:dataabilityaccessdatashare",
"actsfwkdataaccessortest:dataability",
"actsqueryfunctiontest:actsqueryfunctiontest",
"actsserviceabilityclienttest:serviceability",
......
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
group("dataabilityaccessdatashare") {
testonly = true
if (is_standard_system) {
deps = [
"actsdataabilityaccessdatasharetest:ActsDataAbilityAccessDataShareTest",
"datashareserverhap:DataShareServerHap",
]
}
}
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsDataAbilityAccessDataShareTest") {
hap_profile = "./src/main/config.json"
hap_name = "ActsDataAbilityAccessDataShareTest"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_js_assets("hjs_demo_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"shell-timeout": "180000",
"bundle-name": "com.amsst.dataabilityaccessdatashare",
"package-name": "com.amsst.dataabilityaccessdatashare"
},
"kits": [
{
"test-file-name": [
"ActsDataAbilityAccessDataShareTest.hap",
"DataShareServerHap.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.amsst.dataabilityaccessdatashare",
"vendor": "amsst",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 9,
"target": 5,
"releaseType": "Beta1"
}
},
"deviceConfig": {},
"module": {
"package": "com.amsst.dataabilityaccessdatashare",
"name": ".entry",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"mainAbility": ".MainAbility",
"srcPath": ""
}
}
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
onCreate() {
console.info('AceApplication onCreate');
},
onDestroy() {
console.info('AceApplication onDestroy');
}
};
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
.titleST {
font-size: 32px;
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
<text class="titleST">
STDataAbility
</text>
</div>
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file'
import app from '@system.app'
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('====onShow finish====<')
},
onReady() {
},
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('TestApplication onCreate')
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info("TestApplication onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
}
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package', '-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
export default {
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
},
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
console.info('debug value : '+debug)
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd, (err, data) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + data.stdResult);
console.info('executeShellCommand : data : ' + data.exitCode);
})
}
};
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import featureAbility from '@ohos.ability.featureAbility'
import ohosDataAbility from '@ohos.data.dataAbility'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function ActsDataAbilityHelperTest() {
describe('ActsDataAbilityHelperTest', function () {
let dataAbilityUri = ("dataability:///com.example.dataabilityserver_fa.DataAbility");
let dataShareUri = ("datashare:///com.example.dataabilityserver_fa.DataAbility");
let columns = ['id', 'name', 'introduction']
let DAHelper;
let gSetTimeout = 500;
let TAG = ''
function sleep(delay) {
let start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > delay) {
break;
}
}
}
beforeAll(async (done) => {
console.debug('= ACTS_beforeAll ====<begin');
try {
DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);
console.debug('ACTS_beforeAll DAHelper ====> ' + DAHelper + " ,JSON. " + JSON.stringify(DAHelper));
if(DAHelper == null){
console.debug('ACTS_beforeAll DAHelper ====> DAHelper == null');
return;
}
} catch (err) {
console.error('=ACTS_beforeAll acquireDataAbilityHelper catch(err)====>' + err);
}
sleep(500);
console.debug('= ACTS_beforeAll ====<end');
done();
})
afterAll((done) => {
console.debug('= ACTS_afterAll ====<begin');
console.debug('= ACTS_afterAll ====<end');
done();
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_Inset_0100
* @tc.name: insert : insert data to DataShare by DataAbilityHelper
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_Inset_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_Inset_0100';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let insertValuesBucket = {'name':'C++', 'introduction':'Primer'};
await DAHelper.insert(
dataAbilityUri,
insertValuesBucket,
(err, data) => {
console.log(TAG + ' insert err, data====>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(1);
console.log(TAG + '====<end');
done();
})
} catch (err) {
console.error(TAG + ' catch(err)====>' + err);
expect(false).assertTrue();
}
console.log(TAG + '====<end');
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_Inset_0200
* @tc.name: insert : insert data to DataShare by DataAbilityHelper
* @tc.desc: Check the return value of the interface (by promise)
*/
it('ACTS_DataAbilityAccessDataShare_Inset_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_Inset_0200';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let insertValuesBucket = {'name':'C++', 'introduction':'Primer'};
DAHelper.insert(dataAbilityUri, insertValuesBucket)
.then(function (data) {
console.log(TAG + ' then data====>'
+ 'json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(2);
console.log(TAG + '====<end');
done();
}).catch(function (err) {
console.log(TAG + ' catch err ====>'
+ 'json err [ ' + JSON.stringify(err) + ' ]');
expect(false).assertTrue();
console.log(TAG + '====<end .catch');
done();
});
} catch (err) {
console.error(TAG + ' catch(err)====>' + err);
expect(false).assertTrue();
console.log(TAG + '====<end catch');
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_Query_0100
* @tc.name: Queries one or more data records in the database
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_Query_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_Query_0100';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let predicates = new ohosDataAbility.DataAbilityPredicates();
predicates.equalTo('id', 1);
await DAHelper.query(
dataAbilityUri,
columns,
predicates,
(err, data) => {
console.log(TAG + ' query err, data====>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
expect(typeof (data)).assertEqual("object");
console.log(TAG + '====<end');
done();
});
} catch (err) {
console.error(TAG + ' catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_Query_0200
* @tc.name: Updates one or more data records in the database
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_DataAbilityAccessDataShare_Query_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_Query_0200';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let predicates = new ohosDataAbility.DataAbilityPredicates();
predicates.equalTo('id', 2);
let queryPromise = DAHelper.query(
dataAbilityUri,
columns,
predicates
);
console.log(TAG + ' queryPromise ====>'
+ 'json queryPromise [ ' + JSON.stringify(queryPromise) + ' ]');
expect(typeof (queryPromise)).assertEqual("object");
console.log(TAG + '====<end');
done();
} catch (err) {
console.error(TAG + ' query catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_Update_0100
* @tc.name: Updates one or more data records in the database
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_Update_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_Update_0100';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let predicates = new ohosDataAbility.DataAbilityPredicates();
predicates.equalTo('id', 1);
let updateValuesBucket = {
'name': 'Java',
'introduction': 'Learner'
};
await DAHelper.update(
dataAbilityUri,
updateValuesBucket,
predicates,
(err, data) => {
console.log(TAG + ' update err, data====>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(1);
console.log(TAG + '====<end');
done();
});
} catch (err) {
console.error(TAG + ' catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_Update_0200
* @tc.name: Queries one or more data records in the database
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_DataAbilityAccessDataShare_Update_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_Update_0200';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let predicates = new ohosDataAbility.DataAbilityPredicates();
predicates.equalTo('id', 2);
let updateValuesBucket = {
'name': 'Java',
'introduction': 'Learner'
};
DAHelper.update(
dataAbilityUri,
updateValuesBucket,
predicates
).then((data) => {
console.log(TAG + ' then data====>'
+ 'json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(1);
console.log(TAG + '====<end');
done();
}).catch((err) => {
console.log(TAG + ' catch err ====>'
+ 'json err [ ' + JSON.stringify(err) + ' ]');
console.log(TAG + '====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error(TAG + ' update catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_Delete_0100
* @tc.name: Deletes one or more data records in the database
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_Delete_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_Delete_0100';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let predicates = new ohosDataAbility.DataAbilityPredicates();
predicates.equalTo('id', 1);
await DAHelper.delete(
dataAbilityUri,
predicates,
(err, data) => {
console.log(TAG + ' delete err, data====>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(1);
console.log(TAG + '====<end');
done();
});
} catch (err) {
console.error(TAG + ' catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_Delete_0200
* @tc.name: Deletes one or more data records in the database
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_DataAbilityAccessDataShare_Delete_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_Delete_0200';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let predicates = new ohosDataAbility.DataAbilityPredicates();
predicates.equalTo('id', 2);
DAHelper.delete(
dataAbilityUri,
predicates
).then((data) => {
console.log(TAG + ' then data====>'
+ 'json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(1);
console.log(TAG + '====<end');
done();
}).catch((err) => {
console.log(TAG + ' catch err ====>'
+ 'json err [ ' + JSON.stringify(err) + ' ]');
console.log(TAG + '====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error(TAG + ' delete catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_BatchInsert_0100
* @tc.name: Insert one or more data records to the database
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_BatchInsert_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_BatchInsert_0100';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let vbs = new Array({'name': 'Python', 'introduction': 'Cookbook'},
{'name': 'JS', 'introduction': 'Guide'}, {'name': 'GO', 'introduction': 'Expert'});
await DAHelper.batchInsert(
dataAbilityUri,
vbs,
(err, data) => {
console.log(TAG +' batchInsert err, data====>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(3);
console.log(TAG +'====<end');
done();
});
} catch (err) {
console.error(TAG +' catch(err)====>' + err);
console.log(TAG +'====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_BatchInsert_0200
* @tc.name: Insert one or more data records to the database
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_DataAbilityAccessDataShare_BatchInsert_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_BatchInsert_0200';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let vbs = new Array({'name': 'Python', 'introduction': 'Cookbook'},
{'name': 'JS', 'introduction': 'Guide'}, {'name': 'GO', 'introduction': 'Expert'});
DAHelper.batchInsert(
dataAbilityUri,
vbs
).then((data) => {
console.log(TAG + ' then data====>'
+ 'json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(3);
console.log(TAG + '====<end');
done();
}).catch((err) => {
console.log(TAG + ' catch err ====>'
+ 'json err [ ' + JSON.stringify(err) + ' ]');
console.log(TAG + '====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error(TAG + ' batchInsert catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_OnOff_0100
* @tc.name: On/Off : Registers an observer to observe data specified by the given Uri
* @tc.desc: Check the return value of the interface ()
*/
it('ACTS_DataAbilityAccessDataShare_OnOff_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_OnOff_0100';
console.log(TAG + '====<begin');
gSetTimeout = 2000;
try {
var currentAlertTimeout;
expect(typeof (DAHelper)).assertEqual("object");
function onAsyncCallback0100(err) {
expect(err.code).assertEqual(0);
DAHelper.off("dataChange", dataAbilityUri, onAsyncCallback0100);
console.log(TAG + '====<end');
gSetTimeout = 500;
done();
}
DAHelper.off("dataChange", dataAbilityUri, onAsyncCallback0100);
DAHelper.on("dataChange", dataAbilityUri, onAsyncCallback0100);
setTimeout(mySetTimeout, gSetTimeout);
function mySetTimeout() {
console.log(TAG + '====< mySetTimeout');
DAHelper.notifyChange(
dataAbilityUri,
(err) => {
console.log(TAG + ' err=======>'
+ 'err [ ' + JSON.stringify(err) + ' ]');
expect(err.code).assertEqual(0);
}
);
}
} catch (err) {
console.error(TAG + ' catch(err)====>' + err);
expect(false).assertTrue();
console.log(TAG + '====<end catch');
gSetTimeout = 500;
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_OnOff_0200
* @tc.name: On/Off : Registers an observer to observe data specified by the given Uri
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_OnOff_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_OnOff_0200';
console.log(TAG + '====<begin');
gSetTimeout = 2000;
try {
var currentAlertTimeout;
expect(typeof (DAHelper)).assertEqual("object");
function onAsyncCallback0200(err) {
console.log(TAG + ' onAsyncCallback0200=======>');
expect(false).assertTrue();
clearTimeout(currentAlertTimeout);
console.log(TAG + '====<end callback_0200');
done();
}
DAHelper.on("dataChange", dataAbilityUri, onAsyncCallback0200);
DAHelper.off("dataChange", dataAbilityUri, onAsyncCallback0200);
setTimeout(mySetTimeout, gSetTimeout);
function mySetTimeout() {
DAHelper.notifyChange(
dataAbilityUri,
(err) => {
if (err.code != 0) {
console.log(TAG + ' err=======>'
+ 'err [ ' + JSON.stringify(err) + ' ]');
expect(false).assertTrue();
console.log(TAG + '====<end err.code');
done();
} else {
currentAlertTimeout = setTimeout(() => {
expect(err.code).assertEqual(0);
console.log(TAG + '====<end');
done();
}, gSetTimeout);
}
}
);
}
} catch (err) {
console.error(TAG + ' catch(err)====>' + err);
expect(false).assertTrue();
console.log(TAG + '====<end catch');
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_GetType_0100
* @tc.name: Obtains the MIME type matching the data specified by the URI of the Data ability.
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_GetType_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_GetType_0100';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
try {
let mimeType = "image";
await DAHelper.getType(
dataAbilityUri,
(err, data) => {
console.debug(TAG + ' getType err,data=======>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(mimeType);
console.log(TAG + '====<end');
done();
},
);
} catch (err) {
console.error(TAG + ' getType AsyncCallback catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_GetType_0200
* @tc.name: Obtains the MIME type matching the data specified by the URI of the Data ability.
* @tc.desc: Check the return value of the interface (by promise)
*/
it('ACTS_DataAbilityAccessDataShare_GetType_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_GetType_0200';
console.log(TAG + '====<begin');
try {
let mimeType = "image";
var promise = DAHelper.getType(
dataAbilityUri,
).then(data => {
console.log(TAG + ' then data====>'
+ 'json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(mimeType);
console.log(TAG + '====<end');
done();
}).catch(err => {
console.log(TAG + ' catch err ====>'
+ 'json err [ ' + JSON.stringify(err) + ' ]');
console.log(TAG + '====<end .catch');
expect(false).assertTrue();
done();
});
console.log(TAG + ' getType promise ====>' + promise)
} catch (err) {
console.error(TAG + ' getType AsyncCallback catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_GetFileTypes_0100
* @tc.name: Obtains the MIME type of files.
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_GetFileTypes_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_GetFileTypes_0100';
console.log(TAG + '====<begin');
expect(typeof (DAHelper)).assertEqual("object");
let mimeTypeFilter = 'image/*';
try {
await DAHelper.getFileTypes(
dataAbilityUri,
mimeTypeFilter,
(err, data) => {
console.log(TAG + ' getFileTypes err,data=======>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
console.log(TAG + ' data.length ====>' + data.length);
expect(data.length).assertEqual(3);
for (let i = 0; i < data.length; i++) {
expect(typeof (data[i])).assertEqual("string");
console.log(TAG + ' for data ====>' + err.code +
' data[' + i + ']: ' + data[i]);
if (i == 0) {
expect(data[i]).assertEqual("type01");
} else if (i == 1) {
expect(data[i]).assertEqual("type00");
} else if (i == 2) {
expect(data[i]).assertEqual("type03");
}
}
console.log(TAG + '====<end');
done();
},
);
} catch (err) {
console.error(TAG + ' getFileTypes AsyncCallback catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_GetFileTypes_0200
* @tc.name: Obtains the MIME type of files.
* @tc.desc: Check the return value of the interface (by promise)
*/
it('ACTS_DataAbilityAccessDataShare_GetFileTypes_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_GetFileTypes_0200';
console.log(TAG + '====<begin');
let mimeTypeFilter = 'image/*';
try {
var promise = DAHelper.getFileTypes(
dataAbilityUri,
mimeTypeFilter,
).then((data) => {
console.log(TAG + ' then data====>'
+ 'json data [ ' + JSON.stringify(data) + ' ]');
console.log(TAG + ' getFileTypes data.length ====>' + data.length);
expect(data.length).assertEqual(3);
for (var i = 0; i < data.length; i++) {
expect(typeof (data[i])).assertEqual("string");
console.log(TAG + ' for data[' + i + '] ====>' + data[i])
if (i == 0) {
expect(data[i]).assertEqual("type01");
} else if (i == 1) {
expect(data[i]).assertEqual("type00");
} else if (i == 2) {
expect(data[i]).assertEqual("type03");
}
}
console.log(TAG + '====<end');
done();
}).catch(err => {
console.log(TAG + ' getFileTypes catch err ====>'
+ 'json err [ ' + JSON.stringify(err) + ' ]');
console.log(TAG + '====<end .catch');
expect(false).assertTrue();
done();
});
console.log(TAG + ' getFileTypes promise ====>: ' + promise)
} catch (err) {
console.error(TAG + ' getFileTypes AsyncCallback catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_NormalizeUri_0100
* @tc.name: Converts the given uri that refer to the Data ability into a normalized URI.
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_NormalizeUri_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_NormalizeUri_0100';
console.log(TAG + '====<begin');
let ret = false;
expect(typeof (DAHelper)).assertEqual("object");
try {
DAHelper.normalizeUri(
dataAbilityUri,
(err, data) => {
console.log(TAG + ' err,data=======>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
expect(typeof (data)).assertEqual("string");
expect(data).assertEqual(dataShareUri);
console.log(TAG + '====<end');
done();
},
);
} catch (err) {
console.error(TAG + ' normalizeUri AsyncCallback catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_NormalizeUri_0200
* @tc.name: Converts the given uri that refer to the Data ability into a normalized URI.
* @tc.desc: Check the return value of the interface (by promise)
*/
it('ACTS_DataAbilityAccessDataShare_NormalizeUri_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_NormalizeUri_0200';
console.log(TAG + '====<begin');
let ret = false;
expect(typeof (DAHelper)).assertEqual("object");
try {
DAHelper.normalizeUri(
dataAbilityUri,
).then((data) => {
console.log(TAG + ' then data====>'
+ 'json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(dataShareUri);
console.log(TAG + '====<end');
done();
}).catch(err => {
console.log(TAG + ' catch err ====>'
+ 'json err [ ' + JSON.stringify(err) + ' ]');
console.log(TAG + '====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error(TAG + ' normalizeUri promise catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_DenormalizeUri_0100
* @tc.name: Converts the given normalized uri generated by normalizeUri into a denormalized one.
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_DataAbilityAccessDataShare_DenormalizeUri_0100', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_DenormalizeUri_0100';
console.log(TAG + '====<begin');
let ret = false;
expect(typeof (DAHelper)).assertEqual("object");
try {
DAHelper.denormalizeUri(
dataAbilityUri,
(err, data) => {
console.log(TAG + ' err,data=======>'
+ 'json err [ ' + JSON.stringify(err) + ' ], json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(dataShareUri);
console.log(TAG + '====<end');
done();
},
);
} catch (err) {
console.error(TAG +' denormalizeUri AsyncCallback catch(err)====>' + err);
console.log(TAG + '====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DataAbilityAccessDataShare_DenormalizeUri_0200
* @tc.name: Converts the given normalized uri generated by normalizeUri into a denormalized one.
* @tc.desc: Check the return value of the interface (by promise)
*/
it('ACTS_DataAbilityAccessDataShare_DenormalizeUri_0200', 0, async function (done) {
TAG = 'ACTS_DataAbilityAccessDataShare_DenormalizeUri_0200';
console.log(TAG + '====<begin');
let ret = false;
expect(typeof (DAHelper)).assertEqual("object");
try {
DAHelper.denormalizeUri(
dataAbilityUri,
).then((data) => {
console.log(TAG +' then data====>'
+ 'json data [ ' + JSON.stringify(data) + ' ]');
expect(data).assertEqual(dataShareUri);
console.log(TAG +'====<end');
done();
}).catch(err => {
console.log(TAG +' catch err ====>'
+ 'json err [ ' + JSON.stringify(err) + ' ]');
console.log(TAG +'====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error(TAG +' denormalizeUri promise catch(err)====>' + err);
console.log(TAG +'====<end catch');
expect(false).assertTrue();
done();
}
})
})}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import ActsDataAbilityHelperTest from './DataAbilityHelperJsSt.test.js'
export default function testsuite() {
ActsDataAbilityHelperTest()
}
{
"string": [
{
"name": "app_name",
"value": "STDataAbility"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.datashareserver_stage",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"minAPIVersion": 9,
"targetAPIVersion": 9
}
}
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_hap_assist_suite("DataShareServerHap") {
hap_name = "DataShareServerHap"
js_build_mode = "debug"
testonly = true
hap_profile = "entry/src/main/module.json"
deps = [
":datashareserverhap_js_assets",
":datashareserverhap_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("datashareserverhap_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("datashareserverhap_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("datashareserverhap_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":datashareserverhap_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[DataShareServer]: MyAbilityStage onCreate")
}
}
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Extension from '@ohos.application.DataShareExtensionAbility'
import rdb from '@ohos.data.rdb';
let DB_NAME = "book.db";
let TBL_NAME = "book";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, introduction TEXT NOT NULL)";
let rdbStore;
function sleep(time) {
return new Promise(resolve =>
setTimeout(resolve,time)
) } async function output() {
let out = await sleep(1000);
console.log('1');
return out;
}
export default class DataShareExtAbility extends Extension {
async onCreate(want, callback) {
console.log('[DataShareServer]: DataShareExtAbility onCreate, want:' + want.abilityName);
console.log('[DataShareServer]: DataShareExtAbility onCreate this.context.databaseDir:' + this.context.databaseDir);
// @ts-ignore
rdbStore = await rdb.getRdbStore(this.context, { name: DB_NAME }, 1);
console.log('[DataShareServer]: DataShareExtAbility getRdbStore done');
await rdbStore.executeSql(DDL_TBL_CREATE, []);
console.log('[DataShareServer]: DataShareExtAbility executeSql done');
let err = {"code":0};
callback(err);
console.log('[DataShareServer]: DataShareExtAbility onCreate end');
}
async getFileTypes(uri: string, mimeTypeFilter: string, callback) {
console.log('[DataShareServer]: [getFileTypes] enter');
let ret = new Array("type01", "type00", "type03");
console.log('[DataShareServer]: [getFileTypes] leave, ret:' + ret);
let err = {"code":0};
await callback(err,ret);
return ret;
}
async openFile(uri: string, mode: string, callback) {
console.log('[DataShareServer]: [openFile] enter');
let ret = 1;
let err = {"code":0};
await callback(err,ret);
console.log('[DataShareServer]: [openFile] leave, ret:' + ret);
}
async insert(uri, value, callback) {
console.log('[DataShareServer]: [insert] enter');
if (value == null) {
console.error('[DataShareServer]: [insert] invalid valueBuckets');
return;
}
console.log('[DataShareServer]: [insert] value = ' + value);
console.log('[DataShareServer]: [insert] value = ' + JSON.stringify(value));
await rdbStore.insert(TBL_NAME, value, function (err, ret) {
console.log('[DataShareServer]: <<Provider>> [insert] callback ret:' + ret);
if (callback != undefined) {
callback(err, ret);
}
});
console.log('[DataShareServer]: [insert] leave');
}
async update(uri, predicates, value, callback) {
console.log('[DataShareServer]: [update] enter');
if (predicates == null || predicates == undefined) {
console.error('[DataShareServer]: <<Provider>> [update] invalid predicates');
return;
}
console.log('[DataShareServer]: [update] values = ' + value);
console.log('[DataShareServer]: [update] values = ' + JSON.stringify(value));
console.log('[DataShareServer]: [update] predicates = ' + predicates);
console.log('[DataShareServer]: [update] predicates = ' + JSON.stringify(predicates));
try {
await rdbStore.update(TBL_NAME, value, predicates, function (err, ret) {
console.log('[DataShareServer]: [update] callback ret:' + ret);
console.log('[DataShareServer]: [update] callback err:' + err);
if (callback != undefined) {
callback(err, ret);
}
});
} catch (err) {
console.error('[DataShareServer]: [update] error' + err);
}
sleep(1);
console.log('[DataShareServer]: [update] leave');
}
async delete(uri, predicates, callback) {
console.log('[DataShareServer]: [delete] enter');
if (predicates == null || predicates == undefined) {
console.error('[DataShareServer]: [delete] invalid predicates');
return;
}
console.log('[DataShareServer]: [delete] predicates = ' + predicates);
console.log('[DataShareServer]: [delete] predicates = ' + JSON.stringify(predicates));
try {
await rdbStore.delete(TBL_NAME, predicates, function (err, ret) {
console.log('[DataShareServer]: [delete] ret:' + ret);
if (callback != undefined) {
callback(err, ret);
}
});
} catch (err) {
console.error('[DataShareServer]: [delete] error' + err);
}
console.log('[DataShareServer]: [delete] leave');
}
async query(uri, predicates, columns, callback) {
console.log('[DataShareServer]: [query] enter');
if (predicates == null || predicates == undefined) {
console.error('[DataShareServer]: [query] invalid predicates');
}
console.log('[DataShareServer]: [query] values = ' + columns);
console.log('[DataShareServer]: [query] values = ' + JSON.stringify(columns));
console.log('[DataShareServer]: [query] predicates = ' + predicates);
console.log('[DataShareServer]: [query] predicates = ' + JSON.stringify(predicates));
try {
await rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) {
console.log('[DataShareServer]: [query] ret: ' + resultSet);
if (resultSet != undefined) {
console.log('[DataShareServer]: [query] resultSet.rowCount: ' + resultSet.rowCount);
}
if (callback != undefined) {
callback(err, resultSet);
}
});
} catch (err) {
console.error('[DataShareServer]: [query] error' + err);
}
console.log('[DataShareServer]: [query] leave');
}
async getType(uri: string, callback) {
console.log('[DataShareServer]: [getType] enter');
let ret = "image";
console.log('[DataShareServer]: [getType] leave, ret:' + ret);
let err = {"code":0};
await callback(err,ret);
return ret;
}
async batchInsert(uri: string, valueBuckets, callback) {
console.log('[DataShareServer]: [batchInsert] enter');
if (valueBuckets == null || valueBuckets.length == undefined) {
console.error('[DataShareServer]: <<Provider>> [batchInsert] invalid valueBuckets');
return;
}
console.log('[DataShareServer]: [batchInsert] valueBuckets.length:' + valueBuckets.length);
let resultNum = valueBuckets.length
await valueBuckets.forEach(vb => {
console.log('[DataShareServer]: [batchInsert] vb:' + JSON.stringify(vb));
rdbStore.insert(TBL_NAME, vb, function (err, ret) {
console.log('[DataShareServer]: [batchInsert] callback ret:' + ret);
if (callback != undefined) {
callback(err, resultNum);
}
});
});
console.log('[DataShareServer]: [batchInsert] leave');
}
async normalizeUri(uri: string, callback) {
console.log('[DataShareServer]: [normalizeUri] enter');
let ret = uri;
let err = {"code":0};
await callback(err, ret);
console.log('[DataShareServer]: [normalizeUri] leave, ret:' + ret);
}
async denormalizeUri(uri: string, callback) {
console.log('[DataShareServer]: [denormalizeUri] enter');
let ret = uri;
let err = {"code":0};
await callback(err, ret);
console.log('[DataShareServer]: [denormalizeUri] leave, ret:' + ret);
}
};
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
console.log("[DataShareServer]: MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
console.log("[DataShareServer]: MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[DataShareServer]: MainAbility onWindowStageCreate")
windowStage.loadContent("pages/index", (err, data) => {
if (err.code) {
console.error("[DataShareServer]: Failed to load the content. Cause: " + JSON.stringify(err));
return;
}
console.log("[DataShareServer]: Succeeded in loading the content. Data: " + JSON.stringify(data))
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[DataShareServer]: MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[DataShareServer]: MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[DataShareServer]: MainAbility onBackground")
}
};
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct Index {
@State message: string = 'stagemode: datashare server'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "entry",
"srcEntrance": "./ets/Application/MyAbilityStage.ts",
"description": "$string:entry_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:white",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
"extensionAbilities": [
{
"srcEntrance": "./ets/DataShareExtAbility/DataShareExtAbility.ts",
"name": "DataShareExtAbility",
"icon": "$media:icon",
"description": "$string:DataShareExtAbility_desc",
"type": "dataShare",
"uri": "datashare://com.example.dataabilityserver_fa.DataAbility",
"visible": true
}
]
}
}
\ No newline at end of file
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "DataShareExtAbility_desc",
"value": "description"
},
{
"name": "DataShareExtAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"forms": [
{
"name": "widget",
"description": "This is a service widget.",
"src": "./js/widget/pages/index/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
"isDefault": true,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"defaultDimension": "2*2",
"supportDimensions": [
"2*2"
]
},
{
"name": "widget",
"description": "This is a service widget.",
"src": "./js/widget/pages/index/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
"isDefault": true,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"defaultDimension": "2*2",
"supportDimensions": [
"2*2"
]
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册