1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "camera_util.h"
16 #include <cstdint>
17 #include <securec.h>
18 #include <parameter.h>
19 #include <parameters.h>
20 #include "camera_log.h"
21 #include "access_token.h"
22 #include "accesstoken_kit.h"
23 #include "privacy_kit.h"
24 #include "display.h"
25 #include "display_manager.h"
26 #include "display/composer/v1_1/display_composer_type.h"
27 #include "iservice_registry.h"
28 #include "bundle_mgr_interface.h"
29 #include "system_ability_definition.h"
30 #include "ipc_skeleton.h"
31 #include "tokenid_kit.h"
32
33 namespace OHOS {
34 namespace CameraStandard {
35 using namespace OHOS::HDI::Display::Composer::V1_1;
36 static bool g_tablet = false;
37
38 std::unordered_map<int32_t, int32_t> g_cameraToPixelFormat = {
39 {OHOS_CAMERA_FORMAT_RGBA_8888, GRAPHIC_PIXEL_FMT_RGBA_8888},
40 {OHOS_CAMERA_FORMAT_YCBCR_420_888, GRAPHIC_PIXEL_FMT_YCBCR_420_SP},
41 {OHOS_CAMERA_FORMAT_YCRCB_420_SP, GRAPHIC_PIXEL_FMT_YCRCB_420_SP}, // NV21
42 {OHOS_CAMERA_FORMAT_JPEG, GRAPHIC_PIXEL_FMT_BLOB},
43 {OHOS_CAMERA_FORMAT_YCBCR_P010, GRAPHIC_PIXEL_FMT_YCBCR_P010},
44 {OHOS_CAMERA_FORMAT_YCRCB_P010, GRAPHIC_PIXEL_FMT_YCRCB_P010},
45 {OHOS_CAMERA_FORMAT_YCBCR_420_SP, GRAPHIC_PIXEL_FMT_YCBCR_420_SP},
46 {OHOS_CAMERA_FORMAT_422_YUYV, GRAPHIC_PIXEL_FMT_YUYV_422_PKG},
47 {OHOS_CAMERA_FORMAT_DEPTH_16, GRAPHIC_PIXEL_FMT_RGBA16_FLOAT},
48 {OHOS_CAMERA_FORMAT_DNG, GRAPHIC_PIXEL_FMT_BLOB},
49 {OHOS_CAMERA_FORMAT_DNG_XDRAW, GRAPHIC_PIXEL_FMT_BLOB},
50 };
51
52 std::map<int, std::string> g_cameraPos = {
53 {0, "Front"},
54 {1, "Back"},
55 {2, "Other"},
56 };
57
58 std::map<int, std::string> g_cameraType = {
59 {0, "Wide-Angle"},
60 {1, "Ultra-Wide"},
61 {2, "TelePhoto"},
62 {3, "TrueDepth"},
63 {4, "Logical"},
64 {5, "Unspecified"},
65 };
66
67 std::map<int, std::string> g_cameraConType = {
68 {0, "Builtin"},
69 {1, "USB-Plugin"},
70 {2, "Remote"},
71 };
72
73 std::map<int, std::string> g_cameraFormat = {
74 {1, "RGBA_8888"},
75 {2, "YCBCR_420_888"},
76 {3, "YCRCB_420_SP"},
77 {4, "YCBCR_420_SP"},
78 {5, "JPEG"},
79 {6, "YCBCR_P010"},
80 {7, "YCRCB_P010"},
81 {8, "DNG"},
82 {9, "422_YUYV"},
83 };
84
85 std::map<int, std::string> g_cameraFocusMode = {
86 {0, "Manual"},
87 {1, "Continuous-Auto"},
88 {2, "Auto"},
89 {3, "Locked"},
90 };
91
92 std::map<int, std::string> g_cameraExposureMode = {
93 {0, "Manual"},
94 {1, "Continuous-Auto"},
95 {2, "Locked"},
96 {3, "Auto"},
97 };
98
99 std::map<int, std::string> g_cameraFlashMode = {
100 {0, "Close"},
101 {1, "Open"},
102 {2, "Auto"},
103 {3, "Always-Open"},
104 };
105
106 std::map<int, std::string> g_cameraVideoStabilizationMode = {
107 {0, "Off"},
108 {1, "Low"},
109 {2, "Middle"},
110 {3, "High"},
111 {4, "Auto"},
112 };
113
114 std::map<int, std::string> g_cameraPrelaunchAvailable = {
115 {0, "False"},
116 {1, "True"},
117 };
118
119 std::map<int, std::string> g_cameraQuickThumbnailAvailable = {
120 {0, "False"},
121 {1, "True"},
122 };
123
124 std::map<int, std::string> g_cameraQualityPrioritization = {
125 {0, "HighQuality "},
126 {1, "PowerBalance "},
127 };
128
129 bool g_cameraDebugOn = false;
130
HdiToCameraErrorType(OHOS::HDI::Camera::V1_3::ErrorType type)131 int32_t HdiToCameraErrorType(OHOS::HDI::Camera::V1_3::ErrorType type)
132 {
133 enum CamServiceError err = CAMERA_UNKNOWN_ERROR;
134
135 switch (type) {
136 case HDI::Camera::V1_3::FATAL_ERROR:
137 err = CAMERA_DEVICE_FATAL_ERROR;
138 break;
139 case HDI::Camera::V1_3::REQUEST_TIMEOUT:
140 err = CAMERA_DEVICE_REQUEST_TIMEOUT;
141 break;
142 case HDI::Camera::V1_3::DRIVER_ERROR:
143 err = CAMERA_DEVICE_DRIVER_ERROR;
144 break;
145 case HDI::Camera::V1_3::DEVICE_PREEMPT:
146 err = CAMERA_DEVICE_PREEMPTED;
147 break;
148 case HDI::Camera::V1_3::DEVICE_DISCONNECT:
149 err = CAMERA_DEVICE_DISCONNECT;
150 break;
151 case HDI::Camera::V1_3::SENSOR_DATA_ERROR:
152 err = CAMERA_DEVICE_SENSOR_DATA_ERROR;
153 break;
154 case HDI::Camera::V1_3::DCAMERA_ERROR_BEGIN:
155 err = CAMERA_DCAMERA_ERROR_BEGIN;
156 break;
157 case HDI::Camera::V1_3::DCAMERA_ERROR_DEVICE_IN_USE:
158 err = CAMERA_DCAMERA_ERROR_DEVICE_IN_USE;
159 break;
160 case HDI::Camera::V1_3::DCAMERA_ERROR_NO_PERMISSION:
161 err = CAMERA_DCAMERA_ERROR_NO_PERMISSION;
162 break;
163 default:
164 MEDIA_ERR_LOG("HdiToCameraType() error type from hdi: %{public}d", type);
165 break;
166 }
167 return err;
168 }
169
HdiToServiceError(OHOS::HDI::Camera::V1_0::CamRetCode ret)170 int32_t HdiToServiceError(OHOS::HDI::Camera::V1_0::CamRetCode ret)
171 {
172 enum CamServiceError err = CAMERA_UNKNOWN_ERROR;
173
174 switch (ret) {
175 case HDI::Camera::V1_0::NO_ERROR:
176 err = CAMERA_OK;
177 break;
178 case HDI::Camera::V1_0::CAMERA_BUSY:
179 err = CAMERA_DEVICE_BUSY;
180 break;
181 case HDI::Camera::V1_0::INVALID_ARGUMENT:
182 err = CAMERA_INVALID_ARG;
183 break;
184 case HDI::Camera::V1_0::CAMERA_CLOSED:
185 err = CAMERA_DEVICE_CLOSED;
186 break;
187 default:
188 MEDIA_ERR_LOG("HdiToServiceError() error code from hdi: %{public}d", ret);
189 break;
190 }
191 return err;
192 }
193
HdiToServiceErrorV1_2(HDI::Camera::V1_2::CamRetCode ret)194 int32_t HdiToServiceErrorV1_2(HDI::Camera::V1_2::CamRetCode ret)
195 {
196 enum CamServiceError err = CAMERA_UNKNOWN_ERROR;
197
198 switch (ret) {
199 case HDI::Camera::V1_2::NO_ERROR:
200 err = CAMERA_OK;
201 break;
202 case HDI::Camera::V1_2::CAMERA_BUSY:
203 err = CAMERA_DEVICE_BUSY;
204 break;
205 case HDI::Camera::V1_2::INVALID_ARGUMENT:
206 err = CAMERA_INVALID_ARG;
207 break;
208 case HDI::Camera::V1_2::CAMERA_CLOSED:
209 err = CAMERA_DEVICE_CLOSED;
210 break;
211 case HDI::Camera::V1_2::DEVICE_ERROR:
212 err = CAMERA_DEVICE_ERROR;
213 break;
214 case HDI::Camera::V1_2::NO_PERMISSION:
215 err = CAMERA_NO_PERMISSION;
216 break;
217 case HDI::Camera::V1_2::DEVICE_CONFLICT:
218 err = CAMERA_DEVICE_CONFLICT;
219 break;
220 default:
221 MEDIA_ERR_LOG("HdiToServiceErrorV1_2() error code from hdi: %{public}d", ret);
222 break;
223 }
224 return err;
225 }
226
CreateMsg(const char * format,...)227 std::string CreateMsg(const char* format, ...)
228 {
229 va_list args;
230 va_start(args, format);
231 char msg[MAX_STRING_SIZE] = {0};
232 if (vsnprintf_s(msg, sizeof(msg), sizeof(msg) - 1, format, args) < 0) {
233 MEDIA_ERR_LOG("failed to call vsnprintf_s");
234 va_end(args);
235 return "";
236 }
237 va_end(args);
238 return msg;
239 }
240
IsHapTokenId(uint32_t tokenId)241 bool IsHapTokenId(uint32_t tokenId)
242 {
243 return Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) ==
244 Security::AccessToken::ATokenTypeEnum::TOKEN_HAP;
245 }
246
IsValidMode(int32_t opMode,std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility)247 bool IsValidMode(int32_t opMode, std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility)
248 {
249 if (opMode == 0 || opMode == 1 || opMode == 2) { // 0 is normal mode, 1 is capture mode, 2 is video mode
250 MEDIA_INFO_LOG("operationMode:%{public}d", opMode);
251 return true;
252 }
253 camera_metadata_item_t item;
254 int ret = Camera::FindCameraMetadataItem(cameraAbility->get(), OHOS_ABILITY_CAMERA_MODES, &item);
255 if (ret != CAM_META_SUCCESS || item.count == 0) {
256 MEDIA_ERR_LOG("Failed to find stream extend configuration in camera ability with return code %{public}d", ret);
257 ret = Camera::FindCameraMetadataItem(cameraAbility->get(),
258 OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS, &item);
259 if (ret == CAM_META_SUCCESS && item.count != 0) {
260 MEDIA_INFO_LOG("basic config no need valid mode");
261 return true;
262 }
263 return false;
264 }
265
266 for (uint32_t i = 0; i < item.count; i++) {
267 if (opMode == item.data.u8[i]) {
268 MEDIA_INFO_LOG("operationMode:%{public}d found in supported streams", opMode);
269 return true;
270 }
271 }
272 MEDIA_ERR_LOG("operationMode:%{public}d not found in supported streams", opMode);
273 return false;
274 }
275
DumpMetadata(std::shared_ptr<OHOS::Camera::CameraMetadata> cameraSettings)276 void DumpMetadata(std::shared_ptr<OHOS::Camera::CameraMetadata> cameraSettings)
277 {
278 if (cameraSettings == nullptr) {
279 return;
280 }
281 auto srcHeader = cameraSettings->get();
282 CHECK_ERROR_RETURN(srcHeader == nullptr);
283 auto srcItemCount = srcHeader->item_count;
284 camera_metadata_item_t item;
285 for (uint32_t index = 0; index < srcItemCount; index++) {
286 int ret = OHOS::Camera::GetCameraMetadataItem(srcHeader, index, &item);
287 CHECK_ERROR_RETURN_LOG(ret != CAM_META_SUCCESS, "Failed to get metadata item at index: %{public}d", index);
288 const char *name = OHOS::Camera::GetCameraMetadataItemName(item.item);
289 CHECK_ERROR_RETURN_LOG(name == nullptr, "U8ItemToString: get u8 item name fail!");
290 if (item.data_type == META_TYPE_BYTE) {
291 for (size_t k = 0; k < item.count; k++) {
292 MEDIA_DEBUG_LOG("tag index:%d, name:%s, value:%d", item.index, name, (uint8_t)(item.data.u8[k]));
293 }
294 } else if (item.data_type == META_TYPE_INT32) {
295 for (size_t k = 0; k < item.count; k++) {
296 MEDIA_DEBUG_LOG("tag index:%d, name:%s, value:%d", item.index, name, (int32_t)(item.data.i32[k]));
297 }
298 } else if (item.data_type == META_TYPE_UINT32) {
299 for (size_t k = 0; k < item.count; k++) {
300 MEDIA_DEBUG_LOG("tag index:%d, name:%s, value:%d", item.index, name, (uint32_t)(item.data.ui32[k]));
301 }
302 } else if (item.data_type == META_TYPE_FLOAT) {
303 for (size_t k = 0; k < item.count; k++) {
304 MEDIA_DEBUG_LOG("tag index:%d, name:%s, value:%f", item.index, name, (float)(item.data.f[k]));
305 }
306 } else if (item.data_type == META_TYPE_INT64) {
307 for (size_t k = 0; k < item.count; k++) {
308 MEDIA_DEBUG_LOG("tag index:%d, name:%s, value:%lld", item.index, name, (long long)(item.data.i64[k]));
309 }
310 } else if (item.data_type == META_TYPE_DOUBLE) {
311 for (size_t k = 0; k < item.count; k++) {
312 MEDIA_DEBUG_LOG("tag index:%d, name:%s, value:%lf", item.index, name, (double)(item.data.d[k]));
313 }
314 } else {
315 MEDIA_DEBUG_LOG("tag index:%d, name:%s", item.index, name);
316 }
317 }
318 }
319
GetClientBundle(int uid)320 std::string GetClientBundle(int uid)
321 {
322 std::string bundleName = "";
323 auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
324 CHECK_ERROR_RETURN_RET_LOG(samgr == nullptr, bundleName, "GetClientBundle Get ability manager failed");
325
326 sptr<IRemoteObject> object = samgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
327 CHECK_ERROR_RETURN_RET_LOG(object == nullptr, bundleName, "GetClientBundle object is NULL.");
328
329 sptr<OHOS::AppExecFwk::IBundleMgr> bms = iface_cast<OHOS::AppExecFwk::IBundleMgr>(object);
330 CHECK_ERROR_RETURN_RET_LOG(bms == nullptr, bundleName, "GetClientBundle bundle manager service is NULL.");
331
332 auto result = bms->GetNameForUid(uid, bundleName);
333 if (result != ERR_OK) {
334 MEDIA_DEBUG_LOG("GetClientBundle GetBundleNameForUid fail");
335 return "";
336 }
337 MEDIA_INFO_LOG("bundle name is %{public}s ", bundleName.c_str());
338
339 return bundleName;
340 }
341
GetClientNameByToken(int tokenIdNum)342 std::string GetClientNameByToken(int tokenIdNum)
343 {
344 using namespace Security::AccessToken;
345 AccessTokenID tokenId = static_cast<AccessTokenID>(tokenIdNum);
346 ATokenTypeEnum tokenType = AccessTokenKit::GetTokenType(tokenId);
347 if (tokenType == TOKEN_HAP) {
348 HapTokenInfoExt hapTokenInfo = {};
349 int ret = AccessTokenKit::GetHapTokenInfoExtension(tokenId, hapTokenInfo);
350 if (ret != 0) {
351 MEDIA_ERR_LOG("GetHapTokenInfoExtension fail, ret %{public}d", ret);
352 return "unknown";
353 }
354 return hapTokenInfo.baseInfo.bundleName;
355 } else if (tokenType == TOKEN_NATIVE) {
356 NativeTokenInfo nativeTokenInfo = {};
357 int ret = AccessTokenKit::GetNativeTokenInfo(tokenId, nativeTokenInfo);
358 if (ret != 0) {
359 MEDIA_ERR_LOG("GetNativeTokenInfo fail, ret %{public}d", ret);
360 return "unknown";
361 }
362 return nativeTokenInfo.processName;
363 } else {
364 MEDIA_ERR_LOG("unexpected token type %{public}d", tokenType);
365 return "unknown";
366 }
367 }
368
JudgmentPriority(const pid_t & pid,const pid_t & pidCompared)369 int32_t JudgmentPriority(const pid_t& pid, const pid_t& pidCompared)
370 {
371 return PRIORITY_LEVEL_SAME;
372 }
373
IsSameClient(const pid_t & pid,const pid_t & pidCompared)374 bool IsSameClient(const pid_t& pid, const pid_t& pidCompared)
375 {
376 return (pid == pidCompared);
377 }
378
IsInForeGround(const uint32_t callerToken)379 bool IsInForeGround(const uint32_t callerToken)
380 {
381 bool isAllowed = true;
382 if (IPCSkeleton::GetCallingUid() == 0) {
383 MEDIA_DEBUG_LOG("HCameraService::IsInForeGround isAllowed!");
384 return isAllowed;
385 }
386 if (IsHapTokenId(callerToken)) {
387 isAllowed = Security::AccessToken::PrivacyKit::IsAllowedUsingPermission(callerToken, OHOS_PERMISSION_CAMERA);
388 }
389 return isAllowed;
390 }
391
IsCameraNeedClose(const uint32_t callerToken,const pid_t & pid,const pid_t & pidCompared)392 bool IsCameraNeedClose(const uint32_t callerToken, const pid_t& pid, const pid_t& pidCompared)
393 {
394 bool needClose = !(IsInForeGround(callerToken) && (JudgmentPriority(pid, pidCompared) != PRIORITY_LEVEL_HIGHER));
395 if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) ==
396 Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) {
397 needClose = true;
398 }
399 MEDIA_INFO_LOG("IsCameraNeedClose pid = %{public}d, IsInForeGround = %{public}d, TokenType = %{public}d, "
400 "needClose = %{public}d",
401 pid, IsInForeGround(callerToken),
402 Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken), needClose);
403 return needClose;
404 }
405
CheckPermission(const std::string permissionName,uint32_t callerToken)406 int32_t CheckPermission(const std::string permissionName, uint32_t callerToken)
407 {
408 int permissionResult
409 = OHOS::Security::AccessToken::TypePermissionState::PERMISSION_DENIED;
410 Security::AccessToken::ATokenTypeEnum tokenType
411 = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken);
412 if ((tokenType == OHOS::Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE)
413 || (tokenType == OHOS::Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)) {
414 permissionResult = OHOS::Security::AccessToken::AccessTokenKit::VerifyAccessToken(
415 callerToken, permissionName);
416 } else {
417 MEDIA_ERR_LOG("HCameraService::CheckPermission: Unsupported Access Token Type");
418 return CAMERA_INVALID_ARG;
419 }
420
421 if (permissionResult != OHOS::Security::AccessToken::TypePermissionState::PERMISSION_GRANTED) {
422 MEDIA_ERR_LOG("HCameraService::CheckPermission: Permission to Access Camera Denied!!!!");
423 return CAMERA_NO_PERMISSION;
424 } else {
425 MEDIA_DEBUG_LOG("HCameraService::CheckPermission: Permission to Access Camera Granted!!!!");
426 }
427 return CAMERA_OK;
428 }
429
GetVersionId(uint32_t major,uint32_t minor)430 int32_t GetVersionId(uint32_t major, uint32_t minor)
431 {
432 const uint32_t offset = 8;
433 return static_cast<int32_t>((major << offset) | minor);
434 }
435
AddCameraPermissionUsedRecord(const uint32_t callingTokenId,const std::string permissionName)436 void AddCameraPermissionUsedRecord(const uint32_t callingTokenId, const std::string permissionName)
437 {
438 int32_t successCout = 1;
439 int32_t failCount = 0;
440 int32_t ret = Security::AccessToken::PrivacyKit::AddPermissionUsedRecord(callingTokenId, permissionName,
441 successCout, failCount);
442 MEDIA_INFO_LOG("AddPermissionUsedRecord");
443 if (ret != CAMERA_OK) {
444 MEDIA_ERR_LOG("AddPermissionUsedRecord failed.");
445 }
446 }
447
IsVerticalDevice()448 bool IsVerticalDevice()
449 {
450 bool isVerticalDevice = true;
451 auto display = OHOS::Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
452
453 CHECK_ERROR_RETURN_RET_LOG(display == nullptr, isVerticalDevice, "IsVerticalDevice GetDefaultDisplay failed");
454 MEDIA_DEBUG_LOG("GetDefaultDisplay:W(%{public}d),H(%{public}d),Orientation(%{public}d),Rotation(%{public}d)",
455 display->GetWidth(), display->GetHeight(), display->GetOrientation(), display->GetRotation());
456 bool isScreenVertical = display->GetRotation() == OHOS::Rosen::Rotation::ROTATION_0 ||
457 display->GetRotation() == OHOS::Rosen::Rotation::ROTATION_180;
458 bool isScreenHorizontal = display->GetRotation() == OHOS::Rosen::Rotation::ROTATION_90 ||
459 display->GetRotation() == OHOS::Rosen::Rotation::ROTATION_270;
460 isVerticalDevice = (isScreenVertical && (display->GetWidth() < display->GetHeight())) ||
461 (isScreenHorizontal && (display->GetWidth() > display->GetHeight()));
462 return isVerticalDevice;
463 }
464
GetStreamRotation(int32_t & sensorOrientation,camera_position_enum_t & cameraPosition,int & disPlayRotation,std::string & deviceClass)465 int32_t GetStreamRotation(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition, int& disPlayRotation,
466 std::string& deviceClass)
467 {
468 int32_t streamRotation = sensorOrientation;
469 int degrees = 0;
470
471 switch (disPlayRotation) {
472 case DISPALY_ROTATE_0: degrees = STREAM_ROTATE_0; break;
473 case DISPALY_ROTATE_1: degrees = STREAM_ROTATE_90; break;
474 case DISPALY_ROTATE_2: degrees = STREAM_ROTATE_180; break;
475 case DISPALY_ROTATE_3: degrees = STREAM_ROTATE_270; break; // 逆时针转90
476 }
477
478 g_tablet = (deviceClass == "tablet");
479 if (cameraPosition == OHOS_CAMERA_POSITION_FRONT) {
480 sensorOrientation = g_tablet ? sensorOrientation + STREAM_ROTATE_90 : sensorOrientation;
481 streamRotation = (STREAM_ROTATE_360 + sensorOrientation - degrees) % STREAM_ROTATE_360;
482 } else {
483 sensorOrientation = g_tablet ? sensorOrientation - STREAM_ROTATE_90 : sensorOrientation;
484 streamRotation = (sensorOrientation + degrees) % STREAM_ROTATE_360;
485 streamRotation = (STREAM_ROTATE_360 - streamRotation) % STREAM_ROTATE_360;
486 }
487 MEDIA_DEBUG_LOG("HStreamRepeat::SetStreamTransform filp streamRotation %{public}d, rotate %{public}d",
488 streamRotation, disPlayRotation);
489 return streamRotation;
490 }
491
CheckSystemApp()492 bool CheckSystemApp()
493 {
494 Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
495 Security::AccessToken::ATokenTypeEnum tokenType =
496 Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken);
497 if (tokenType != Security::AccessToken::TOKEN_HAP) {
498 MEDIA_DEBUG_LOG("Caller is not a application.");
499 return true;
500 }
501 uint64_t accessTokenId = IPCSkeleton::GetCallingFullTokenID();
502 bool isSystemApplication = Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(accessTokenId);
503 MEDIA_DEBUG_LOG("isSystemApplication:%{public}d", isSystemApplication);
504 return isSystemApplication;
505 }
506
SplitString(const std::string & input,char delimiter)507 std::vector<std::string> SplitString(const std::string& input, char delimiter)
508 {
509 std::vector<std::string> result;
510 std::stringstream ss(input);
511 std::string token;
512
513 while (std::getline(ss, token, delimiter)) {
514 result.push_back(token);
515 }
516 return result;
517 }
518
GetTimestamp()519 int64_t GetTimestamp()
520 {
521 auto now = std::chrono::system_clock::now();
522 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
523 return duration.count();
524 }
525 } // namespace CameraStandard
526 } // namespace OHOS
527