mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
@@ -22,10 +22,10 @@ const ERROR_CODE_CALLER_RELEASED = 16200001;
|
||||
const ERROR_CODE_CLAAEE_INVALID = 16200002;
|
||||
const ERROR_CODE_INNER_ERROR = 16000050;
|
||||
|
||||
const ERROR_MSG_INVALID_PARAM = "Invalid input parameter.";
|
||||
const ERROR_MSG_CALLER_RELEASED = "Caller released. The caller has been released.";
|
||||
const ERROR_MSG_CLAAEE_INVALID = "Callee invalid. The callee does not exist.";
|
||||
const ERROR_MSG_INNER_ERROR = "Inner Error.";
|
||||
const ERROR_MSG_INVALID_PARAM = 'Invalid input parameter.';
|
||||
const ERROR_MSG_CALLER_RELEASED = 'Caller released. The caller has been released.';
|
||||
const ERROR_MSG_CLAAEE_INVALID = 'Callee invalid. The callee does not exist.';
|
||||
const ERROR_MSG_INNER_ERROR = 'Inner Error.';
|
||||
|
||||
var errMap = new Map();
|
||||
errMap.set(ERROR_CODE_INVALID_PARAM, ERROR_MSG_INVALID_PARAM);
|
||||
@@ -48,39 +48,39 @@ class BusinessError extends Error {
|
||||
|
||||
class Caller {
|
||||
constructor(obj) {
|
||||
console.log("Caller::constructor obj is " + typeof obj);
|
||||
console.log('Caller::constructor obj is ' + typeof obj);
|
||||
this.__call_obj__ = obj;
|
||||
this.releaseState = false;
|
||||
}
|
||||
|
||||
call(method, data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
console.log("Caller call method [" + method + "]");
|
||||
console.log('Caller call method [' + method + ']');
|
||||
if (typeof method !== 'string' || typeof data !== 'object') {
|
||||
console.log("Caller call " + typeof method + " " + typeof data);
|
||||
console.log('Caller call ' + typeof method + ' ' + typeof data);
|
||||
reject(new BusinessError(ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (method == '' || data == null) {
|
||||
console.log("Caller call " + method + ", " + data);
|
||||
console.log('Caller call ' + method + ', ' + data);
|
||||
reject(new BusinessError(ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.releaseState == true) {
|
||||
console.log("Caller call this.callee release");
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller call this.callee release');
|
||||
reject(new BusinessError(ERROR_CODE_CALLER_RELEASED));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.__call_obj__.callee == null) {
|
||||
console.log("Caller call this.callee is nullptr");
|
||||
console.log('Caller call this.callee is nullptr');
|
||||
reject(new BusinessError(ERROR_CODE_CLAAEE_INVALID));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Caller call msgData rpc.MessageSequence create");
|
||||
console.log('Caller call msgData rpc.MessageSequence create');
|
||||
let msgData = rpc.MessageSequence.create();
|
||||
msgData.writeString(method);
|
||||
let msgReply = rpc.MessageSequence.create();
|
||||
@@ -90,39 +90,39 @@ class Caller {
|
||||
let retData = undefined;
|
||||
try {
|
||||
retData = await this.__call_obj__.callee.sendMessageRequest(EVENT_CALL_NOTIFY, msgData, msgReply, option);
|
||||
console.log("Caller call msgData rpc.sendMessageRequest called");
|
||||
console.log('Caller call msgData rpc.sendMessageRequest called');
|
||||
if (retData.errCode != 0) {
|
||||
msgData.reclaim();
|
||||
msgReply.reclaim();
|
||||
console.log("Caller call return errCode " + retData.errCode);
|
||||
console.log('Caller call return errCode ' + retData.errCode);
|
||||
reject(new BusinessError(retData.errCode));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Caller call msgData rpc.sendMessageRequest error " + e);
|
||||
console.log('Caller call msgData rpc.sendMessageRequest error ' + e);
|
||||
}
|
||||
|
||||
try {
|
||||
let retval = retData.reply.readInt();
|
||||
let str = retData.reply.readString();
|
||||
if (retval === REQUEST_SUCCESS && str === 'object') {
|
||||
console.log("Caller call return str " + str);
|
||||
console.log('Caller call return str ' + str);
|
||||
msgData.reclaim();
|
||||
msgReply.reclaim();
|
||||
} else {
|
||||
console.log("Caller call retval is [" + retval + "], str [" + str + "]");
|
||||
console.log('Caller call retval is [' + retval + '], str [' + str + ']');
|
||||
msgData.reclaim();
|
||||
msgReply.reclaim();
|
||||
reject(new BusinessError(retval));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Caller call msgData sendMessageRequest retval error");
|
||||
console.log('Caller call msgData sendMessageRequest retval error');
|
||||
reject(new BusinessError(ERROR_CODE_INNER_ERROR));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Caller call msgData sendMessageRequest end");
|
||||
console.log('Caller call msgData sendMessageRequest end');
|
||||
resolve(undefined);
|
||||
return;
|
||||
});
|
||||
@@ -130,32 +130,32 @@ class Caller {
|
||||
|
||||
callWithResult(method, data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
console.log("Caller callWithResult method [" + method + "]");
|
||||
console.log('Caller callWithResult method [' + method + ']');
|
||||
if (typeof method !== 'string' || typeof data !== 'object') {
|
||||
console.log("Caller callWithResult " + typeof method + " " + typeof data);
|
||||
console.log('Caller callWithResult ' + typeof method + ' ' + typeof data);
|
||||
reject(new BusinessError(ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (method == '' || data == null) {
|
||||
console.log("Caller callWithResult " + method + ", " + data);
|
||||
console.log('Caller callWithResult ' + method + ', ' + data);
|
||||
reject(new BusinessError(ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.releaseState == true) {
|
||||
console.log("Caller callWithResult this.callee release");
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller callWithResult this.callee release');
|
||||
reject(new BusinessError(ERROR_CODE_CALLER_RELEASED));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.__call_obj__.callee == null) {
|
||||
console.log("Caller callWithResult this.callee is nullptr");
|
||||
console.log('Caller callWithResult this.callee is nullptr');
|
||||
reject(new BusinessError(ERROR_CODE_CLAAEE_INVALID));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Caller callWithResult msgData rpc.MessageSequence create");
|
||||
console.log('Caller callWithResult msgData rpc.MessageSequence create');
|
||||
let msgData = rpc.MessageSequence.create();
|
||||
msgData.writeString(method);
|
||||
let msgReply = rpc.MessageSequence.create();
|
||||
@@ -166,53 +166,53 @@ class Caller {
|
||||
let retData = undefined;
|
||||
try {
|
||||
retData = await this.__call_obj__.callee.sendMessageRequest(EVENT_CALL_NOTIFY, msgData, msgReply, option);
|
||||
console.log("Caller callWithResult msgData rpc.sendMessageRequest called");
|
||||
console.log('Caller callWithResult msgData rpc.sendMessageRequest called');
|
||||
if (retData.errCode != 0) {
|
||||
msgData.reclaim();
|
||||
msgReply.reclaim();
|
||||
console.log("Caller callWithResult return errCode " + retData.errCode);
|
||||
console.log('Caller callWithResult return errCode ' + retData.errCode);
|
||||
reject(new BusinessError(retData.errCode));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Caller call msgData rpc.MessageSequence error " + e);
|
||||
console.log('Caller call msgData rpc.MessageSequence error ' + e);
|
||||
}
|
||||
|
||||
try {
|
||||
let retval = retData.reply.readInt();
|
||||
let str = retData.reply.readString();
|
||||
if (retval === REQUEST_SUCCESS && str === 'object') {
|
||||
console.log("Caller callWithResult return str " + str);
|
||||
console.log('Caller callWithResult return str ' + str);
|
||||
msgData.reclaim();
|
||||
reply = retData.reply;
|
||||
} else {
|
||||
console.log("Caller callWithResult retval is [" + retval + "], str [" + str + "]");
|
||||
console.log('Caller callWithResult retval is [' + retval + '], str [' + str + ']');
|
||||
msgData.reclaim();
|
||||
msgReply.reclaim();
|
||||
reject(new BusinessError(retval));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Caller callWithResult msgData sendMessageRequest retval error");
|
||||
console.log('Caller callWithResult msgData sendMessageRequest retval error');
|
||||
reject(new BusinessError(ERROR_CODE_INNER_ERROR));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Caller callWithResult msgData sendMessageRequest end");
|
||||
console.log('Caller callWithResult msgData sendMessageRequest end');
|
||||
resolve(reply);
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
release() {
|
||||
console.log("Caller release js called.");
|
||||
if (this.releaseState == true) {
|
||||
console.log("Caller release remoteObj releaseState is true");
|
||||
console.log('Caller release js called.');
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller release remoteObj releaseState is true');
|
||||
throw new BusinessError(ERROR_CODE_CALLER_RELEASED);
|
||||
}
|
||||
|
||||
if (this.__call_obj__.callee == null) {
|
||||
console.log("Caller release call remoteObj is released");
|
||||
console.log('Caller release call remoteObj is released');
|
||||
throw new BusinessError(ERROR_CODE_CLAAEE_INVALID);
|
||||
}
|
||||
|
||||
@@ -221,14 +221,14 @@ class Caller {
|
||||
}
|
||||
|
||||
onRelease(callback) {
|
||||
console.log("Caller onRelease jscallback called.");
|
||||
console.log('Caller onRelease jscallback called.');
|
||||
if (typeof callback !== 'function') {
|
||||
console.log("Caller onRelease " + typeof callback);
|
||||
console.log('Caller onRelease ' + typeof callback);
|
||||
throw new BusinessError(ERROR_CODE_INVALID_PARAM);
|
||||
}
|
||||
|
||||
if (this.releaseState == true) {
|
||||
console.log("Caller onRelease remoteObj releaseState is true");
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller onRelease remoteObj releaseState is true');
|
||||
throw new BusinessError(ERROR_CODE_CALLER_RELEASED);
|
||||
}
|
||||
|
||||
@@ -236,14 +236,14 @@ class Caller {
|
||||
}
|
||||
|
||||
onRemoteStateChange(callback) {
|
||||
console.log("Caller onRemoteStateChange jscallback called.");
|
||||
console.log('Caller onRemoteStateChange jscallback called.');
|
||||
if (typeof callback !== 'function') {
|
||||
console.log("Caller onRemoteStateChange " + typeof callback);
|
||||
console.log('Caller onRemoteStateChange ' + typeof callback);
|
||||
throw new BusinessError(ERROR_CODE_INVALID_PARAM);
|
||||
}
|
||||
|
||||
if (this.releaseState == true) {
|
||||
console.log("Caller onRemoteStateChange remoteObj releaseState is true");
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller onRemoteStateChange remoteObj releaseState is true');
|
||||
throw new BusinessError(ERROR_CODE_CALLER_RELEASED);
|
||||
}
|
||||
|
||||
@@ -251,20 +251,20 @@ class Caller {
|
||||
}
|
||||
|
||||
on(type, callback) {
|
||||
console.log("Caller onRelease jscallback called.");
|
||||
if (typeof type !== 'string' || type !== "release") {
|
||||
console.log('Caller onRelease jscallback called.');
|
||||
if (typeof type !== 'string' || type !== 'release') {
|
||||
console.log(
|
||||
"Caller onRelease error, input [type] is invalid.");
|
||||
'Caller onRelease error, input [type] is invalid.');
|
||||
throw new BusinessError(ERROR_CODE_INVALID_PARAM);
|
||||
}
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
console.log("Caller onRelease error " + typeof callback);
|
||||
console.log('Caller onRelease error ' + typeof callback);
|
||||
throw new BusinessError(ERROR_CODE_INVALID_PARAM);
|
||||
}
|
||||
|
||||
if (this.releaseState == true) {
|
||||
console.log("Caller onRelease error, remoteObj releaseState is true");
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller onRelease error, remoteObj releaseState is true');
|
||||
throw new BusinessError(ERROR_CODE_CALLER_RELEASED);
|
||||
}
|
||||
|
||||
@@ -272,14 +272,14 @@ class Caller {
|
||||
}
|
||||
|
||||
off(type, callback) {
|
||||
if (typeof type !== 'string' || type !== "release") {
|
||||
if (typeof type !== 'string' || type !== 'release') {
|
||||
console.log(
|
||||
"Caller onRelease error, input [type] is invalid.");
|
||||
'Caller onRelease error, input [type] is invalid.');
|
||||
throw new BusinessError(ERROR_CODE_INVALID_PARAM);
|
||||
}
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
console.log("Caller onRelease error " + typeof callback);
|
||||
console.log('Caller onRelease error ' + typeof callback);
|
||||
throw new BusinessError(ERROR_CODE_INVALID_PARAM);
|
||||
}
|
||||
// Empty
|
||||
|
||||
@@ -3335,7 +3335,7 @@ void UvWorkOnAbilityConnectDone(uv_work_t *work, int status)
|
||||
|
||||
void NAPIAbilityConnection::HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(callback.env, &loop);
|
||||
if (loop == nullptr) {
|
||||
@@ -3396,7 +3396,7 @@ void NAPIAbilityConnection::OnAbilityConnectDone(
|
||||
HandleOnAbilityConnectDone(*callback, resultCode);
|
||||
}
|
||||
connectionState_ = CONNECTION_STATE_CONNECTED;
|
||||
HILOG_INFO("%{public}s, end.", __func__);
|
||||
HILOG_INFO("%{public}s, end.", __func__);
|
||||
}
|
||||
|
||||
void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status)
|
||||
@@ -3456,7 +3456,7 @@ void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status)
|
||||
|
||||
void NAPIAbilityConnection::HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(callback.env, &loop);
|
||||
if (loop == nullptr) {
|
||||
@@ -3511,7 +3511,7 @@ void NAPIAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementNam
|
||||
HandleOnAbilityDisconnectDone(*callback, resultCode);
|
||||
}
|
||||
connectionState_ = CONNECTION_STATE_DISCONNECTED;
|
||||
HILOG_INFO("%{public}s, end.", __func__);
|
||||
HILOG_INFO("%{public}s, end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4144,9 +4144,9 @@ sptr<NAPIAbilityConnection> JsNapiCommon::FindConnectionLocked(const Want &want,
|
||||
HILOG_DEBUG("find connection exist");
|
||||
auto connection = iter->second;
|
||||
if (connection == nullptr) {
|
||||
HILOG_ERROR("connection is nullptr");
|
||||
connects_.erase(iter);
|
||||
return nullptr;
|
||||
HILOG_ERROR("connection is nullptr");
|
||||
connects_.erase(iter);
|
||||
return nullptr;
|
||||
}
|
||||
id = iter->first.id;
|
||||
return connection;
|
||||
|
||||
@@ -35,7 +35,7 @@ bool JsQuickfixCallback::operator()(std::string baseFileName, std::string &patch
|
||||
HILOG_ERROR("invalid baseFileName!");
|
||||
return false;
|
||||
}
|
||||
int baseFileNameLen = baseFileName.length();
|
||||
int baseFileNameLen = static_cast<int>(baseFileName.length());
|
||||
int prefixLen = strlen(BUNDLE_INSTALL_PATH);
|
||||
int suffixLen = strlen(MERGE_ABC_PATH);
|
||||
int moduleLen = baseFileNameLen - prefixLen - suffixLen;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace AbilityRuntime {
|
||||
class JsRuntime;
|
||||
class JsQuickfixCallback final {
|
||||
public:
|
||||
explicit JsQuickfixCallback(std::map<std::string, std::string> moduleAndHqfPath) :
|
||||
explicit JsQuickfixCallback(const std::map<std::string, std::string> moduleAndHqfPath) :
|
||||
moduleAndHqfPath_(moduleAndHqfPath) {};
|
||||
~JsQuickfixCallback() = default;
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ void ComponentInterceptionProxy::NotifyHandleAbilityStateChange(const sptr<IRemo
|
||||
}
|
||||
|
||||
bool ComponentInterceptionProxy::ReleaseCallInterception(const sptr<IRemoteObject> &connect,
|
||||
const AppExecFwk::ElementName &element, sptr<Want> &extraParam)
|
||||
const AppExecFwk::ElementName &element, sptr<Want> &extraParam)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
@@ -38,10 +38,6 @@ std::string UncaughtExceptionCallback::GetNativeStrFromJsTaggedObj(NativeObject*
|
||||
size_t valueStrBufLength = valueStr->GetLength();
|
||||
size_t valueStrLength = 0;
|
||||
auto valueCStr = std::make_unique<char[]>(valueStrBufLength + 1);
|
||||
if (valueCStr == nullptr) {
|
||||
JSENV_LOG_E("Failed to new valueCStr.");
|
||||
return "";
|
||||
}
|
||||
|
||||
valueStr->GetCString(valueCStr.get(), valueStrBufLength + 1, &valueStrLength);
|
||||
std::string ret(valueCStr.get(), valueStrLength);
|
||||
|
||||
+20
-20
@@ -18,26 +18,26 @@ import display from '@ohos.display';
|
||||
import extension from '@ohos.app.ability.ServiceExtensionAbility';
|
||||
import window from '@ohos.window';
|
||||
|
||||
const TAG = "JumpInterceptorDialog_Service";
|
||||
const TAG = 'JumpInterceptorDialog_Service';
|
||||
|
||||
var winNum = 1;
|
||||
var win;
|
||||
let winNum = 1;
|
||||
let win;
|
||||
|
||||
export default class JumpInterceptorServiceExtAbility extends extension {
|
||||
onCreate(want) {
|
||||
console.debug(TAG, "onCreate, want: " + JSON.stringify(want));
|
||||
console.debug(TAG, 'onCreate, want: ' + JSON.stringify(want));
|
||||
globalThis.jumpInterceptorExtensionContext = this.context;
|
||||
}
|
||||
|
||||
async onRequest(want, startId) {
|
||||
globalThis.abilityWant = want;
|
||||
globalThis.params = JSON.parse(want["parameters"]["params"]);
|
||||
globalThis.position = JSON.parse(want["parameters"]["position"]);
|
||||
globalThis.interceptor_callerBundleName = want["parameters"]["interceptor_callerBundleName"];
|
||||
globalThis.interceptor_callerModuleName = want["parameters"]["interceptor_callerModuleName"];
|
||||
globalThis.interceptor_callerLabelId = want["parameters"]["interceptor_callerLabelId"];
|
||||
globalThis.interceptor_targetModuleName = want["parameters"]["interceptor_targetModuleName"];
|
||||
globalThis.interceptor_targetLabelId = want["parameters"]["interceptor_targetLabelId"];
|
||||
globalThis.params = JSON.parse(want['parameters']['params']);
|
||||
globalThis.position = JSON.parse(want['parameters']['position']);
|
||||
globalThis.interceptor_callerBundleName = want['parameters']['interceptor_callerBundleName'];
|
||||
globalThis.interceptor_callerModuleName = want['parameters']['interceptor_callerModuleName'];
|
||||
globalThis.interceptor_callerLabelId = want['parameters']['interceptor_callerLabelId'];
|
||||
globalThis.interceptor_targetModuleName = want['parameters']['interceptor_targetModuleName'];
|
||||
globalThis.interceptor_targetLabelId = want['parameters']['interceptor_targetLabelId'];
|
||||
await this.getHapResource();
|
||||
display.getDefaultDisplay().then(dis => {
|
||||
let navigationBarRect = {
|
||||
@@ -51,16 +51,16 @@ export default class JumpInterceptorServiceExtAbility extends extension {
|
||||
winNum--;
|
||||
}
|
||||
if (deviceInfo.deviceType == "phone") {
|
||||
this.createWindow("JumpInterceptorDialog" + startId, window.WindowType.TYPE_SYSTEM_ALERT, navigationBarRect);
|
||||
this.createWindow('JumpInterceptorDialog' + startId, window.WindowType.TYPE_SYSTEM_ALERT, navigationBarRect);
|
||||
} else {
|
||||
this.createWindow("JumpInterceptorDialog" + startId, window.WindowType.TYPE_FLOAT, navigationBarRect);
|
||||
this.createWindow('JumpInterceptorDialog' + startId, window.WindowType.TYPE_FLOAT, navigationBarRect);
|
||||
}
|
||||
winNum++;
|
||||
});
|
||||
}
|
||||
|
||||
async getHapResource() {
|
||||
console.debug(TAG, "start getHapResource");
|
||||
console.debug(TAG, 'start getHapResource');
|
||||
globalThis.callerAppName = await this.loadAppName(
|
||||
globalThis.interceptor_callerBundleName,
|
||||
globalThis.interceptor_callerModuleName,
|
||||
@@ -71,12 +71,12 @@ export default class JumpInterceptorServiceExtAbility extends extension {
|
||||
globalThis.interceptor_targetModuleName,
|
||||
globalThis.interceptor_targetLabelId
|
||||
);
|
||||
console.debug(TAG, "getHapResource load finished");
|
||||
console.debug(TAG, 'getHapResource load finished');
|
||||
}
|
||||
|
||||
async loadAppName(bundleName: string, moduleName: string, labelId: number) {
|
||||
let moduleContext = globalThis.jumpInterceptorExtensionContext.createModuleContext(bundleName, moduleName);
|
||||
let appName: string = "";
|
||||
let appName: string = '';
|
||||
try {
|
||||
appName = await moduleContext.resourceManager.getString(labelId);
|
||||
} catch (error) {
|
||||
@@ -86,20 +86,20 @@ export default class JumpInterceptorServiceExtAbility extends extension {
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
console.info(TAG, "onDestroy.");
|
||||
console.info(TAG, 'onDestroy.');
|
||||
}
|
||||
|
||||
private async createWindow(name: string, windowType: number, rect) {
|
||||
console.info(TAG, "create window");
|
||||
console.info(TAG, 'create window');
|
||||
try {
|
||||
win = await window.create(globalThis.jumpInterceptorExtensionContext, name, windowType);
|
||||
await win.moveTo(rect.left, rect.top);
|
||||
await win.resetSize(rect.width, rect.height);
|
||||
await win.loadContent('pages/jumpInterceptorDialog');
|
||||
await win.setBackgroundColor("#00000000");
|
||||
await win.setBackgroundColor('#00000000');
|
||||
await win.show();
|
||||
} catch {
|
||||
console.error(TAG, "window create failed!");
|
||||
console.error(TAG, 'window create failed!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+34
-34
@@ -20,14 +20,14 @@ import deviceInfo from '@ohos.deviceInfo';
|
||||
import defaultAppManager from '@ohos.bundle.defaultAppManager';
|
||||
import bundleManager from '@ohos.bundle.bundleManager';
|
||||
|
||||
const TAG = "SelectorDialog_Service";
|
||||
const TAG = 'SelectorDialog_Service';
|
||||
|
||||
var winNum = 1;
|
||||
var win;
|
||||
let winNum = 1;
|
||||
let win;
|
||||
|
||||
export default class SelectorServiceExtensionAbility extends extension {
|
||||
onCreate(want) {
|
||||
console.debug(TAG, "onCreate, want: " + JSON.stringify(want));
|
||||
console.debug(TAG, 'onCreate, want: ' + JSON.stringify(want));
|
||||
globalThis.selectExtensionContext = this.context;
|
||||
globalThis.defaultAppManager = defaultAppManager;
|
||||
globalThis.bundleManager = bundleManager;
|
||||
@@ -48,7 +48,7 @@ export default class SelectorServiceExtensionAbility extends extension {
|
||||
}
|
||||
}
|
||||
globalThis.phoneShowHapList = phoneShowHapList;
|
||||
console.debug(TAG, "phoneShowHapList: " + JSON.stringify(phoneShowHapList));
|
||||
console.debug(TAG, 'phoneShowHapList: ' + JSON.stringify(phoneShowHapList));
|
||||
}
|
||||
|
||||
async getPcShowHapList() {
|
||||
@@ -57,18 +57,18 @@ export default class SelectorServiceExtensionAbility extends extension {
|
||||
await this.getHapResource(globalThis.params.hapList[i], pcShowHapList);
|
||||
}
|
||||
globalThis.pcShowHapList = pcShowHapList;
|
||||
console.debug(TAG, "pcShowHapList: " + JSON.stringify(pcShowHapList));
|
||||
console.debug(TAG, 'pcShowHapList: ' + JSON.stringify(pcShowHapList));
|
||||
}
|
||||
|
||||
async getHapResource(hap, showHapList) {
|
||||
let bundleName = hap.bundle;
|
||||
let moduleName = hap.module;
|
||||
let abilityName = hap.ability;
|
||||
let appName = "";
|
||||
let appIcon = "";
|
||||
let type = "";
|
||||
let userId = Number("0");
|
||||
if (globalThis.params.deviceType == "pc") {
|
||||
let appName = '';
|
||||
let appIcon = '';
|
||||
let type = '';
|
||||
let userId = Number('0');
|
||||
if (globalThis.params.deviceType == 'pc') {
|
||||
type = hap.type;
|
||||
userId = Number(hap.userId);
|
||||
}
|
||||
@@ -77,34 +77,34 @@ export default class SelectorServiceExtensionAbility extends extension {
|
||||
await moduleContext.resourceManager.getString(lableId).then(value => {
|
||||
appName = value;
|
||||
}).catch(error => {
|
||||
console.error(TAG, "getString error:" + JSON.stringify(error));
|
||||
console.error(TAG, 'getString error:' + JSON.stringify(error));
|
||||
});
|
||||
|
||||
let iconId = Number(hap.icon);
|
||||
await moduleContext.resourceManager.getMediaBase64(iconId).then(value => {
|
||||
appIcon = value;
|
||||
}).catch(error => {
|
||||
console.error(TAG, "getMediaBase64 error:" + JSON.stringify(error));
|
||||
console.error(TAG, 'getMediaBase64 error:' + JSON.stringify(error));
|
||||
});
|
||||
showHapList.push(bundleName + "#" + abilityName + "#" + appName +
|
||||
"#" + appIcon + "#" + moduleName + "#" + type + "#" + userId);
|
||||
showHapList.push(bundleName + '#' + abilityName + '#' + appName +
|
||||
'#' + appIcon + '#' + moduleName + '#' + type + '#' + userId);
|
||||
}
|
||||
|
||||
async onRequest(want, startId) {
|
||||
console.debug(TAG, "onRequest, want: " + JSON.stringify(want));
|
||||
console.debug(TAG, 'onRequest, want: ' + JSON.stringify(want));
|
||||
globalThis.abilityWant = want;
|
||||
globalThis.params = JSON.parse(want["parameters"]["params"]);
|
||||
globalThis.position = JSON.parse(want["parameters"]["position"]);
|
||||
console.debug(TAG, "onRequest, want: " + JSON.stringify(want));
|
||||
console.debug(TAG, "onRequest, params: " + JSON.stringify(globalThis.params));
|
||||
globalThis.callerToken = want["parameters"]["callerToken"];
|
||||
console.debug(TAG, "onRequest, params: " + JSON.stringify(globalThis.params));
|
||||
console.debug(TAG, "onRequest, position: " + JSON.stringify(globalThis.position));
|
||||
if (globalThis.params.deviceType == "pc") {
|
||||
globalThis.params = JSON.parse(want['parameters']['params']);
|
||||
globalThis.position = JSON.parse(want['parameters']['position']);
|
||||
console.debug(TAG, 'onRequest, want: ' + JSON.stringify(want));
|
||||
console.debug(TAG, 'onRequest, params: ' + JSON.stringify(globalThis.params));
|
||||
globalThis.callerToken = want['parameters']['callerToken'];
|
||||
console.debug(TAG, 'onRequest, params: ' + JSON.stringify(globalThis.params));
|
||||
console.debug(TAG, 'onRequest, position: ' + JSON.stringify(globalThis.position));
|
||||
if (globalThis.params.deviceType == 'pc') {
|
||||
globalThis.modelFlag = Boolean(globalThis.params.modelFlag)
|
||||
globalThis.action = Boolean(globalThis.params.action)
|
||||
}
|
||||
if (globalThis.params.deviceType == "phone") {
|
||||
if (globalThis.params.deviceType == 'phone') {
|
||||
await this.getPhoneShowHapList();
|
||||
} else {
|
||||
await this.getPcShowHapList();
|
||||
@@ -121,22 +121,22 @@ export default class SelectorServiceExtensionAbility extends extension {
|
||||
win.destroy();
|
||||
winNum--;
|
||||
}
|
||||
if (deviceInfo.deviceType == "phone") {
|
||||
this.createWindow("SelectorDialog" + startId, window.WindowType.TYPE_SYSTEM_ALERT, navigationBarRect);
|
||||
if (deviceInfo.deviceType == 'phone') {
|
||||
this.createWindow('SelectorDialog' + startId, window.WindowType.TYPE_SYSTEM_ALERT, navigationBarRect);
|
||||
} else {
|
||||
console.debug(TAG, "onRequest, params: " + JSON.stringify(globalThis.params));
|
||||
this.createWindow("SelectorDialog" + startId, window.WindowType.TYPE_DIALOG, navigationBarRect);
|
||||
console.debug(TAG, 'onRequest, params: ' + JSON.stringify(globalThis.params));
|
||||
this.createWindow('SelectorDialog' + startId, window.WindowType.TYPE_DIALOG, navigationBarRect);
|
||||
}
|
||||
winNum++;
|
||||
})
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
console.info(TAG, "onDestroy.");
|
||||
console.info(TAG, 'onDestroy.');
|
||||
}
|
||||
|
||||
private async createWindow(name: string, windowType: number, rect) {
|
||||
console.info(TAG, "create window");
|
||||
console.info(TAG, 'create window');
|
||||
try {
|
||||
win = await window.create(globalThis.selectExtensionContext, name, windowType);
|
||||
await win.bindDialogTarget(globalThis.callerToken.value, () => {
|
||||
@@ -148,15 +148,15 @@ export default class SelectorServiceExtensionAbility extends extension {
|
||||
});
|
||||
await win.moveTo(rect.left, rect.top);
|
||||
await win.resetSize(rect.width, rect.height);
|
||||
if (globalThis.params.deviceType == "phone") {
|
||||
if (globalThis.params.deviceType == 'phone') {
|
||||
await win.loadContent('pages/selectorPhoneDialog');
|
||||
} else {
|
||||
await win.loadContent('pages/selectorPcDialog');
|
||||
}
|
||||
await win.setBackgroundColor("#00000000");
|
||||
await win.setBackgroundColor('#00000000');
|
||||
await win.show();
|
||||
} catch (e) {
|
||||
console.error(TAG, "window create failed: " + JSON.stringify(e));
|
||||
console.error(TAG, 'window create failed: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
};
|
||||
+15
-15
@@ -18,23 +18,23 @@ import window from '@ohos.window';
|
||||
import display from '@ohos.display';
|
||||
import deviceInfo from '@ohos.deviceInfo';
|
||||
|
||||
const TAG = "TipsDialog_Service";
|
||||
const TAG = 'TipsDialog_Service';
|
||||
|
||||
var winNum = 1;
|
||||
var win;
|
||||
let winNum = 1;
|
||||
let win;
|
||||
|
||||
export default class TipsServiceExtensionAbility extends extension {
|
||||
onCreate(want) {
|
||||
console.debug(TAG, "onCreate, want: " + JSON.stringify(want));
|
||||
console.debug(TAG, 'onCreate, want: ' + JSON.stringify(want));
|
||||
globalThis.tipsExtensionContext = this.context;
|
||||
}
|
||||
|
||||
onRequest(want, startId) {
|
||||
console.debug(TAG, "onRequest, want: " + JSON.stringify(want));
|
||||
console.debug(TAG, 'onRequest, want: ' + JSON.stringify(want));
|
||||
globalThis.abilityWant = want;
|
||||
globalThis.params = JSON.parse(want["parameters"]["params"]);
|
||||
globalThis.position = JSON.parse(want["parameters"]["position"]);
|
||||
globalThis.callerToken = want["parameters"]["callerToken"];
|
||||
globalThis.params = JSON.parse(want['parameters']['params']);
|
||||
globalThis.position = JSON.parse(want['parameters']['position']);
|
||||
globalThis.callerToken = want['parameters']['callerToken'];
|
||||
|
||||
display.getDefaultDisplay().then(dis => {
|
||||
let navigationBarRect = {
|
||||
@@ -47,21 +47,21 @@ export default class TipsServiceExtensionAbility extends extension {
|
||||
win.destroy();
|
||||
winNum--;
|
||||
}
|
||||
if (deviceInfo.deviceType == "phone") {
|
||||
this.createWindow("TipsDialog" + startId, window.WindowType.TYPE_SYSTEM_ALERT, navigationBarRect);
|
||||
if (deviceInfo.deviceType == 'phone') {
|
||||
this.createWindow('TipsDialog' + startId, window.WindowType.TYPE_SYSTEM_ALERT, navigationBarRect);
|
||||
} else {
|
||||
this.createWindow("TipsDialog" + startId, window.WindowType.TYPE_DIALOG, navigationBarRect);
|
||||
this.createWindow('TipsDialog' + startId, window.WindowType.TYPE_DIALOG, navigationBarRect);
|
||||
}
|
||||
winNum++;
|
||||
})
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
console.info(TAG, "onDestroy.");
|
||||
console.info(TAG, 'onDestroy.');
|
||||
}
|
||||
|
||||
private async createWindow(name: string, windowType: number, rect) {
|
||||
console.info(TAG, "create window");
|
||||
console.info(TAG, 'create window');
|
||||
try {
|
||||
win = await window.create(globalThis.tipsExtensionContext, name, windowType);
|
||||
await win.bindDialogTarget(globalThis.callerToken.value, () => {
|
||||
@@ -74,10 +74,10 @@ export default class TipsServiceExtensionAbility extends extension {
|
||||
await win.moveTo(rect.left, rect.top);
|
||||
await win.resetSize(rect.width, rect.height);
|
||||
await win.loadContent('pages/tipsDialog');
|
||||
await win.setBackgroundColor("#00000000");
|
||||
await win.setBackgroundColor('#00000000');
|
||||
await win.show();
|
||||
} catch {
|
||||
console.error(TAG, "window create failed!");
|
||||
console.error(TAG, 'window create failed!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user