Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
536e4ba0
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
536e4ba0
编写于
6月 01, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 01, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8829 修复uri临时授权xts
Merge pull request !8829 from 于文泽/master
上级
573ab70d
15cb1c64
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
162 addition
and
153 deletion
+162
-153
ability/ability_runtime/stage/actsuripermission/actsassistanthap/entry/src/main/ets/Hap2MainAbility4/Hap2MainAbility4.ts
...p/entry/src/main/ets/Hap2MainAbility4/Hap2MainAbility4.ts
+84
-80
ability/ability_runtime/stage/actsuripermission/actsassistanthap2/entry/src/main/ets/Hap3MainAbility1/Hap3MainAbility1.ts
...2/entry/src/main/ets/Hap3MainAbility1/Hap3MainAbility1.ts
+78
-73
未找到文件。
ability/ability_runtime/stage/actsuripermission/actsassistanthap/entry/src/main/ets/Hap2MainAbility4/Hap2MainAbility4.ts
浏览文件 @
536e4ba0
...
...
@@ -15,97 +15,101 @@
import
Ability
from
'
@ohos.app.ability.UIAbility
'
import
commonEvent
from
'
@ohos.commonEvent
'
;
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
))
}
export
default
class
Hap2MainAbility4
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onCreate
'
)
}
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onCreate
'
)
}
onDestroy
()
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onDestroy
'
)
}
onDestroy
()
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onDestroy
'
)
}
onWindowStageCreate
(
windowStage
)
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onWindowStageCreate
'
)
windowStage
.
setUIContent
(
this
.
context
,
'
pages/Hap2MainAbility4_pages
'
,
null
)
}
onWindowStageDestroy
()
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onWindowStageDestroy
'
)
}
onWindowStageCreate
(
windowStage
)
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onWindowStageCreate
'
)
windowStage
.
setUIContent
(
this
.
context
,
'
pages/Hap2MainAbility4_pages
'
,
null
)
onForeground
()
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onForeground
'
)
let
uri
:
string
=
globalThis
.
abilityWant3
.
uri
;
if
(
uri
==
null
)
{
console
.
log
(
'
[Demo] Hap2MainAbility1 uri is invalid
'
);
return
;
}
let
eventName1
:
string
=
'
Temp_UriPermissionTest_0300_Read_Successfully
'
;
let
eventName2
:
string
=
'
Temp_UriPermissionTest_0300_Read_Failed
'
;
globalThis
.
fs
.
open
(
uri
,
globalThis
.
fs
.
OpenMode
.
READ_ONLY
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName1
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName1
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName2
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName2
);
});
});
onWindowStageDestroy
()
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onWindowStageDestroy
'
)
let
eventName3
:
string
=
'
Temp_UriPermissionTest_0300_Write_Successfully
'
;
let
eventName4
:
string
=
'
Temp_UriPermissionTest_0300_Write_Failed
'
;
globalThis
.
fs
.
open
(
uri
,
globalThis
.
fs
.
OpenMode
.
READ_WRITE
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName3
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName3
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName4
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName4
);
});
});
let
eventName5
:
string
=
'
TerminateDone_Hap2MainAbility3
'
;
let
subscribeInfo
=
{
events
:
[
eventName5
]
}
onForeground
()
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onForeground
'
)
let
uri
:
string
=
globalThis
.
abilityWant3
.
uri
;
if
(
uri
==
null
)
{
console
.
log
(
'
[Demo] Hap2MainAbility1 uri is invalid
'
);
return
;
}
let
eventName1
:
string
=
'
Temp_UriPermissionTest_0300_Read_Successfully
'
;
let
eventName2
:
string
=
'
Temp_UriPermissionTest_0300_Read_Failed
'
;
let
eventName6
:
string
=
'
Temp_UriPermissionTest_0300_Read_Successfully_
'
;
let
eventName7
:
string
=
'
Temp_UriPermissionTest_0300_Read_Failed_
'
;
async
function
SubscribeCallBackContext
(
err
,
data
)
{
console
.
log
(
'
Subscribe CallBack data:
'
+
JSON
.
stringify
(
data
));
if
(
data
.
event
===
eventName5
)
{
await
sleep
(
1000
);
globalThis
.
fs
.
open
(
uri
,
globalThis
.
fs
.
OpenMode
.
READ_ONLY
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName1
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName1
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName2
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName2
);
});
});
let
eventName3
:
string
=
'
Temp_UriPermissionTest_0300_Write_Successfully
'
;
let
eventName4
:
string
=
'
Temp_UriPermissionTest_0300_Write_Failed
'
;
globalThis
.
fs
.
open
(
uri
,
globalThis
.
fs
.
OpenMode
.
READ_WRITE
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName3
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName3
);
});
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName6
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName6
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName4
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName4
);
});
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName7
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName7
);
});
});
}
}
let
eventName5
:
string
=
'
TerminateDone_Hap2MainAbility3
'
;
let
subscribeInfo
=
{
events
:
[
eventName5
]
}
let
eventName6
:
string
=
'
Temp_UriPermissionTest_0300_Read_Successfully_
'
;
let
eventName7
:
string
=
'
Temp_UriPermissionTest_0300_Read_Failed_
'
;
function
SubscribeCallBackContext
(
err
,
data
)
{
console
.
log
(
'
Subscribe CallBack data:
'
+
JSON
.
stringify
(
data
));
if
(
data
.
event
===
eventName5
)
{
globalThis
.
fs
.
open
(
uri
,
globalThis
.
fs
.
OpenMode
.
READ_ONLY
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName6
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName6
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName7
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName7
);
});
});
}
}
let
subscriber__1
;
commonEvent
.
createSubscriber
(
subscribeInfo
).
then
(
async
(
data
)
=>
{
subscriber__1
=
data
;
console
.
debug
(
'
====>Create Subscriber====>
'
);
await
commonEvent
.
subscribe
(
subscriber__1
,
SubscribeCallBackContext
);
});
let
subscriber__1
;
commonEvent
.
createSubscriber
(
subscribeInfo
).
then
(
async
(
data
)
=>
{
subscriber__1
=
data
;
console
.
debug
(
'
====>Create Subscriber====>
'
);
await
commonEvent
.
subscribe
(
subscriber__1
,
SubscribeCallBackContext
);
});
let
eventName
:
string
=
'
TerminateSelf_Hap2MainAbility3
'
;
commonEvent
.
publish
(
eventName
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName
);
});
}
let
eventName
:
string
=
'
TerminateSelf_Hap2MainAbility3
'
;
commonEvent
.
publish
(
eventName
,
(
err
)
=>
{
console
.
log
(
'
Hap2MainAbility4
'
+
eventName
);
});
}
onBackground
()
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onBackground
'
)
}
onBackground
()
{
console
.
log
(
'
[Demo] Hap2MainAbility4 onBackground
'
)
}
};
ability/ability_runtime/stage/actsuripermission/actsassistanthap2/entry/src/main/ets/Hap3MainAbility1/Hap3MainAbility1.ts
浏览文件 @
536e4ba0
...
...
@@ -17,89 +17,94 @@ import Ability from '@ohos.app.ability.UIAbility'
import
commonEvent
from
'
@ohos.commonEvent
'
;
import
fs
from
'
@ohos.file.fs
'
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
))
}
export
default
class
Hap3MainAbility1
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onCreate
'
)
globalThis
.
abilityWant
=
want
;
}
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onCreate
'
)
globalThis
.
abilityWant
=
want
;
}
onDestroy
()
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onDestroy
'
)
}
onDestroy
()
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onDestroy
'
)
}
onWindowStageCreate
(
windowStage
)
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onWindowStageCreate
'
)
windowStage
.
setUIContent
(
this
.
context
,
'
pages/Hap3MainAbility1_pages
'
,
null
)
}
onWindowStageCreate
(
windowStage
)
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onWindowStageCreate
'
)
windowStage
.
setUIContent
(
this
.
context
,
'
pages/Hap3MainAbility1_pages
'
,
null
)
}
onWindowStageDestroy
()
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onWindowStageDestroy
'
)
}
onForeground
()
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onForeground
'
)
let
eventName
:
string
=
'
TerminateNotify_Hap3MainAbility1
'
;
let
subscribeInfo
=
{
events
:
[
eventName
]
}
let
subscriber_1
;
function
UnSubscribeInfoCallback_1
(
err
,
data
)
{
console
.
info
(
"
Hap2MainAbility1 ===UnSubscribeInfoCallback_1===
"
)
}
onWindowStageDestroy
()
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onWindowStageDestroy
'
)
}
function
SubscribeCallBackContext
(
err
,
data
)
{
console
.
log
(
'
Hap3MainAbility1 Subscribe CallBack data:
'
+
JSON
.
stringify
(
data
));
if
(
data
.
event
===
eventName
)
{
let
uri
:
string
=
globalThis
.
abilityWant
.
uri
;
if
(
uri
==
null
)
{
console
.
log
(
'
[Demo] Hap3MainAbility1 uri is invalid
'
);
return
;
}
console
.
info
(
'
[Demo] Hap3MainAbility1 uri is
'
+
JSON
.
stringify
(
uri
));
let
eventName13_1
:
string
=
'
Temp_UriPermissionTest_1300_Read_Successfully
'
;
let
eventName13_2
:
string
=
'
Temp_UriPermissionTest_1300_Read_Failed
'
;
fs
.
open
(
uri
,
fs
.
OpenMode
.
READ_ONLY
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName13_1
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName13_1
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName13_2
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName13_2
);
});
});
onForeground
()
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onForeground
'
)
let
eventName
:
string
=
'
TerminateNotify_Hap3MainAbility1
'
;
let
subscribeInfo
=
{
events
:
[
eventName
]
}
let
subscriber_1
;
function
UnSubscribeInfoCallback_1
(
err
,
data
)
{
console
.
info
(
"
Hap2MainAbility1 ===UnSubscribeInfoCallback_1===
"
)
}
let
eventName13_3
:
string
=
'
Temp_UriPermissionTest_1300_Write_Successfully
'
;
let
eventName13_4
:
string
=
'
Temp_UriPermissionTest_1300_Write_Failed
'
;
fs
.
open
(
uri
,
fs
.
OpenMode
.
READ_WRITE
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName13_3
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName13_3
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName13_4
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName13_4
);
});
});
}
commonEvent
.
unsubscribe
(
subscriber_1
,
UnSubscribeInfoCallback_1
)
async
function
SubscribeCallBackContext
(
err
,
data
)
{
console
.
log
(
'
Hap3MainAbility1 Subscribe CallBack data:
'
+
JSON
.
stringify
(
data
));
if
(
data
.
event
===
eventName
)
{
await
sleep
(
1000
);
let
uri
:
string
=
globalThis
.
abilityWant
.
uri
;
if
(
uri
==
null
)
{
console
.
log
(
'
[Demo] Hap3MainAbility1 uri is invalid
'
);
return
;
}
commonEvent
.
createSubscriber
(
subscribeInfo
).
then
(
async
(
data
)
=>
{
subscriber_1
=
data
;
console
.
debug
(
'
====>Create Subscriber====>
'
);
await
commonEvent
.
subscribe
(
subscriber_1
,
SubscribeCallBackContext
);
console
.
info
(
'
[Demo] Hap3MainAbility1 uri is
'
+
JSON
.
stringify
(
uri
));
let
eventName13_1
:
string
=
'
Temp_UriPermissionTest_1300_Read_Successfully
'
;
let
eventName13_2
:
string
=
'
Temp_UriPermissionTest_1300_Read_Failed
'
;
fs
.
open
(
uri
,
fs
.
OpenMode
.
READ_ONLY
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName13_1
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName13_1
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName13_2
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName13_2
);
});
});
let
eventName1
:
string
=
'
RevicedFrom_Hap3MainAbility1
'
;
commonEvent
.
publish
(
eventName1
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName1
);
let
eventName13_3
:
string
=
'
Temp_UriPermissionTest_1300_Write_Successfully
'
;
let
eventName13_4
:
string
=
'
Temp_UriPermissionTest_1300_Write_Failed
'
;
fs
.
open
(
uri
,
fs
.
OpenMode
.
READ_WRITE
).
then
((
file
)
=>
{
console
.
info
(
'
file fd:
'
+
file
.
fd
);
commonEvent
.
publish
(
eventName13_3
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName13_3
);
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
open file failed with error message:
'
+
err
.
message
+
'
, error code:
'
+
err
.
code
);
commonEvent
.
publish
(
eventName13_4
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName13_4
);
});
});
}
commonEvent
.
unsubscribe
(
subscriber_1
,
UnSubscribeInfoCallback_1
)
}
onBackground
()
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onBackground
'
)
}
commonEvent
.
createSubscriber
(
subscribeInfo
).
then
(
async
(
data
)
=>
{
subscriber_1
=
data
;
console
.
debug
(
'
====>Create Subscriber====>
'
);
await
commonEvent
.
subscribe
(
subscriber_1
,
SubscribeCallBackContext
);
});
let
eventName1
:
string
=
'
RevicedFrom_Hap3MainAbility1
'
;
commonEvent
.
publish
(
eventName1
,
(
err
)
=>
{
console
.
log
(
'
Hap3MainAbility1
'
+
eventName1
);
});
}
onBackground
()
{
console
.
log
(
'
[Demo] Hap3MainAbility1 onBackground
'
)
}
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录