feat: SetAppAccessToken时,将render进程标志位renderFlag置1

对外变更:
SetAppAccessToken接口返回值类型改动,有void修改为int,用于判断设置accesstoken是否成功

Close: #I7IDCL

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: I3f20b176c636fa990811029351d06c336432b542
This commit is contained in:
zhangdengyu 2023-07-05 14:59:03 +08:00
parent 24b69c61b7
commit 0d98518522
6 changed files with 37 additions and 7 deletions

View File

@ -175,6 +175,7 @@ ohos_static_library("nwebspawn_server") {
deps = [ "//foundation/communication/netmanager_base/services/netmanagernative/netsys_client:netsys_client" ]
external_deps = [
"access_token:libtoken_setproc",
"access_token:libtokenid_sdk",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog_native:libhilog",

View File

@ -29,12 +29,36 @@
const char* RENDERER_NAME = "renderer";
#endif
void SetAppAccessToken(struct AppSpawnContent_ *content, AppSpawnClient *client)
#ifdef NWEB_SPAWN
#include "tokenid_kit.h"
#include "access_token.h"
using namespace OHOS::Security::AccessToken;
#endif
int SetAppAccessToken(struct AppSpawnContent_ *content, AppSpawnClient *client)
{
AppSpawnClientExt *appProperty = reinterpret_cast<AppSpawnClientExt *>(client);
int32_t ret = SetSelfTokenID(appProperty->property.accessTokenIdEx);
#if NWEB_SPAWN
TokenIdKit tokenIdKit;
uint64_t tokenId = tokenIdKit.GetRenderTokenID(appProperty->property.accessTokenIdEx);
if (tokenId == static_cast<uint64_t>(INVALID_TOKENID)) {
APPSPAWN_LOGE("AppSpawnServer::Failed to get render token id, renderTokenId =%{public}llu",
static_cast<unsigned long long>(tokenId));
return -1;
}
#else
uint64_t tokenId = appProperty->property.accessTokenIdEx;
#endif
int32_t ret = SetSelfTokenID(tokenId);
if (ret != 0) {
APPSPAWN_LOGE("AppSpawnServer::set access token id failed, ret = %{public}d", ret);
return -1;
}
APPSPAWN_LOGV("AppSpawnServer::set access token id = %{public}llu, ret = %{public}d %{public}d",
static_cast<unsigned long long>(appProperty->property.accessTokenIdEx), ret, getuid());
return 0;
}
void SetSelinuxCon(struct AppSpawnContent_ *content, AppSpawnClient *client)

View File

@ -25,7 +25,7 @@ extern "C" {
#endif
int32_t SetAppSandboxProperty(struct AppSpawnContent_ *content, AppSpawnClient *client);
void SetAppAccessToken(struct AppSpawnContent_ *content, AppSpawnClient *client);
int SetAppAccessToken(struct AppSpawnContent_ *content, AppSpawnClient *client);
void SetSelinuxCon(struct AppSpawnContent_ *content, AppSpawnClient *client);
void LoadExtendLib(AppSpawnContent *content);
void RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client);

View File

@ -145,6 +145,7 @@ static int AppSpawnChild(void *arg)
AppSandboxArg *sandbox = (AppSandboxArg *)arg;
struct AppSpawnContent_ *content = sandbox->content;
AppSpawnClient *client = sandbox->client;
int ret = -1;
#ifdef OHOS_DEBUG
struct timespec tmStart = {0};
@ -156,10 +157,13 @@ static int AppSpawnChild(void *arg)
}
if (content->setAppAccessToken != NULL) {
content->setAppAccessToken(content, client);
ret = content->setAppAccessToken(content, client);
if (ret != 0) {
APPSPAWN_LOGE("AppSpawnChild, set app token id failed");
return -1;
}
}
int ret = -1;
if ((content->getWrapBundleNameValue != NULL && content->getWrapBundleNameValue(content, client) == 0) ||
((client->flags & APP_COLD_START) != 0)) {
// cold start fail, to start normal

View File

@ -58,7 +58,7 @@ typedef struct AppSpawnContent_ {
// for child
void (*clearEnvironment)(struct AppSpawnContent_ *content, AppSpawnClient *client);
void (*initDebugParams)(struct AppSpawnContent_ *content, AppSpawnClient *client);
void (*setAppAccessToken)(struct AppSpawnContent_ *content, AppSpawnClient *client);
int (*setAppAccessToken)(struct AppSpawnContent_ *content, AppSpawnClient *client);
int (*setAppSandbox)(struct AppSpawnContent_ *content, AppSpawnClient *client);
int (*setKeepCapabilities)(struct AppSpawnContent_ *content, AppSpawnClient *client);
int (*setFileDescriptors)(struct AppSpawnContent_ *content, AppSpawnClient *client);

View File

@ -213,7 +213,8 @@ HWTEST(AppSpawnStandardTest, App_Spawn_Standard_002, TestSize.Level0)
EXPECT_NE(content->setProcessName(content, &client->client, nullptr, 0), 0);
content->setAppSandbox(content, &client->client);
content->setAppAccessToken(content, &client->client);
int ret = content->setAppAccessToken(content, &client->client);
EXPECT_EQ(ret, 0);
EXPECT_NE(content->coldStartApp(content, &client->client), 0);
GTEST_LOG_(INFO) << "App_Spawn_Standard_002 end";