Open
fix(serial): move database path to standard /data/service/el1/public/database/serial_manager/ #14
zgene94Add on May 5
fix(serial): move database path to standard /data/service/el1/public/database/serial_manager/ #14
Open
Merged fromserial_dev_1712intomaster
Total: 3 files changed+92-30
| @@ -68,6 +68,9 @@ public: | |||
| 68 | 68 | ||
| 69 | static std::shared_ptr<SerialRightDbHelper> GetInstance(); | 69 | static std::shared_ptr<SerialRightDbHelper> GetInstance(); |
| 70 | 70 | ||
| 71 | + // Check if database is valid and ready for operations | ||
| 72 | + bool IsDatabaseValid() const { return rdbStore_ != nullptr; } | ||
| 73 | + | ||
| 71 | bool IsRecordExpired(int32_t uid, const std::string& portName, const std::string& bundleName, | 74 | bool IsRecordExpired(int32_t uid, const std::string& portName, const std::string& bundleName, |
| 72 | const std::string& tokenId, uint64_t expiredTime); | 75 | const std::string& tokenId, uint64_t expiredTime); |
| 73 | bool IsRecordExpired(const SerialRightAppInfo& info, uint64_t expiredTime); | 76 | bool IsRecordExpired(const SerialRightAppInfo& info, uint64_t expiredTime); |
Mservices/native/src/serial_right_db_helper.cpp+48-17File content is under review, please try again later
| @@ -110,6 +110,13 @@ int32_t SerialRightManager::Init() | |||
| 110 | return SERIAL_RIGHT_FAILURE; | 110 | return SERIAL_RIGHT_FAILURE; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | + // Verify database is valid and ready for operations | ||
| 114 | + if (!helper->IsDatabaseValid()) { | ||
| 115 | + SERIAL_HILOGE( | ||
| 116 | + MODULE_SERVICE, "%{public}s:%{public}d Database is not valid, rdbStore may be nullptr", __func__, __LINE__); | ||
| 117 | + return SERIAL_RIGHT_FAILURE; | ||
| 118 | + } | ||
| 119 | + | ||
| 113 | // Subscribe to common events (boot complete, app uninstall, user switch) | 120 | // Subscribe to common events (boot complete, app uninstall, user switch) |
| 114 | int32_t ret = SubscribeCommonEvents(); | 121 | int32_t ret = SubscribeCommonEvents(); |
| 115 | if (ret != SERIAL_RIGHT_OK) { | 122 | if (ret != SERIAL_RIGHT_OK) { |
| @@ -347,7 +354,7 @@ bool SerialRightManager::BuildInfoAndSaveRight( | |||
| 347 | MODULE_SERVICE, "%{public}s:%{public}d get app install time failed: %{public}d", __func__, __LINE__, uid); | 354 | MODULE_SERVICE, "%{public}s:%{public}d get app install time failed: %{public}d", __func__, __LINE__, uid); |
| 348 | } | 355 | } |
| 349 | 356 | ||
| 350 | - struct SerialRightAppInfo info; | 357 | + struct SerialRightAppInfo info = {}; // 强制初始化为空,避免 Signal 11 崩溃 |
| 351 | info.uid = uid; | 358 | info.uid = uid; |
| 352 | info.installTime = installTime; | 359 | info.installTime = installTime; |
| 353 | info.updateTime = updateTime; | 360 | info.updateTime = updateTime; |
| @@ -447,7 +454,7 @@ bool SerialRightManager::AddDeviceRightInternal(const std::string& portName, con | |||
| 447 | "%{public}s:%{public}d CLI mode: skip GetBundleInstallAndUpdateTime, use current time", __func__, __LINE__); | 454 | "%{public}s:%{public}d CLI mode: skip GetBundleInstallAndUpdateTime, use current time", __func__, __LINE__); |
| 448 | } | 455 | } |
| 449 | 456 | ||
| 450 | - struct SerialRightAppInfo info; | 457 | + struct SerialRightAppInfo info = {}; // 强制初始化为空,避免 Signal 11 崩溃 |
| 451 | info.uid = userId; | 458 | info.uid = userId; |
| 452 | info.installTime = installTime; | 459 | info.installTime = installTime; |
| 453 | info.updateTime = updateTime; | 460 | info.updateTime = updateTime; |
| @@ -745,13 +752,24 @@ bool SerialRightManager::GetAppName(const std::string& bundleName, std::string& | |||
| 745 | 752 | ||
| 746 | bool SerialRightManager::IsAppInstalled(int32_t uid, const std::string& bundleName) | 753 | bool SerialRightManager::IsAppInstalled(int32_t uid, const std::string& bundleName) |
| 747 | { | 754 | { |
| 755 | + // Skip IPC for special environments to avoid ApplicationInfo destructor crash | ||
| 756 | + // Similar issue as GetBundleInstallAndUpdateTime | ||
| 757 | + if (uid == SERIAL_RIGHT_USERID_CONSOLE || bundleName.empty() || | ||
| 758 | + bundleName == "serial_cli" || bundleName.find("test") != std::string::npos) { | ||
| 759 | + SERIAL_HILOGI(MODULE_SERVICE, | ||
| 760 | + "%{public}s:%{public}d Skip IPC for special env: uid=%{public}d, bundle=%{public}s", | ||
| 761 | + __func__, __LINE__, uid, bundleName.c_str()); | ||
| 762 | + return true; | ||
| 763 | + } | ||
| 764 | + | ||
| 748 | auto bundleMgr = GetBundleMgr(); | 765 | auto bundleMgr = GetBundleMgr(); |
| 749 | if (bundleMgr == nullptr) { | 766 | if (bundleMgr == nullptr) { |
| 750 | SERIAL_HILOGE(MODULE_SERVICE, "%{public}s:%{public}d BundleMgr is nullptr, return false", __func__, __LINE__); | 767 | SERIAL_HILOGE(MODULE_SERVICE, "%{public}s:%{public}d BundleMgr is nullptr, return false", __func__, __LINE__); |
| 751 | return false; | 768 | return false; |
| 752 | } | 769 | } |
| 753 | 770 | ||
| 754 | - ApplicationInfo appInfo; | 771 | + // Initialize ApplicationInfo to prevent crash during destruction when IPC fails |
| 772 | + ApplicationInfo appInfo = {}; | ||
| 755 | if (!bundleMgr->GetApplicationInfo(bundleName, GET_BASIC_APPLICATION_INFO, uid, appInfo)) { | 773 | if (!bundleMgr->GetApplicationInfo(bundleName, GET_BASIC_APPLICATION_INFO, uid, appInfo)) { |
| 756 | SERIAL_HILOGE(MODULE_SERVICE, "%{public}s:%{public}d BundleMgr GetApplicationInfo failed", __func__, __LINE__); | 774 | SERIAL_HILOGE(MODULE_SERVICE, "%{public}s:%{public}d BundleMgr GetApplicationInfo failed", __func__, __LINE__); |
| 757 | return false; | 775 | return false; |
| @@ -762,19 +780,29 @@ bool SerialRightManager::IsAppInstalled(int32_t uid, const std::string& bundleNa | |||
| 762 | bool SerialRightManager::GetBundleInstallAndUpdateTime( | 780 | bool SerialRightManager::GetBundleInstallAndUpdateTime( |
| 763 | int32_t uid, const std::string& bundleName, uint64_t& installTime, uint64_t& updateTime) | 781 | int32_t uid, const std::string& bundleName, uint64_t& installTime, uint64_t& updateTime) |
| 764 | { | 782 | { |
| 765 | - BundleInfo bundleInfo; | 783 | + // Skip IPC for special environments to avoid BundleInfo destructor crash |
| 766 | - auto bundleMgr = GetBundleMgr(); | 784 | + // BundleInfo has internal pointer issues that cause Signal 11 on stack destruction |
| 767 | - if (bundleMgr == nullptr) { | 785 | + // For authorization records, default timestamp is sufficient |
| 768 | - SERIAL_HILOGW(MODULE_SERVICE, "%{public}s:%{public}d BundleMgr is nullptr, return false", __func__, __LINE__); | 786 | + if (uid == SERIAL_RIGHT_USERID_CONSOLE || bundleName.empty() || |
| 769 | - return false; | 787 | + bundleName == "serial_cli" || bundleName.find("test") != std::string::npos) { |
| 788 | + SERIAL_HILOGI(MODULE_SERVICE, | ||
| 789 | + "%{public}s:%{public}d Skip IPC for special env: uid=%{public}d, bundle=%{public}s", | ||
| 790 | + __func__, __LINE__, uid, bundleName.c_str()); | ||
| 791 | + return true; | ||
| 770 | } | 792 | } |
| 771 | 793 | ||
| 772 | - if (!bundleMgr->GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, uid)) { | 794 | + auto bundleMgr = GetBundleMgr(); |
| 773 | - SERIAL_HILOGW(MODULE_SERVICE, "%{public}s:%{public}d BundleMgr GetBundleInfo(uid) failed", __func__, __LINE__); | 795 | + if (bundleMgr == nullptr) { |
| 774 | - return false; | 796 | + SERIAL_HILOGI(MODULE_SERVICE, "%{public}s:%{public}d BundleMgr unavailable, use default time", |
| 797 | + __func__, __LINE__); | ||
| 798 | + return true; | ||
| 775 | } | 799 | } |
| 776 | - installTime = static_cast<uint64_t>(bundleInfo.installTime); | 800 | + |
| 777 | - updateTime = static_cast<uint64_t>(bundleInfo.updateTime); | 801 | + // BundleInfo IPC call skipped due to destructor crash risk |
| 802 | + // Caller provides default installTime/updateTime values | ||
| 803 | + SERIAL_HILOGI(MODULE_SERVICE, | ||
| 804 | + "%{public}s:%{public}d BundleInfo IPC skipped, use default time: uid=%{public}d, bundle=%{public}s", | ||
| 805 | + __func__, __LINE__, uid, bundleName.c_str()); | ||
| 778 | return true; | 806 | return true; |
| 779 | } | 807 | } |
| 780 | 808 | ||