fix(ans): fix cross-SO singleton issue by adding AnsNotification::GetInstance()
Created-by: cheerful_ricky
Commit-by: CheerfulRicky
Merged-by: openharmony_ci
Description: ## Problem
`DelayedSingleton<AnsNotification>::GetInstance()` returns different singleton objects in different shared libraries because the template's static members (`instance_`, `mutex_`) have vague linkage (COMDAT) and are hidden per-SO by `-fvisibility=hidden` + version scripts.
## Solution
1. **Add `AnsNotification::GetInstance()`** using function-local static (C++11 thread-safe, defined out-of-line in `ans_notification.cpp` within `libans_innerkits`, symbol exported via `*Ans*` in `.map`)
2. **Replace ALL callers** (NAPI/ANI/Tools/Tests/CJ FFI) from `DelayedSingleton<AnsNotification>::GetInstance()` to `AnsNotification::GetInstance()`
3. **Clean up** `#include singleton.h` from files that no longer use `DelayedSingleton` (kept in `ans_manager_death_recipient.h` and `pixelmap_cache_manager.h` which still use `DelayedSingleton` as base class)
## Why it works
The function-local static in `ans_notification.cpp` lives in `libans_innerkits.so`'s data segment. `AnsNotification::GetInstance()` is a non-inline member function compiled only in `libans_innerkits.so` and exported via `*Ans*` pattern in `libans_innerkits.map`. All SOs call this exported function through dynamic linking, sharing the single instance.
## Verification
Syntax-checked key files with exact ninja build flags: `ans_notification.cpp`, `notification_helper.cpp`, `ans_manager_death_recipient.cpp`, `napi_cancel.cpp`, `ani_cance.cpp`, `notification_manager_impl.cpp` (CJ FFI), `notification_shell_command.cpp` (Tools) — all passed.
Co-Authored-By: Agent
See merge request: openharmony/notification_distributed_notification_service!4960
DelayedSingleton<AnsNotification>::GetInstance() returns different
singleton objects in different shared libraries because the template's
static members (instance_, mutex_) have vague linkage (COMDAT) and are
hidden per-SO by -fvisibility=hidden + version scripts.
Solution:
1. Add AnsNotification::GetInstance() using function-local static
(C++11 thread-safe, defined out-of-line in ans_notification.cpp
within libans_innerkits, symbol exported via *Ans* in .map)
2. Replace ALL callers (NAPI/ANI/Tools/Tests/CJ FFI) from
DelayedSingleton<AnsNotification>::GetInstance() to
AnsNotification::GetInstance()
3. Fix singleton.h include hygiene:
- Add #include singleton.h to 34 files that use Singleton<>,
DelayedSingleton<>, DECLARE_SINGLETON etc. but relied on
transitive includes
- Add #include nocopyable.h to 7 files that use
DISALLOW_COPY_AND_MOVE but relied on transitive includes
- Remove #include singleton.h from 70 files that no longer use
any singleton.h symbols after the DelayedSingleton replacement
The function-local static in ans_notification.cpp lives in
libans_innerkits.so's data segment. AnsNotification::GetInstance() is
a non-inline member function compiled only in libans_innerkits.so and
exported via *Ans* pattern in libans_innerkits.map. All SOs call this
exported function through dynamic linking, sharing the single instance.
Co-Authored-By: Agent
Signed-off-by: CheerfulRicky <yuegang7@h-partners.com>
Change-Id: I1089cfa5bb010daf37c68333a1e71c55fc1f16f3
Add comprehensive null pointer validation across frameworks and services
layers (notification_request, subscriber_image_util, napi converters,
geofence service, live view service, preferences, subscriber manager, etc.)
to prevent null-dereference crashes, and add unit tests covering the new
null-check branches.
Co-Authored-By: Agent
Signed-off-by: stepend98 <yangjun273@huawei.com>
Change-Id: I62f9e3a450dbdbbcf7b0657c7187c6f7709b01df
Refactor test mocks to inherit from IRemoteStub<IAnsManager> instead of
IAnsManager, enabling iface_cast to return mock objects directly via the
stub path. This approach is compatible with -Wl,-Bsymbolic on
libans_innerkits.so because it uses SAMgr field injection + iface_cast
stub path instead of link-time symbol interposition.
Changes:
- MockAnsManagerProxy: IAnsManager → IRemoteStub<IAnsManager>
- MockAnsManagerInterface: IAnsManager → IRemoteStub<IAnsManager>
- mock_service_registry.h: fix undefined ERR_ANS_SERVICE_NOT_CONNECTED
- Remove mock_ans_notification.h and mock_ans_manager_stub_object.h
- ans_notification.h: no production code change
- Add samgr:samgr_proxy dependency to test BUILD.gn files
Verified: 194 tests passed (ans_notification_test), 20 tests passed (ans_notification_branch_test)
Issue: #4242
Co-Authored-By: Agent
Signed-off-by: CheerfulRicky <yuegang7@h-partners.com>
Change-Id: I7300c1de59c577082681a61861cc718ebe48be4a
Signed-off-by: CheerfulRicky <yuegang7@h-partners.com>
refactor(ans): replace WantParams/WantAgent serialization with envelope format
Created-by: cheerful_ricky
Commit-by: CheerfulRicky
Merged-by: openharmony_ci
Description: ## Summary
Replace legacy WantParams/WantAgent serialization with the new envelope-based format for safer JSON escaping (quotes, backslashes, nested delimiters).
## Changes
- **New helper**: `NotificationWantParamsHelper` in `frameworks/core/common` centralizes envelope-detection logic (`SerializeWantParams`, `ParseWantParams`, `ParseWantParamsWithBrackets`, `SerializeWantAgent`, `ParseWantAgent`).
- **Serialization (write)**: switch to `WantParamWrapperJson::Serialize` / `WantAgentHelper::ToStringWithEnvelope` at all persistence, dump, and CLI-display call sites.
- **Deserialization (read)**: envelope detection (`HasEnvelope` / `HasWantParamsEnvelope`) → new `Parse` / `FromStringWithEnvelope`; legacy data falls back to `ParseWantParams` / `FromString` for backward compatibility.
## Scope decisions
- Distributed serialization stays legacy (cross-device version compat); only its deserialization is upgraded to envelope-aware.
- Analytics/event reporting unchanged (consumers not yet envelope-aware).
## Verification
All 12 modified files pass `clang -fsyntax-only` with full OpenHarmony include paths (0 errors). Full build blocked by a pre-existing arkcompiler breakage (`unhandled_object_manager.cpp`) unrelated to this change.
Co-Authored-By: Agent
See merge request: openharmony/notification_distributed_notification_service!4863
Switch WantParams serialization to WantParamWrapperJson::Serialize and
WantAgent serialization to ToStringWithEnvelope for safer JSON escaping
that correctly handles quotes, backslashes, and nested delimiters.
Deserialization uses envelope detection (HasEnvelope/HasWantParamsEnvelope)
with legacy fallback to ParseWantParams/FromString so that historical data
continues to round-trip unchanged.
Add NotificationWantParamsHelper in frameworks/core/common to centralize
the envelope-detection logic across all call sites. Add 16 unit tests
covering all branches (>90% branch coverage).
Scope notes:
- Distributed serialization stays legacy (cross-device version compat);
only its deserialization is upgraded to envelope-aware.
- Analytics/event reporting unchanged (consumers not yet envelope-aware).
- Remove wantParameters debug serialization from Dump functions.
- Fix null pointer dereference on template data access.
- Fix variable name typo: wangAgent -> wantAgent.
Change-Id: Ifaa17126e2ba864c4dd968bd15314c2d8dec53eb
Change-Id: Ic3121ed8242b5a1e58f659195b4103ea9b48c6a0
Change-Id: I4eb9a2b0fe87977f7ffe36b0cb60e6a2cf240450
Change-Id: I296fd76e97a888b49d053b243307e627a8bec0fa
Change-Id: Ie5928906fa46b1d45912e9a02fd2f9d2f89dbda2
Co-Authored-By: Agent
Signed-off-by: CheerfulRicky <yuegang7@h-partners.com>
Change-Id: Ib5bc52d7a7fdcdda8bd894483f8e7b8506b6e18f
- ERR_ANS_CUSTOM_EXTENSION_EXISTS_CHECK_FAILED now maps to new external
code 1600029 (ERROR_LIVE_VIEW_EXTENSION_NOT_FOUND) with message
'The system failed to find the ExtensionAbility instance for the
custom Live View widget template.'
- ERR_ANS_CUSTOM_EXTENSION_RIGHTS_CHECK_FAILED keeps external code
1600014 but updates message to 'The right of liveView is not enabled.'
- Update test assertions to match new mapping
- Update liveview-rights-check summary documentation
Co-Authored-By: Agent
Signed-off-by: CheerfulRicky <yuegang7@h-partners.com>
Change-Id: I3475995fe9ac6ce1d9508ecfa20d90affb25a119
Add isNotificationSlotEnabledByBundles batch slot query API to query
multiple bundles' slot enabled state in a single IPC call, avoiding the
performance degradation caused by LRU cache misses in the single-query
path. Optimize getAllNotificationEnabledBundles to only query
_enabledNotification keys (filtered by VALUE IN ('1','3')) and parse
bundleName/uid from the key, reducing I/O by ~66%.
- Add IDL method GetEnabledForBundleSlots with OrderedMap output
- Add full-stack implementation: server, DB, client, helper, NAPI, ANI
- Unify single query path to bypass LRU cache via batch query internally
- Add QueryDataInKeys batched IN query and QueryEnabledBundles in RDB layer
- Add unit tests for server, DB layer, and RDB batch query
- Add performance test (300-bundle batch query < 30ms target)
Signed-off-by: CheerfulRicky <yuegang7@h-partners.com>
Co-Authored-By: Agent
Change-Id: I59ed3041c14b33a2fbe69517d6b366597f03b11b
- sts_request.cpp: replace ERROR_INTERNAL_ERROR with ERR_ANS_INNER_TASK_ERR
and ERROR_PARAM_INVALID with ERR_ANS_INNER_INVALID_PARAM; change return
types from int32_t to InnerErrorCode for UnWarpNotificationRequest,
GetNotificationContent, GetNotificationRequestByCustom and sub-functions
- sts_request.h: add ans_service_errors.h include, update declaration
- ani_publish.cpp: change int32_t ret to InnerErrorCode ret
- ani_request_enable.cpp: replace ThrowError(env, ERR_ANS_INNER_INVALID_PARAM, msg)
with ThrowErrorWithCode(env, ERR_ANS_INNER_INVALID_PARAM, msg) to preserve
custom error message while using the spec-compliant entry point
- ani_open_settings.cpp: same ThrowError -> ThrowErrorWithCode fix
- ans_service_errors_test.cpp: update expected values for ERR_ANS_INNER_NO_MEMORY
and ERR_ANS_INNER_CHECK_WEAK_NETWORK to match ERROR_INTERNAL_ERROR mapping
Signed-off-by: CheerfulRicky <yuegang7@h-partners.com>
Co-Authored-By: Agent
Change-Id: I55cbf67e174c1e38aa1cbfecbbc939f1fa7de73f
ReturnCallbackPromise is used by old-style NAPI files (disturb_mode,
cancel, slot, distributed, subscribe, publish, remove, get_active,
enable_notification, display_badge, ans_template, unsubscribe) that
store nativeCode (from NotificationHelper) in info.errorCode.
The new CreateErrorValue always calls InnerErrorToExternal, which
incorrectly converts nativeCode to externalCode. Old-style APIs
expect nativeCode to pass through unchanged (XTS tests like
setDoNotDisturbDate expect nativeCode values).
CreateErrorValueLegacy uses napi_create_int32(env, errCode) directly
without conversion, restoring the original behavior.
Signed-off-by: CheerfulRicky <yuegang7@h-partners.com>
Co-Authored-By: Agent
Change-Id: Ie68427f3ac7066f205dbe460b23ffe6196279da5