mirror of
https://gitee.com/openharmony/bundlemanager_bundle_framework
synced 2024-11-23 07:09:53 +00:00
IssueNo: #I56WDJ: add default proxy and host.
Description: add default proxy and host. Sig: SIG_ApplicaitonFramework Feature or Bugfix: Feature Binary Source: No Signed-off-by: SoftSquirrel <xuhao47@huawei.com>
This commit is contained in:
parent
39bb00bb3d
commit
b28bf61426
@ -27,6 +27,7 @@ use_pre_bundle_profile = false
|
||||
declare_args() {
|
||||
bundle_framework_graphics = true
|
||||
bundle_framework_free_install = true
|
||||
bundle_framework_default_app = true
|
||||
|
||||
ability_runtime_enable = true
|
||||
account_enable = true
|
||||
@ -82,6 +83,7 @@ declare_args() {
|
||||
|
||||
print("bundle_framework_graphics = " + "$bundle_framework_graphics")
|
||||
print("bundle_framework_free_install = " + "$bundle_framework_free_install")
|
||||
print("bundle_framework_default_app = " + "$bundle_framework_default_app")
|
||||
print("ability_runtime_enable = " + "$ability_runtime_enable")
|
||||
print("account_enable = " + "$account_enable")
|
||||
print("configpolicy_enable = " + "$configpolicy_enable")
|
||||
|
@ -15,7 +15,8 @@
|
||||
],
|
||||
"features": [
|
||||
"bundle_framework_graphics",
|
||||
"bundle_framework_free_install"
|
||||
"bundle_framework_free_install",
|
||||
"bundle_framework_default_app"
|
||||
],
|
||||
"hisysevent_config": [
|
||||
"//foundation/bundlemanager/bundle_framework/hisysevent.yaml"
|
||||
|
@ -16,6 +16,9 @@ import("../../../appexecfwk.gni")
|
||||
|
||||
config("bundlemgr_sdk_config") {
|
||||
include_dirs = [ "include/bundlemgr" ]
|
||||
if (bundle_framework_default_app) {
|
||||
include_dirs += [ "include/default_app" ]
|
||||
}
|
||||
}
|
||||
|
||||
config("appexecfwk_core_config") {
|
||||
@ -80,6 +83,14 @@ ohos_shared_library("appexecfwk_core") {
|
||||
external_deps += [ "multimedia_image_standard:image_native" ]
|
||||
}
|
||||
|
||||
if (bundle_framework_default_app) {
|
||||
defines += [ "BUNDLE_FRAMEWORK_DEFAULT_APP" ]
|
||||
sources += [
|
||||
"src/default_app/default_app_host.cpp",
|
||||
"src/default_app/default_app_proxy.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
if (global_resmgr_enable) {
|
||||
defines += [ "GLOBAL_RESMGR_ENABLE" ]
|
||||
external_deps += [ "resource_management:global_resmgr" ]
|
||||
|
@ -381,6 +381,11 @@ private:
|
||||
* @return Returns ERR_OK if called successfully; returns error code otherwise.
|
||||
*/
|
||||
ErrCode HandleGetBundleUserMgr(Parcel &data, Parcel &reply);
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
ErrCode HandleGetDefaultAppProxy(Parcel &data, Parcel &reply);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Handles the IsApplicationEnabled function called from a IBundleMgr proxy object.
|
||||
* @param data Indicates the data to be read.
|
||||
@ -554,14 +559,6 @@ private:
|
||||
|
||||
ErrCode HandleGetDisposedStatus(Parcel &data, Parcel &reply);
|
||||
|
||||
ErrCode HandleIsDefaultApplication(Parcel &data, Parcel &reply);
|
||||
|
||||
ErrCode HandleGetDefaultApplication(Parcel &data, Parcel &reply);
|
||||
|
||||
ErrCode HandleSetDefaultApplication(Parcel &data, Parcel &reply);
|
||||
|
||||
ErrCode HandleResetDefaultApplication(Parcel &data, Parcel &reply);
|
||||
|
||||
ErrCode HandleObtainCallingBundleName(Parcel &data, Parcel &reply);
|
||||
|
||||
private:
|
||||
|
@ -35,6 +35,9 @@
|
||||
#ifdef BUNDLE_FRAMEWORK_GRAPHICS
|
||||
#include "pixel_map.h"
|
||||
#endif
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
#include "default_app_interface.h"
|
||||
#endif
|
||||
#include "shortcut_info.h"
|
||||
#include "want.h"
|
||||
|
||||
@ -787,6 +790,14 @@ public:
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
virtual sptr<IDefaultApp> GetDefaultAppProxy()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Obtains the DistributedBundleInfo based on a given bundle name and networkId.
|
||||
* @param networkId Indicates the networkId of remote device.
|
||||
@ -968,26 +979,6 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool IsDefaultApplication(const std::string& type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool SetDefaultApplication(int32_t userId, const std::string& type, const Want& want)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool ResetDefaultApplication(int32_t userId, const std::string& type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool ObtainCallingBundleName(std::string &bundleName)
|
||||
{
|
||||
return false;
|
||||
@ -1079,10 +1070,6 @@ public:
|
||||
GET_SANDBOX_APP_BUNDLE_INFO,
|
||||
SET_DISPOSED_STATUS,
|
||||
GET_DISPOSED_STATUS,
|
||||
IS_DEFAULT_APPLICATION,
|
||||
GET_DEFAULT_APPLICATION,
|
||||
SET_DEFAULT_APPLICATION,
|
||||
RESET_DEFAULT_APPLICATION,
|
||||
QUERY_CALLING_BUNDLE_NAME,
|
||||
};
|
||||
};
|
||||
|
@ -472,6 +472,11 @@ public:
|
||||
* @return Returns a pointer to IBundleUserMgr class if exist; returns nullptr otherwise.
|
||||
*/
|
||||
virtual sptr<IBundleUserMgr> GetBundleUserMgr() override;
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
virtual sptr<IDefaultApp> GetDefaultAppProxy() override;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Obtains the FormInfo objects provided by all applications on the device.
|
||||
* @param formInfos List of FormInfo objects if obtained; returns an empty List if no FormInfo is available on the
|
||||
@ -682,14 +687,6 @@ public:
|
||||
|
||||
virtual int32_t GetDisposedStatus(const std::string &bundleName) override;
|
||||
|
||||
virtual bool IsDefaultApplication(const std::string& type) override;
|
||||
|
||||
virtual bool GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo) override;
|
||||
|
||||
virtual bool SetDefaultApplication(int32_t userId, const std::string& type, const Want& want) override;
|
||||
|
||||
virtual bool ResetDefaultApplication(int32_t userId, const std::string& type) override;
|
||||
|
||||
virtual bool ObtainCallingBundleName(std::string &bundleName) override;
|
||||
|
||||
private:
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_DEFAULT_APP_HOST_H
|
||||
#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_DEFAULT_APP_HOST_H
|
||||
|
||||
|
||||
#include "default_app_interface.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class DefaultAppHost : public IRemoteStub<IDefaultApp> {
|
||||
public:
|
||||
DefaultAppHost();
|
||||
virtual ~DefaultAppHost();
|
||||
|
||||
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
|
||||
private:
|
||||
ErrCode HandleIsDefaultApplication(Parcel& data, Parcel& reply);
|
||||
ErrCode HandleGetDefaultApplication(Parcel& data, Parcel& reply);
|
||||
ErrCode HandleSetDefaultApplication(Parcel& data, Parcel& reply);
|
||||
ErrCode HandleResetDefaultApplication(Parcel& data, Parcel& reply);
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(DefaultAppHost);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_DEFAULT_APP_INTERFACE_H
|
||||
#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_DEFAULT_APP_INTERFACE_H
|
||||
|
||||
#include "bundle_info.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class IDefaultApp : public IRemoteBroker {
|
||||
public:
|
||||
using Want = OHOS::AAFwk::Want;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.DefaultApp");
|
||||
|
||||
virtual bool IsDefaultApplication(const std::string& type) = 0;
|
||||
virtual bool GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo) = 0;
|
||||
virtual bool SetDefaultApplication(int32_t userId, const std::string& type, const Want& want) = 0;
|
||||
virtual bool ResetDefaultApplication(int32_t userId, const std::string& type) = 0;
|
||||
|
||||
enum class Message : uint32_t {
|
||||
IS_DEFAULT_APPLICATION = 0,
|
||||
GET_DEFAULT_APPLICATION = 1,
|
||||
SET_DEFAULT_APPLICATION = 2,
|
||||
RESET_DEFAULT_APPLICATION = 3,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_DEFAULT_APP_PROXY_H
|
||||
#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_DEFAULT_APP_PROXY_H
|
||||
|
||||
#include "default_app_interface.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class DefaultAppProxy : public IRemoteProxy<IDefaultApp> {
|
||||
public:
|
||||
explicit DefaultAppProxy(const sptr<IRemoteObject>& object);
|
||||
virtual ~DefaultAppProxy();
|
||||
|
||||
virtual bool IsDefaultApplication(const std::string& type) override;
|
||||
virtual bool GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo) override;
|
||||
virtual bool SetDefaultApplication(int32_t userId, const std::string& type, const Want& want) override;
|
||||
virtual bool ResetDefaultApplication(int32_t userId, const std::string& type) override;
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
bool GetParcelableInfo(IDefaultApp::Message code, MessageParcel& data, T& parcelableInfo);
|
||||
bool SendRequest(IDefaultApp::Message code, MessageParcel& data, MessageParcel& reply);
|
||||
static inline BrokerDelegator<DefaultAppProxy> delegator_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -176,10 +176,6 @@ void BundleMgrHost::init()
|
||||
funcMap_.emplace(IBundleMgr::Message::GET_SANDBOX_APP_BUNDLE_INFO, &BundleMgrHost::HandleGetSandboxBundleInfo);
|
||||
funcMap_.emplace(IBundleMgr::Message::SET_DISPOSED_STATUS, &BundleMgrHost::HandleSetDisposedStatus);
|
||||
funcMap_.emplace(IBundleMgr::Message::GET_DISPOSED_STATUS, &BundleMgrHost::HandleGetDisposedStatus);
|
||||
funcMap_.emplace(IBundleMgr::Message::IS_DEFAULT_APPLICATION, &BundleMgrHost::HandleIsDefaultApplication);
|
||||
funcMap_.emplace(IBundleMgr::Message::GET_DEFAULT_APPLICATION, &BundleMgrHost::HandleGetDefaultApplication);
|
||||
funcMap_.emplace(IBundleMgr::Message::SET_DEFAULT_APPLICATION, &BundleMgrHost::HandleSetDefaultApplication);
|
||||
funcMap_.emplace(IBundleMgr::Message::RESET_DEFAULT_APPLICATION, &BundleMgrHost::HandleResetDefaultApplication);
|
||||
funcMap_.emplace(IBundleMgr::Message::QUERY_CALLING_BUNDLE_NAME, &BundleMgrHost::HandleObtainCallingBundleName);
|
||||
}
|
||||
|
||||
@ -1293,6 +1289,24 @@ ErrCode BundleMgrHost::HandleGetBundleUserMgr(Parcel &data, Parcel &reply)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
ErrCode BundleMgrHost::HandleGetDefaultAppProxy(Parcel &data, Parcel &reply)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
sptr<IDefaultApp> defaultAppProxy = GetDefaultAppProxy();
|
||||
if (defaultAppProxy == nullptr) {
|
||||
APP_LOGE("defaultAppProxy is nullptr.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
if (!reply.WriteObject<IRemoteObject>(defaultAppProxy->AsObject())) {
|
||||
APP_LOGE("WriteObject failed.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
ErrCode BundleMgrHost::HandleGetAllFormsInfo(Parcel &data, Parcel &reply)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
@ -1771,85 +1785,6 @@ ErrCode BundleMgrHost::HandleGetDisposedStatus(Parcel &data, Parcel &reply)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BundleMgrHost::HandleIsDefaultApplication(Parcel &data, Parcel &reply)
|
||||
{
|
||||
APP_LOGD("begin to HandleIsDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
std::string type = data.ReadString();
|
||||
bool ret = IsDefaultApplication(type);
|
||||
|
||||
if (!reply.WriteBool(ret)) {
|
||||
APP_LOGE("write ret failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BundleMgrHost::HandleGetDefaultApplication(Parcel &data, Parcel &reply)
|
||||
{
|
||||
APP_LOGD("begin to HandleGetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
int32_t userId = data.ReadInt32();
|
||||
std::string type = data.ReadString();
|
||||
BundleInfo bundleInfo;
|
||||
bool ret = GetDefaultApplication(userId, type, bundleInfo);
|
||||
|
||||
if (!reply.WriteBool(ret)) {
|
||||
APP_LOGE("write ret failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (ret) {
|
||||
if (!reply.WriteParcelable(&bundleInfo)) {
|
||||
APP_LOGE("write bundleInfo failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BundleMgrHost::HandleSetDefaultApplication(Parcel &data, Parcel &reply)
|
||||
{
|
||||
APP_LOGD("begin to HandleSetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
int32_t userId = data.ReadInt32();
|
||||
std::string type = data.ReadString();
|
||||
std::unique_ptr<Want> want(data.ReadParcelable<Want>());
|
||||
if (want == nullptr) {
|
||||
APP_LOGE("ReadParcelable<want> failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
bool ret = SetDefaultApplication(userId, type, *want);
|
||||
|
||||
if (!reply.WriteBool(ret)) {
|
||||
APP_LOGE("write ret failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BundleMgrHost::HandleResetDefaultApplication(Parcel &data, Parcel &reply)
|
||||
{
|
||||
APP_LOGD("begin to HandleResetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
int32_t userId = data.ReadInt32();
|
||||
std::string type = data.ReadString();
|
||||
bool ret = ResetDefaultApplication(userId, type);
|
||||
|
||||
if (!reply.WriteBool(ret)) {
|
||||
APP_LOGE("write ret failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BundleMgrHost::HandleObtainCallingBundleName(Parcel &data, Parcel &reply)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
@ -1936,6 +1936,34 @@ sptr<IBundleUserMgr> BundleMgrProxy::GetBundleUserMgr()
|
||||
return bundleUserMgr;
|
||||
}
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
sptr<IDefaultApp> BundleMgrProxy::GetDefaultAppProxy()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("fail to get default app proxy due to write InterfaceToken failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (!SendTransactCmd(IBundleMgr::Message::GET_DEFAULT_APP_PROXY, data, reply)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> object = reply.ReadObject<IRemoteObject>();
|
||||
if (object == nullptr) {
|
||||
APP_LOGE("reply failed.");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IDefaultApp> defaultAppProxy = iface_cast<IDefaultApp>(object);
|
||||
if (defaultAppProxy == nullptr) {
|
||||
APP_LOGE("defaultAppProxy is nullptr.");
|
||||
}
|
||||
|
||||
return defaultAppProxy;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool BundleMgrProxy::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
@ -2555,133 +2583,6 @@ int32_t BundleMgrProxy::GetDisposedStatus(const std::string &bundleName)
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
bool BundleMgrProxy::IsDefaultApplication(const std::string& type)
|
||||
{
|
||||
APP_LOGD("begin to call IsDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
if (type.empty()) {
|
||||
APP_LOGE("type is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("WriteInterfaceToken failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
APP_LOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
if (!SendTransactCmd(IBundleMgr::Message::IS_DEFAULT_APPLICATION, data, reply)) {
|
||||
APP_LOGE("SendTransactCmd failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
bool BundleMgrProxy::GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo)
|
||||
{
|
||||
APP_LOGD("begin to GetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
if (type.empty()) {
|
||||
APP_LOGE("type is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("WriteInterfaceToken failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
APP_LOGE("write userId failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
APP_LOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GetParcelableInfo<BundleInfo>(IBundleMgr::Message::GET_DEFAULT_APPLICATION, data, bundleInfo)) {
|
||||
APP_LOGE("failed to GetDefaultApplication from server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
APP_LOGD("GetDefaultApplication success.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BundleMgrProxy::SetDefaultApplication(int32_t userId, const std::string& type, const Want& want)
|
||||
{
|
||||
APP_LOGD("begin to SetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("WriteInterfaceToken failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
APP_LOGE("write userId failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
APP_LOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteParcelable(&want)) {
|
||||
APP_LOGE("write want failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
if (!SendTransactCmd(IBundleMgr::Message::SET_DEFAULT_APPLICATION, data, reply)) {
|
||||
APP_LOGE("SendTransactCmd failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
bool BundleMgrProxy::ResetDefaultApplication(int32_t userId, const std::string& type)
|
||||
{
|
||||
APP_LOGD("begin to ResetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
if (type.empty()) {
|
||||
APP_LOGE("type is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("WriteInterfaceToken failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
APP_LOGE("write userId failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
APP_LOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
if (!SendTransactCmd(IBundleMgr::Message::RESET_DEFAULT_APPLICATION, data, reply)) {
|
||||
APP_LOGE("SendTransactCmd failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
bool BundleMgrProxy::ObtainCallingBundleName(std::string &bundleName)
|
||||
{
|
||||
APP_LOGD("begin to ObtainCallingBundleName");
|
||||
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "default_app_host.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
DefaultAppHost::DefaultAppHost()
|
||||
{
|
||||
APP_LOGD("create DefaultAppHost.");
|
||||
}
|
||||
|
||||
DefaultAppHost::~DefaultAppHost()
|
||||
{
|
||||
APP_LOGD("destroy DefaultAppHost.");
|
||||
}
|
||||
|
||||
int DefaultAppHost::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
APP_LOGI("DefaultAppHost OnRemoteRequest, message code : %{public}u", code);
|
||||
std::u16string descriptor = DefaultAppHost::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
APP_LOGE("descriptor invalid.");
|
||||
return OBJECT_NULL;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case static_cast<uint32_t>(IDefaultApp::Message::IS_DEFAULT_APPLICATION): {
|
||||
HandleIsDefaultApplication(data, reply);
|
||||
break;
|
||||
}
|
||||
case static_cast<uint32_t>(IDefaultApp::Message::GET_DEFAULT_APPLICATION): {
|
||||
HandleGetDefaultApplication(data, reply);
|
||||
break;
|
||||
}
|
||||
case static_cast<uint32_t>(IDefaultApp::Message::SET_DEFAULT_APPLICATION): {
|
||||
HandleSetDefaultApplication(data, reply);
|
||||
break;
|
||||
}
|
||||
case static_cast<uint32_t>(IDefaultApp::Message::RESET_DEFAULT_APPLICATION): {
|
||||
HandleResetDefaultApplication(data, reply);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
ErrCode DefaultAppHost::HandleIsDefaultApplication(Parcel& data, Parcel& reply)
|
||||
{
|
||||
APP_LOGI("begin to HandleIsDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
std::string type = data.ReadString();
|
||||
bool ret = IsDefaultApplication(type);
|
||||
|
||||
if (!reply.WriteBool(ret)) {
|
||||
APP_LOGE("write ret failed.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode DefaultAppHost::HandleGetDefaultApplication(Parcel& data, Parcel& reply)
|
||||
{
|
||||
APP_LOGI("begin to HandleGetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
int32_t userId = data.ReadInt32();
|
||||
std::string type = data.ReadString();
|
||||
BundleInfo bundleInfo;
|
||||
bool ret = GetDefaultApplication(userId, type, bundleInfo);
|
||||
|
||||
if (!reply.WriteBool(ret)) {
|
||||
APP_LOGE("write ret failed.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (ret) {
|
||||
if (!reply.WriteParcelable(&bundleInfo)) {
|
||||
APP_LOGE("write bundleInfo failed.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode DefaultAppHost::HandleSetDefaultApplication(Parcel& data, Parcel& reply)
|
||||
{
|
||||
APP_LOGI("begin to HandleSetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
int32_t userId = data.ReadInt32();
|
||||
std::string type = data.ReadString();
|
||||
std::unique_ptr<Want> want(data.ReadParcelable<Want>());
|
||||
if (want == nullptr) {
|
||||
APP_LOGE("ReadParcelable<Want> failed.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
bool ret = SetDefaultApplication(userId, type, *want);
|
||||
|
||||
if (!reply.WriteBool(ret)) {
|
||||
APP_LOGE("write ret failed.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode DefaultAppHost::HandleResetDefaultApplication(Parcel& data, Parcel& reply)
|
||||
{
|
||||
APP_LOGI("begin to HandleResetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
int32_t userId = data.ReadInt32();
|
||||
std::string type = data.ReadString();
|
||||
bool ret = ResetDefaultApplication(userId, type);
|
||||
|
||||
if (!reply.WriteBool(ret)) {
|
||||
APP_LOGE("write ret failed.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "default_app_proxy.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_types.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
DefaultAppProxy::DefaultAppProxy(const sptr<IRemoteObject>& object)
|
||||
: IRemoteProxy<IDefaultApp>(object)
|
||||
{
|
||||
APP_LOGD("create DefaultAppProxy.");
|
||||
}
|
||||
|
||||
DefaultAppProxy::~DefaultAppProxy()
|
||||
{
|
||||
APP_LOGD("destroy DefaultAppProxy.");
|
||||
}
|
||||
|
||||
bool DefaultAppProxy::IsDefaultApplication(const std::string& type)
|
||||
{
|
||||
APP_LOGI("begin to call IsDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
if (type.empty()) {
|
||||
APP_LOGE("type is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("WriteInterfaceToken failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
APP_LOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
if (!SendRequest(IDefaultApp::Message::IS_DEFAULT_APPLICATION, data, reply)) {
|
||||
APP_LOGE("SendRequest failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
bool DefaultAppProxy::GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo)
|
||||
{
|
||||
APP_LOGI("begin to GetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
if (type.empty()) {
|
||||
APP_LOGE("type is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("WriteInterfaceToken failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
APP_LOGE("write userId failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
APP_LOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GetParcelableInfo<BundleInfo>(IDefaultApp::Message::GET_DEFAULT_APPLICATION, data, bundleInfo)) {
|
||||
APP_LOGE("failed to GetDefaultApplication from server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
APP_LOGI("GetDefaultApplication success.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DefaultAppProxy::SetDefaultApplication(int32_t userId, const std::string& type, const Want& want)
|
||||
{
|
||||
APP_LOGI("begin to SetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("WriteInterfaceToken failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
APP_LOGE("write userId failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
APP_LOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteParcelable(&want)) {
|
||||
APP_LOGE("write want failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
if (!SendRequest(IDefaultApp::Message::SET_DEFAULT_APPLICATION, data, reply)) {
|
||||
APP_LOGE("SendRequest failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
bool DefaultAppProxy::ResetDefaultApplication(int32_t userId, const std::string& type)
|
||||
{
|
||||
APP_LOGI("begin to ResetDefaultApplication.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
if (type.empty()) {
|
||||
APP_LOGE("type is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
APP_LOGE("WriteInterfaceToken failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
APP_LOGE("write userId failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
APP_LOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
if (!SendRequest(IDefaultApp::Message::RESET_DEFAULT_APPLICATION, data, reply)) {
|
||||
APP_LOGE("SendRequest failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool DefaultAppProxy::GetParcelableInfo(IDefaultApp::Message code, MessageParcel& data, T& parcelableInfo)
|
||||
{
|
||||
MessageParcel reply;
|
||||
if (!SendRequest(code, data, reply)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!reply.ReadBool()) {
|
||||
APP_LOGE("reply false.");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<T> info(reply.ReadParcelable<T>());
|
||||
if (info == nullptr) {
|
||||
APP_LOGE("ReadParcelable failed.");
|
||||
return false;
|
||||
}
|
||||
parcelableInfo = *info;
|
||||
APP_LOGI("GetParcelableInfo success.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DefaultAppProxy::SendRequest(IDefaultApp::Message code, MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
APP_LOGE("failed to send request %{public}d due to remote object null.", code);
|
||||
return false;
|
||||
}
|
||||
int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
|
||||
if (result != NO_ERROR) {
|
||||
APP_LOGE("receive error code %{public}d in transact %{public}d", result, code);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import("appexecfwk_bundlemgr.gni")
|
||||
config("bundlemgr_common_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"include/default_app",
|
||||
"include/free_install",
|
||||
"include/sandbox_app",
|
||||
"//utils/system/safwk/native/include",
|
||||
@ -216,6 +217,11 @@ ohos_shared_library("libbms") {
|
||||
defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ]
|
||||
}
|
||||
|
||||
if (bundle_framework_default_app) {
|
||||
sources += default_app
|
||||
defines += [ "BUNDLE_FRAMEWORK_DEFAULT_APP" ]
|
||||
}
|
||||
|
||||
if (configpolicy_enable) {
|
||||
external_deps += [ "config_policy:configpolicy_util" ]
|
||||
defines += [ "CONFIG_POLOCY_ENABLE" ]
|
||||
|
@ -69,6 +69,12 @@ free_install = [
|
||||
"${services_path}/bundlemgr/src/free_install/service_center_status_callback_stub.cpp",
|
||||
]
|
||||
|
||||
default_app = [
|
||||
"${services_path}/bundlemgr/src/default_app/default_app_db.cpp",
|
||||
"${services_path}/bundlemgr/src/default_app/default_app_host_impl.cpp",
|
||||
"${services_path}/bundlemgr/src/default_app/default_app_mgr.cpp",
|
||||
]
|
||||
|
||||
bundle_install_deps = [
|
||||
"${services_path}/bundlemgr:bundle_parser",
|
||||
"${services_path}/bundlemgr:parser_common",
|
||||
|
@ -45,6 +45,9 @@
|
||||
#ifdef GLOBAL_RESMGR_ENABLE
|
||||
#include "resource_manager.h"
|
||||
#endif
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
#include "element.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -733,6 +736,13 @@ public:
|
||||
|
||||
int32_t GetDisposedStatus(const std::string &bundleName);
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
bool QueryInfoAndSkillsByElement(int32_t userId, const Element& element,
|
||||
AbilityInfo& abilityInfo, ExtensionAbilityInfo& extensionInfo, std::vector<Skill>& skills) const;
|
||||
|
||||
bool GetElement(int32_t userId, const ElementName& elementName, Element& element) const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Init transferStates.
|
||||
|
@ -479,6 +479,11 @@ public:
|
||||
* @return Returns a pointer to IBundleUserMgr class if exist; returns nullptr otherwise.
|
||||
*/
|
||||
virtual sptr<IBundleUserMgr> GetBundleUserMgr() override;
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
virtual sptr<IDefaultApp> GetDefaultAppProxy() override;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Obtains the FormInfo objects provided by all applications on the device.
|
||||
* @param formInfos List of FormInfo objects if obtained; returns an empty List if no FormInfo is available on the
|
||||
@ -679,14 +684,6 @@ public:
|
||||
|
||||
virtual int32_t GetDisposedStatus(const std::string &bundleName) override;
|
||||
|
||||
virtual bool IsDefaultApplication(const std::string& type) override;
|
||||
|
||||
virtual bool GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo) override;
|
||||
|
||||
virtual bool SetDefaultApplication(int32_t userId, const std::string& type, const Want& want) override;
|
||||
|
||||
virtual bool ResetDefaultApplication(int32_t userId, const std::string& type) override;
|
||||
|
||||
virtual bool ObtainCallingBundleName(std::string &bundleName) override;
|
||||
|
||||
private:
|
||||
|
@ -28,6 +28,9 @@
|
||||
#include "aging/bundle_aging_mgr.h"
|
||||
#include "bundle_connect_ability_mgr.h"
|
||||
#endif
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
#include "default_app_host_impl.h"
|
||||
#endif
|
||||
#include "bundle_clone_mgr.h"
|
||||
#include "bundle_constants.h"
|
||||
#include "bundle_data_mgr.h"
|
||||
@ -85,6 +88,11 @@ public:
|
||||
* @return Returns the pointer of IBundleUserMgr object.
|
||||
*/
|
||||
sptr<BundleUserMgrHostImpl> GetBundleUserMgr() const;
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
sptr<IDefaultApp> GetDefaultAppProxy() const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Check all user.
|
||||
*/
|
||||
@ -151,6 +159,10 @@ private:
|
||||
sptr<BundleUserMgrHostImpl> userMgrHost_;
|
||||
std::shared_ptr<DistributedMonitor> distributedSub_;
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
sptr<DefaultAppHostImpl> defaultAppHostImpl_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(BundleMgrService);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
59
services/bundlemgr/include/default_app/default_app_db.h
Normal file
59
services/bundlemgr/include/default_app/default_app_db.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_DB
|
||||
#define FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_DB
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "distributed_kv_data_manager.h"
|
||||
#include "element.h"
|
||||
#include "inner_bundle_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
const std::string APP_ID = "bundle_manager_service";
|
||||
const std::string DEFAULT_APP_DATA_STORE_ID = "default_app_datas";
|
||||
}
|
||||
|
||||
struct DefaultAppInfo {
|
||||
std::map<std::string, Element> infos;
|
||||
};
|
||||
|
||||
class DefaultAppDb {
|
||||
public:
|
||||
DefaultAppDb();
|
||||
~DefaultAppDb();
|
||||
bool GetDefaultApplicationInfos(int32_t userId, std::map<std::string, Element>& infos);
|
||||
bool GetDefaultApplicationInfo(int32_t userId, const std::string& type, Element& element);
|
||||
bool SetDefaultApplicationInfos(int32_t userId, const std::map<std::string, Element>& infos);
|
||||
bool SetDefaultApplicationInfo(int32_t userId, const std::string& type, const Element& element);
|
||||
bool DeleteDefaultApplicationInfos(int32_t userId);
|
||||
bool DeleteDefaultApplicationInfo(int32_t userId, const std::string& type);
|
||||
private:
|
||||
bool OpenKvDb();
|
||||
bool GetDataFromDb(int32_t userId, std::map<std::string, Element>& infos);
|
||||
bool SaveDataToDb(int32_t userId, const std::map<std::string, Element>& infos);
|
||||
bool DeleteDataFromDb(int32_t userId);
|
||||
|
||||
const DistributedKv::AppId appId_ { APP_ID };
|
||||
const DistributedKv::StoreId storeId_ { DEFAULT_APP_DATA_STORE_ID };
|
||||
DistributedKv::DistributedKvDataManager dataManager_;
|
||||
std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_DEFAULT_APP_HOST_IMPL_H
|
||||
#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_DEFAULT_APP_HOST_IMPL_H
|
||||
|
||||
#include "default_app_host.h"
|
||||
#include "default_app_mgr.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class DefaultAppHostImpl : public DefaultAppHost {
|
||||
public:
|
||||
virtual bool IsDefaultApplication(const std::string& type) override;
|
||||
virtual bool GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo) override;
|
||||
virtual bool SetDefaultApplication(int32_t userId, const std::string& type, const Want& want) override;
|
||||
virtual bool ResetDefaultApplication(int32_t userId, const std::string& type) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<DefaultAppMgr> defaultAppMgr_ = std::make_shared<DefaultAppMgr>();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
53
services/bundlemgr/include/default_app/default_app_mgr.h
Normal file
53
services/bundlemgr/include/default_app/default_app_mgr.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_MGR
|
||||
#define FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_MGR
|
||||
|
||||
#include<set>
|
||||
|
||||
#include "default_app_db.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class DefaultAppMgr {
|
||||
public:
|
||||
DefaultAppMgr();
|
||||
~DefaultAppMgr();
|
||||
bool IsDefaultApplication(int32_t userId, const std::string& type);
|
||||
bool GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo);
|
||||
bool SetDefaultApplication(int32_t userId, const std::string& type, const Element& element);
|
||||
bool ResetDefaultApplication(int32_t userId, const std::string& type);
|
||||
private:
|
||||
bool GetBundleInfo(int32_t userId, const std::string& type, const Element& element, BundleInfo& bundleInfo);
|
||||
void InitSupportAppTypes();
|
||||
bool IsAppType(const std::string& type);
|
||||
bool IsFileType(const std::string& type);
|
||||
bool IsMatch(const std::string& type, const std::vector<Skill>& skills);
|
||||
bool MatchAppType(const std::string& type, const std::vector<Skill>& skills);
|
||||
bool MatchFileType(const std::string& type, const std::vector<Skill>& skills);
|
||||
bool IsElementValid(const Element& element);
|
||||
bool IsUserIdExist(int32_t userId);
|
||||
bool IsBrowserSkillsValid(const std::vector<Skill>& skills);
|
||||
bool IsImageSkillsValid(const std::vector<Skill>& skills);
|
||||
bool IsAudioSkillsValid(const std::vector<Skill>& skills);
|
||||
bool IsVideoSkillsValid(const std::vector<Skill>& skills);
|
||||
|
||||
std::shared_ptr<DefaultAppDb> defaultAppDb_;
|
||||
std::set<std::string> supportAppTypes;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
30
services/bundlemgr/include/default_app/element.h
Normal file
30
services/bundlemgr/include/default_app/element.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_ELEMENT
|
||||
#define FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_ELEMENT
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
struct Element {
|
||||
std::string bundleName;
|
||||
std::string moduleName;
|
||||
std::string abilityName;
|
||||
std::string extensionName;
|
||||
std::string type;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -118,12 +118,12 @@ public:
|
||||
std::vector<SkillUri> uris;
|
||||
bool Match(const OHOS::AAFwk::Want &want) const;
|
||||
bool MatchLauncher(const OHOS::AAFwk::Want &want) const;
|
||||
bool MatchType(const std::string &type, const std::string &skillUriType) const;
|
||||
private:
|
||||
bool MatchAction(const std::string &action) const;
|
||||
bool MatchEntities(const std::vector<std::string> ¶mEntities) const;
|
||||
bool MatchUriAndType(const std::string &uriString, const std::string &type) const;
|
||||
bool MatchUri(const std::string &uriString, const SkillUri &skillUri) const;
|
||||
bool MatchType(const std::string &type, const std::string &skillUriType) const;
|
||||
};
|
||||
|
||||
enum InstallExceptionStatus : int32_t {
|
||||
|
@ -2999,5 +2999,111 @@ std::shared_ptr<Media::PixelMap> BundleDataMgr::LoadImageFile(const std::string
|
||||
return std::shared_ptr<Media::PixelMap>(std::move(pixelMapPtr));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
bool BundleDataMgr::QueryInfoAndSkillsByElement(int32_t userId, const Element& element,
|
||||
AbilityInfo& abilityInfo, ExtensionAbilityInfo& extensionInfo, std::vector<Skill>& skills) const
|
||||
{
|
||||
APP_LOGI("begin to QueryInfoAndSkillsByElement.");
|
||||
const std::string& bundleName = element.bundleName;
|
||||
const std::string& moduleName = element.moduleName;
|
||||
const std::string& abilityName = element.abilityName;
|
||||
const std::string& extensionName = element.extensionName;
|
||||
bool isAbility = !element.abilityName.empty();
|
||||
bool ret = false;
|
||||
if (isAbility) {
|
||||
// get ability info
|
||||
ret = ExplicitQueryAbilityInfo(bundleName, moduleName, abilityName,
|
||||
GET_ABILITY_INFO_DEFAULT, userId, abilityInfo);
|
||||
if (!ret) {
|
||||
APP_LOGE("ExplicitQueryAbilityInfo failed.");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// get extension info
|
||||
ret = ExplicitQueryExtensionInfo(bundleName, moduleName, extensionName,
|
||||
GET_EXTENSION_INFO_DEFAULT, userId, extensionInfo);
|
||||
if (!ret) {
|
||||
APP_LOGE("ExplicitQueryExtensionInfo failed.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// get skills info
|
||||
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
|
||||
if (bundleInfos_.empty()) {
|
||||
APP_LOGE("bundleInfos_ is empty.");
|
||||
return false;
|
||||
}
|
||||
auto item = bundleInfos_.find(bundleName);
|
||||
if (item == bundleInfos_.end()) {
|
||||
APP_LOGE("can't find bundleName : %{public}s.", bundleName.c_str());
|
||||
return false;
|
||||
}
|
||||
const InnerBundleInfo& innerBundleInfo = item->second;
|
||||
if (isAbility) {
|
||||
std::string key;
|
||||
key.append(bundleName).append(".").append(moduleName).append(".").append(abilityName);
|
||||
APP_LOGI("begin to find ability skills, key : %{public}s.", key.c_str());
|
||||
for (const auto& item : innerBundleInfo.GetInnerSkillInfos()) {
|
||||
if (item.first == key) {
|
||||
skills = item.second;
|
||||
APP_LOGI("find ability skills success.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::string key;
|
||||
key.append(bundleName).append(".").append(moduleName).append(".").append(extensionName);
|
||||
APP_LOGI("begin to find extension skills, key : %{public}s.", key.c_str());
|
||||
for (const auto& item : innerBundleInfo.GetExtensionSkillInfos()) {
|
||||
if (item.first == key) {
|
||||
skills = item.second;
|
||||
APP_LOGI("find extension skills success.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
APP_LOGI("QueryInfoAndSkillsByElement success.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BundleDataMgr::GetElement(int32_t userId, const ElementName& elementName, Element& element) const
|
||||
{
|
||||
APP_LOGI("begin to GetElement.");
|
||||
const std::string& bundleName = elementName.GetBundleName();
|
||||
const std::string& moduleName = elementName.GetModuleName();
|
||||
const std::string& abilityName = elementName.GetAbilityName();
|
||||
if (bundleName.empty() || moduleName.empty() || abilityName.empty()) {
|
||||
APP_LOGE("bundleName or moduleName or abilityName is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
AbilityInfo abilityInfo;
|
||||
bool ret = ExplicitQueryAbilityInfo(bundleName, moduleName, abilityName,
|
||||
GET_ABILITY_INFO_DEFAULT, userId, abilityInfo);
|
||||
if (ret) {
|
||||
APP_LOGI("ElementName is ability.");
|
||||
element.bundleName = bundleName;
|
||||
element.moduleName = moduleName;
|
||||
element.abilityName = abilityName;
|
||||
return true;
|
||||
}
|
||||
|
||||
ExtensionAbilityInfo extensionInfo;
|
||||
ret = ExplicitQueryExtensionInfo(bundleName, moduleName, abilityName,
|
||||
GET_EXTENSION_INFO_DEFAULT, userId, extensionInfo);
|
||||
if (ret) {
|
||||
APP_LOGI("ElementName is extension.");
|
||||
element.bundleName = bundleName;
|
||||
element.moduleName = moduleName;
|
||||
element.extensionName = abilityName;
|
||||
return true;
|
||||
}
|
||||
|
||||
APP_LOGE("ElementName doesn't exist.");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -1098,6 +1098,13 @@ sptr<IBundleUserMgr> BundleMgrHostImpl::GetBundleUserMgr()
|
||||
return DelayedSingleton<BundleMgrService>::GetInstance()->GetBundleUserMgr();
|
||||
}
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
sptr<IDefaultApp> BundleMgrHostImpl::GetDefaultAppProxy()
|
||||
{
|
||||
return DelayedSingleton<BundleMgrService>::GetInstance()->GetDefaultAppProxy();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool BundleMgrHostImpl::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
|
||||
{
|
||||
APP_LOGD("start GetAllFormsInfo");
|
||||
@ -1607,30 +1614,6 @@ int32_t BundleMgrHostImpl::GetDisposedStatus(const std::string &bundleName)
|
||||
return dataMgr->GetDisposedStatus(bundleName);
|
||||
}
|
||||
|
||||
bool BundleMgrHostImpl::IsDefaultApplication(const std::string& type)
|
||||
{
|
||||
APP_LOGD("begin to call IsDefaultApplication, type : %{public}s.", type.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BundleMgrHostImpl::GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo)
|
||||
{
|
||||
APP_LOGD("begin to GetDefaultApplication, userId : %{public}d, type : %{public}s.", userId, type.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BundleMgrHostImpl::SetDefaultApplication(int32_t userId, const std::string& type, const Want& want)
|
||||
{
|
||||
APP_LOGD("begin to SetDefaultApplication, userId : %{public}d, type : %{public}s.", userId, type.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BundleMgrHostImpl::ResetDefaultApplication(int32_t userId, const std::string& type)
|
||||
{
|
||||
APP_LOGD("begin to ResetDefaultApplication, userId : %{public}d, type : %{public}s.", userId, type.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BundleMgrHostImpl::ObtainCallingBundleName(std::string &bundleName)
|
||||
{
|
||||
bool ret = GetBundleNameForUid(IPCSkeleton::GetCallingUid(), bundleName);
|
||||
|
@ -209,6 +209,16 @@ bool BundleMgrService::Init()
|
||||
APP_LOGI("create BundleConnectAbility success");
|
||||
#endif
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
if (defaultAppHostImpl_ == nullptr) {
|
||||
defaultAppHostImpl_ = new (std::nothrow) DefaultAppHostImpl();
|
||||
if (defaultAppHostImpl_ == nullptr) {
|
||||
APP_LOGE("create DefaultAppHostImpl failed.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
CheckAllUser();
|
||||
ready_ = true;
|
||||
APP_LOGI("init end success");
|
||||
@ -262,6 +272,13 @@ sptr<BundleUserMgrHostImpl> BundleMgrService::GetBundleUserMgr() const
|
||||
return userMgrHost_;
|
||||
}
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
|
||||
sptr<IDefaultApp> BundleMgrService::GetDefaultAppProxy() const
|
||||
{
|
||||
return defaultAppHostImpl_;
|
||||
}
|
||||
#endif
|
||||
|
||||
void BundleMgrService::CheckAllUser()
|
||||
{
|
||||
if (dataMgr_ == nullptr) {
|
||||
|
82
services/bundlemgr/src/default_app/default_app_db.cpp
Normal file
82
services/bundlemgr/src/default_app/default_app_db.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "default_app_db.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
DefaultAppDb::DefaultAppDb()
|
||||
{
|
||||
APP_LOGI("create DefaultAppDb.");
|
||||
OpenKvDb();
|
||||
}
|
||||
|
||||
DefaultAppDb::~DefaultAppDb()
|
||||
{
|
||||
APP_LOGI("destroy DefaultAppDb.");
|
||||
dataManager_.CloseKvStore(appId_, kvStorePtr_);
|
||||
}
|
||||
|
||||
bool DefaultAppDb::OpenKvDb()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::GetDataFromDb(int32_t userId, std::map<std::string, Element>& infos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::SaveDataToDb(int32_t userId, const std::map<std::string, Element>& infos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::DeleteDataFromDb(int32_t userId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::GetDefaultApplicationInfos(int32_t userId, std::map<std::string, Element>& infos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::GetDefaultApplicationInfo(int32_t userId, const std::string& type, Element& element)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::SetDefaultApplicationInfos(int32_t userId, const std::map<std::string, Element>& infos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::SetDefaultApplicationInfo(int32_t userId, const std::string& type, const Element& element)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::DeleteDefaultApplicationInfos(int32_t userId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppDb::DeleteDefaultApplicationInfo(int32_t userId, const std::string& type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
76
services/bundlemgr/src/default_app/default_app_host_impl.cpp
Normal file
76
services/bundlemgr/src/default_app/default_app_host_impl.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "default_app_host_impl.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "bundle_mgr_service.h"
|
||||
#include "bundle_permission_mgr.h"
|
||||
#include "bundle_promise.h"
|
||||
#include "bundle_util.h"
|
||||
#include "element.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "status_receiver_host.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
bool DefaultAppHostImpl::IsDefaultApplication(const std::string& type)
|
||||
{
|
||||
APP_LOGI("begin to call IsDefaultApplication.");
|
||||
int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE;
|
||||
return defaultAppMgr_->IsDefaultApplication(userId, type);
|
||||
}
|
||||
|
||||
bool DefaultAppHostImpl::GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo)
|
||||
{
|
||||
APP_LOGI("begin to GetDefaultApplication.");
|
||||
return defaultAppMgr_->GetDefaultApplication(userId, type, bundleInfo);
|
||||
}
|
||||
|
||||
bool DefaultAppHostImpl::SetDefaultApplication(int32_t userId, const std::string& type, const Want& want)
|
||||
{
|
||||
APP_LOGI("begin to SetDefaultApplication.");
|
||||
// case1 : ElementName is empty.
|
||||
ElementName elementName = want.GetElement();
|
||||
bool isEmpty = elementName.GetBundleName().empty() && elementName.GetModuleName().empty()
|
||||
&& elementName.GetAbilityName().empty();
|
||||
if (isEmpty) {
|
||||
APP_LOGI("ElementName is empty.");
|
||||
Element element;
|
||||
return defaultAppMgr_->SetDefaultApplication(userId, type, element);
|
||||
}
|
||||
// case2 : ElementName is valid ability or valid extension.
|
||||
auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
|
||||
if (dataMgr == nullptr) {
|
||||
APP_LOGE("DataMgr is nullptr");
|
||||
return false;
|
||||
}
|
||||
Element element;
|
||||
bool ret = dataMgr->GetElement(userId, elementName, element);
|
||||
if (!ret) {
|
||||
APP_LOGE("GetElement failed.");
|
||||
return false;
|
||||
}
|
||||
return defaultAppMgr_->SetDefaultApplication(userId, type, element);
|
||||
}
|
||||
|
||||
bool DefaultAppHostImpl::ResetDefaultApplication(int32_t userId, const std::string& type)
|
||||
{
|
||||
APP_LOGI("begin to ResetDefaultApplication.");
|
||||
return defaultAppMgr_->ResetDefaultApplication(userId, type);
|
||||
}
|
||||
}
|
||||
}
|
162
services/bundlemgr/src/default_app/default_app_mgr.cpp
Normal file
162
services/bundlemgr/src/default_app/default_app_mgr.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "default_app_mgr.h"
|
||||
|
||||
#include "bundle_data_mgr.h"
|
||||
#include "bundle_mgr_service.h"
|
||||
#include "bundle_permission_mgr.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
const std::string BROWSER = "BROWSER";
|
||||
const std::string IMAGE = "IMAGE";
|
||||
const std::string AUDIO = "AUDIO";
|
||||
const std::string VIDEO = "VIDEO";
|
||||
const std::string PERMISSION_GET_DEFAULT_APPLICATION = "ohos.permission.GET_DEFAULT_APPLICATION";
|
||||
const std::string PERMISSION_SET_DEFAULT_APPLICATION = "ohos.permission.SET_DEFAULT_APPLICATION";
|
||||
}
|
||||
|
||||
DefaultAppMgr::DefaultAppMgr()
|
||||
{
|
||||
APP_LOGI("create DefaultAppMgr.");
|
||||
InitSupportAppTypes();
|
||||
}
|
||||
|
||||
DefaultAppMgr::~DefaultAppMgr()
|
||||
{
|
||||
APP_LOGI("destroy DefaultAppMgr.");
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsDefaultApplication(int32_t userId, const std::string& type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::GetDefaultApplication(int32_t userId, const std::string& type, BundleInfo& bundleInfo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::SetDefaultApplication(int32_t userId, const std::string& type, const Element& element)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::ResetDefaultApplication(int32_t userId, const std::string& type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::GetBundleInfo(int32_t userId, const std::string& type, const Element& element,
|
||||
BundleInfo& bundleInfo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsMatch(const std::string& type, const std::vector<Skill>& skills)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::MatchAppType(const std::string& type, const std::vector<Skill>& skills)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsBrowserSkillsValid(const std::vector<Skill>& skills)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsImageSkillsValid(const std::vector<Skill>& skills)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsAudioSkillsValid(const std::vector<Skill>& skills)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsVideoSkillsValid(const std::vector<Skill>& skills)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::MatchFileType(const std::string& type, const std::vector<Skill>& skills)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void DefaultAppMgr::InitSupportAppTypes()
|
||||
{
|
||||
supportAppTypes.insert(BROWSER);
|
||||
supportAppTypes.insert(IMAGE);
|
||||
supportAppTypes.insert(AUDIO);
|
||||
supportAppTypes.insert(VIDEO);
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsAppType(const std::string& type)
|
||||
{
|
||||
if (type.empty()) {
|
||||
return false;
|
||||
}
|
||||
return supportAppTypes.find(type) != supportAppTypes.end();
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsFileType(const std::string& type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsUserIdExist(int32_t userId)
|
||||
{
|
||||
std::shared_ptr<BundleDataMgr> dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
|
||||
if (dataMgr == nullptr) {
|
||||
APP_LOGE("get BundleDataMgr failed.");
|
||||
return false;
|
||||
}
|
||||
return dataMgr->HasUserId(userId);
|
||||
}
|
||||
|
||||
bool DefaultAppMgr::IsElementValid(const Element& element)
|
||||
{
|
||||
const std::string& bundleName = element.bundleName;
|
||||
const std::string& moduleName = element.moduleName;
|
||||
const std::string& abilityName = element.abilityName;
|
||||
const std::string& extensionName = element.extensionName;
|
||||
if (bundleName.empty()) {
|
||||
APP_LOGE("bundleName empty, Element invalid.");
|
||||
return false;
|
||||
}
|
||||
if (moduleName.empty()) {
|
||||
APP_LOGE("moduleName empty, Element invalid.");
|
||||
return false;
|
||||
}
|
||||
if (abilityName.empty() && extensionName.empty()) {
|
||||
APP_LOGE("abilityName and extensionName both empty, Element invalid.");
|
||||
return false;
|
||||
}
|
||||
if (!abilityName.empty() && !extensionName.empty()) {
|
||||
APP_LOGE("abilityName and extensionName both non-empty, Element invalid.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user