diff --git a/frameworks/kits/ability/native/include/ability_impl.h b/frameworks/kits/ability/native/include/ability_impl.h index 42ec06fa8f..fed8049a50 100644 --- a/frameworks/kits/ability/native/include/ability_impl.h +++ b/frameworks/kits/ability/native/include/ability_impl.h @@ -446,6 +446,7 @@ private: std::shared_ptr abilityLifecycleCallbacks_; std::shared_ptr applactionImpl_; std::shared_ptr contextDeal_; + std::shared_ptr configuration_ = nullptr; private: /** diff --git a/frameworks/kits/ability/native/src/ability_impl.cpp b/frameworks/kits/ability/native/src/ability_impl.cpp index b91a6ef51f..821282f871 100644 --- a/frameworks/kits/ability/native/src/ability_impl.cpp +++ b/frameworks/kits/ability/native/src/ability_impl.cpp @@ -815,8 +815,17 @@ Uri AbilityImpl::DenormalizeUri(const Uri &uri) void AbilityImpl::ScheduleUpdateConfiguration(const Configuration &config) { APP_LOGI("%{public}s begin.", __func__); + + // Update for the first time + if (!configuration_) { + configuration_ = std::make_shared(config); + APP_LOGI("AbilityImpl::Init the configuration"); + return; + } + if (ability_ == nullptr) { APP_LOGE("AbilityImpl::ScheduleUpdateConfiguration ability_ is nullptr"); + return; } ability_->OnConfigurationUpdated(config); diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h index fbe8fd5362..b58ca0ffe5 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h @@ -179,6 +179,11 @@ public: return 0; } + virtual int ClearUpApplicationData(const std::string &bundleName) override + { + return 0; + } + enum RequestCode { E_STATE_INITIAL = 0, E_STATE_INACTIVE, diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h index 3fbf1302d4..eb0962e01e 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -147,6 +147,11 @@ public: return 0; } + virtual int ClearUpApplicationData(const std::string &bundleName) override + { + return 0; + } + AbilityLifeCycleState curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; sptr abilityScheduler_; // kit interface used to schedule ability life Want want_; diff --git a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h index 9f3621a408..daa3fe3b5f 100644 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h @@ -164,6 +164,11 @@ public: return 0; } + virtual int ClearUpApplicationData(const std::string &bundleName) override + { + return 0; + } + sptr abilityScheduler_ = nullptr; // kit interface used to schedule ability life Want want_; bool startAbility = false; diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index 9ece1923de..4f7a91c60f 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -306,6 +306,15 @@ public: */ ErrCode KillProcess(const std::string &bundleName); + /** + * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, + * clear the application data. + * + * @param bundleName, bundle name in Application record. + * @return + */ + ErrCode ClearUpApplicationData(const std::string &bundleName); + /** * @brief Checks whether this ability is the first ability in a mission. * diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_errors.h b/interfaces/innerkits/ability_manager/include/ability_manager_errors.h index 68baff4c11..4f7767dfb0 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_errors.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_errors.h @@ -324,6 +324,11 @@ enum { * Result(2097216) for KillProcess: keep alive process can not be killed */ KILL_PROCESS_KEEP_ALIVE, + + /** + * Result(2097217) for clear the application data fail. + */ + CLEAR_APPLICATION_DATA_FAIL, }; enum { diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index d0da341eba..2309cc08fe 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -320,6 +320,15 @@ public: */ virtual int KillProcess(const std::string &bundleName) = 0; + /** + * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, + * clear the application data. + * + * @param bundleName, bundle name in Application record. + * @return + */ + virtual int ClearUpApplicationData(const std::string &bundleName) = 0; + /** * Uninstall app * @@ -708,6 +717,8 @@ public: GET_SYSTEM_MEMORY_ATTR, + CLEAR_UP_APPLICATION_DATA, + START_ABILITY_FOR_OPTIONS, // ipc id for continue ability(1101) diff --git a/interfaces/kits/napi/aafwk/abilityManager/BUILD.gn b/interfaces/kits/napi/aafwk/abilityManager/BUILD.gn index 85dcab0173..e3ffbec7e5 100644 --- a/interfaces/kits/napi/aafwk/abilityManager/BUILD.gn +++ b/interfaces/kits/napi/aafwk/abilityManager/BUILD.gn @@ -42,6 +42,8 @@ ohos_shared_library("abilitymanager") { "//foundation/appexecfwk/standard/services/appmgr:libams", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//utils/native/base:utils", ] diff --git a/interfaces/kits/napi/aafwk/abilityManager/napi_ability_manager.cpp b/interfaces/kits/napi/aafwk/abilityManager/napi_ability_manager.cpp index d064a7cd45..8b47222bac 100644 --- a/interfaces/kits/napi/aafwk/abilityManager/napi_ability_manager.cpp +++ b/interfaces/kits/napi/aafwk/abilityManager/napi_ability_manager.cpp @@ -18,6 +18,7 @@ #include #include +#include "ability_manager_client.h" #include "ability_manager_interface.h" #include "app_mgr_interface.h" #include "hilog_wrapper.h" @@ -1694,7 +1695,8 @@ napi_value NAPI_KillProcessesByBundleName(napi_env env, napi_callback_info info) auto NAPI_ClearUpApplicationDataAsyncExecuteCallback = [](napi_env env, void *data) { HILOG_INFO("clearUpApplicationData called(CallBack Mode)..."); AsyncClearUpApplicationDataCallbackInfo *async_callback_info = (AsyncClearUpApplicationDataCallbackInfo *)data; - async_callback_info->result = GetAppManagerInstance()->ClearUpApplicationData(async_callback_info->bundleName); + async_callback_info->result = AAFwk::AbilityManagerClient::GetInstance()-> + ClearUpApplicationData(async_callback_info->bundleName); }; auto NAPI_ClearUpApplicationDataAsyncCompleteCallback = [](napi_env env, napi_status status, void *data) { diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp index 89ef0f4c33..686d0b826b 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp @@ -2977,7 +2977,7 @@ napi_value WrapResultSet(napi_env env, const std::shared_ptr &mission); int ChangedPowerStorageAbilityToActive(std::shared_ptr &powerStorage, bool isPowerStateLockScreen = false); + void HandleActiveTimeout(const std::shared_ptr &ability); bool IsLockScreenState(); bool CheckMissionRecordInWhiteList(const std::shared_ptr &mission); bool DeleteMissionRecordInStackOnLockScreen(const std::shared_ptr &missionRecord); diff --git a/services/abilitymgr/include/ams_configuration_parameter.h b/services/abilitymgr/include/ams_configuration_parameter.h index fa3d11b3a3..b159298548 100644 --- a/services/abilitymgr/include/ams_configuration_parameter.h +++ b/services/abilitymgr/include/ams_configuration_parameter.h @@ -35,6 +35,8 @@ const std::string STARTUP_PHONE_SERVICE {"startup_phone_service"}; const std::string MISSION_SAVE_TIME {"mission_save_time"}; const std::string SYSTEM_CONFIGURATION {"system_configuration"}; const std::string SYSTEM_ORIENTATION {"system_orientation"}; +const std::string STARTUP_CONTACTS {"startup_contacts"}; +const std::string STARTUP_MMS {"startup_mms"}; } // namespace AmsConfig enum class SatrtUiMode { STATUSBAR = 1, NAVIGATIONBAR = 2, STARTUIBOTH = 3 }; @@ -73,6 +75,16 @@ public: * return false : ams do not start phone service */ bool GetPhoneServiceState() const; + /** + * return true : ams can start contacts + * return false : ams do not start contacts + */ + bool GetStartContactsState() const; + /** + * return true : ams can start mms + * return false : ams do not start mms + */ + bool GetStartMmsState() const; /** * Get profile information */ @@ -109,6 +121,8 @@ private: bool canStartUiStatusBar_ {false}; bool canStartUiNavigationBar_ {false}; bool canStartPhoneService_ {false}; + bool canStartContacts {false}; + bool canStartMms {false}; std::string orientation_ {""}; int missionSaveTime_ {12 * 60 * 60 * 1000}; std::map memThreshold_; diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 50455e1746..10cdd498cf 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -182,6 +182,13 @@ public: */ int KillApplication(const std::string &bundleName); + /** + * clear the application data + * + * @param bundleName. + */ + int ClearUpApplicationData(const std::string &bundleName); + void AttachTimeOut(const sptr &token); void PrepareTerminate(const sptr &token); @@ -204,6 +211,11 @@ public: */ void GetSystemMemoryAttr(AppExecFwk::SystemMemoryAttr &memoryInfo, std::string &strConfig); + /** + * Start a resident process + */ + void StartupResidentProcess(); + protected: /** * OnAbilityRequestDone, app manager service call this interface after ability request done. diff --git a/services/abilitymgr/include/configuration_distributor.h b/services/abilitymgr/include/configuration_distributor.h index ea6c58b996..8934b55bee 100644 --- a/services/abilitymgr/include/configuration_distributor.h +++ b/services/abilitymgr/include/configuration_distributor.h @@ -30,9 +30,11 @@ public: void Atach(const std::weak_ptr &ob); void Detach(const std::weak_ptr &ob); void UpdateConfiguration(const AppExecFwk::Configuration &newConfig); + void InitConfiguration(const AppExecFwk::Configuration &); private: std::list> observerList_; std::mutex configLock_; + AppExecFwk::Configuration config_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/resource/ams_service_config.json b/services/abilitymgr/resource/ams_service_config.json index ea1715159c..392255de15 100644 --- a/services/abilitymgr/resource/ams_service_config.json +++ b/services/abilitymgr/resource/ams_service_config.json @@ -5,6 +5,8 @@ "startup_system_ui_status_bar" : true, "startup_system_ui_navigation_bar" : true, "startup_phone_service" : true, + "startup_contacts":true, + "startup_mms":true, "mission_save_time" : 43200000 }, "memorythreshold":{ diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index a2cbd2b6d3..8ee091e55d 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -882,6 +882,28 @@ void AbilityConnectManager::HandleAbilityDiedTask(const std::shared_ptrGetAbilityInfo().name == AbilityConfig::CONTACTS_ABILITY_NAME) { + AbilityRequest requestInfo; + requestInfo.want = abilityRecord->GetWant(); + requestInfo.abilityInfo = abilityRecord->GetAbilityInfo(); + requestInfo.appInfo = abilityRecord->GetApplicationInfo(); + + RemoveServiceAbility(abilityRecord); + StartAbilityLocked(requestInfo); + return; + } + + if (abilityRecord->GetAbilityInfo().name == AbilityConfig::MMS_ABILITY_NAME) { + AbilityRequest requestInfo; + requestInfo.want = abilityRecord->GetWant(); + requestInfo.abilityInfo = abilityRecord->GetAbilityInfo(); + requestInfo.appInfo = abilityRecord->GetApplicationInfo(); + + RemoveServiceAbility(abilityRecord); + StartAbilityLocked(requestInfo); + return; + } + ConnectListType connlist = abilityRecord->GetConnectRecordList(); for (auto &connectRecord : connlist) { HILOG_WARN("This record complete disconnect directly. recordId:%{public}d", connectRecord->GetRecordId()); diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 5e4c4a5a73..c0fa2eddd7 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -296,6 +296,13 @@ ErrCode AbilityManagerClient::KillProcess(const std::string &bundleName) return abms->KillProcess(bundleName); } +ErrCode AbilityManagerClient::ClearUpApplicationData(const std::string &bundleName) +{ + CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); + sptr abms = iface_cast(remoteObject_); + return abms->ClearUpApplicationData(bundleName); +} + ErrCode AbilityManagerClient::IsFirstInMission(const sptr &token) { if (token == nullptr) { diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index dd5b1ef94c..4e6e67b4ed 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -771,6 +771,27 @@ int AbilityManagerProxy::KillProcess(const std::string &bundleName) return reply.ReadInt32(); } +int AbilityManagerProxy::ClearUpApplicationData(const std::string &bundleName) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (!data.WriteString16(Str8ToStr16(bundleName))) { + HILOG_ERROR("bundleName write failed."); + return ERR_INVALID_VALUE; + } + int error = Remote()->SendRequest(IAbilityManager::CLEAR_UP_APPLICATION_DATA, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} + int AbilityManagerProxy::UninstallApp(const std::string &bundleName) { MessageParcel data; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index d049452a42..333eabba0d 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -676,6 +676,8 @@ void AbilityManagerService::GetGlobalConfiguration() std::string direction = amsConfigResolver_->GetOrientation(); HILOG_INFO("current global direction is : %{public}s", direction.c_str()); GetConfiguration()->AddItem(GlobalConfigurationKey::SYSTEM_ORIENTATION, direction); + + DelayedSingleton::GetInstance()->InitConfiguration(*GetConfiguration()); } std::shared_ptr AbilityManagerService::GetConfiguration() @@ -1258,21 +1260,23 @@ int AbilityManagerService::AttachAbilityThread( auto abilityInfo = abilityRecord->GetAbilityInfo(); auto type = abilityInfo.type; - if (type != AppExecFwk::AbilityType::DATA) { + int returnCode = -1; + if (type == AppExecFwk::AbilityType::SERVICE || type == AppExecFwk::AbilityType::EXTENSION) { + returnCode = connectManager_->AttachAbilityThreadLocked(scheduler, token); + } else if (type == AppExecFwk::AbilityType::DATA) { + returnCode = dataAbilityManager_->AttachAbilityThread(scheduler, token); + } else if (IsSystemUiApp(abilityInfo)) { + returnCode = kernalAbilityManager_->AttachAbilityThread(scheduler, token); + } else { + returnCode = currentMissionListManager_->AttachAbilityThread(scheduler, token); + } + + HILOG_INFO("attach ability type [%{public}d] | returnCode [%{public}d]", type, returnCode); + if (SUCCEEDED(returnCode) && type != AppExecFwk::AbilityType::DATA) { DelayedSingleton::GetInstance()->Atach(abilityRecord); } - if (type == AppExecFwk::AbilityType::SERVICE || type == AppExecFwk::AbilityType::EXTENSION) { - return connectManager_->AttachAbilityThreadLocked(scheduler, token); - } - if (type == AppExecFwk::AbilityType::DATA) { - return dataAbilityManager_->AttachAbilityThread(scheduler, token); - } - if (IsSystemUiApp(abilityInfo)) { - return kernalAbilityManager_->AttachAbilityThread(scheduler, token); - } - - return currentMissionListManager_->AttachAbilityThread(scheduler, token); + return returnCode; } void AbilityManagerService::DumpFuncInit() @@ -1682,6 +1686,46 @@ void AbilityManagerService::StartingPhoneServiceAbility() (void)StartAbility(phoneServiceWant, DEFAULT_INVAL_VALUE); } +void AbilityManagerService::StartingContactsAbility() +{ + HILOG_DEBUG("%{public}s", __func__); + if (!iBundleManager_) { + HILOG_INFO("bms service is null"); + return; + } + + AppExecFwk::AbilityInfo contactsInfo; + Want contactsWant; + contactsWant.SetElementName(AbilityConfig::CONTACTS_BUNDLE_NAME, AbilityConfig::CONTACTS_ABILITY_NAME); + + while (!(iBundleManager_->QueryAbilityInfo(contactsWant, contactsInfo))) { + HILOG_INFO("Waiting query contacts service completed."); + usleep(REPOLL_TIME_MICRO_SECONDS); + } + + (void)StartAbility(contactsWant, DEFAULT_INVAL_VALUE); +} + +void AbilityManagerService::StartingMmsAbility() +{ + HILOG_DEBUG("%{public}s", __func__); + if (!iBundleManager_) { + HILOG_INFO("bms service is null"); + return; + } + + AppExecFwk::AbilityInfo mmsInfo; + Want mmsWant; + mmsWant.SetElementName(AbilityConfig::MMS_BUNDLE_NAME, AbilityConfig::MMS_ABILITY_NAME); + + while (!(iBundleManager_->QueryAbilityInfo(mmsWant, mmsInfo))) { + HILOG_INFO("Waiting query mms service completed."); + usleep(REPOLL_TIME_MICRO_SECONDS); + } + + (void)StartAbility(mmsWant, DEFAULT_INVAL_VALUE); +} + void AbilityManagerService::StartSystemUi(const std::string abilityName) { HILOG_INFO("Starting system ui app."); @@ -1844,6 +1888,16 @@ int AbilityManagerService::KillProcess(const std::string &bundleName) return ERR_OK; } +int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) +{ + HILOG_DEBUG("ClearUpApplicationData, bundleName: %{public}s", bundleName.c_str()); + int ret = DelayedSingleton::GetInstance()->ClearUpApplicationData(bundleName); + if (ret != ERR_OK) { + return CLEAR_APPLICATION_DATA_FAIL; + } + return ERR_OK; +} + int AbilityManagerService::UninstallApp(const std::string &bundleName) { HILOG_DEBUG("Uninstall app, bundleName: %{public}s", bundleName.c_str()); @@ -2207,6 +2261,19 @@ void AbilityManagerService::StartSystemApplication() HILOG_INFO("start navigation bar"); StartingSystemUiAbility(SatrtUiMode::NAVIGATIONBAR); } + + if (amsConfigResolver_->GetStartContactsState()) { + HILOG_INFO("start contacts"); + StartingContactsAbility(); + } + + if (amsConfigResolver_->GetStartMmsState()) { + HILOG_INFO("start mms"); + StartingMmsAbility(); + } + + // Location may change + DelayedSingleton::GetInstance()->StartupResidentProcess(); } void AbilityManagerService::ConnectBmsService() diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 63866b0cf1..155e1d0a26 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -105,6 +105,7 @@ void AbilityManagerStub::SecondStepInit() requestFuncMap_[UPDATE_CONFIGURATION] = &AbilityManagerStub::UpdateConfigurationInner; requestFuncMap_[SET_SHOW_ON_LOCK_SCREEN] = &AbilityManagerStub::SetShowOnLockScreenInner; requestFuncMap_[GET_SYSTEM_MEMORY_ATTR] = &AbilityManagerStub::GetSystemMemoryAttrInner; + requestFuncMap_[CLEAR_UP_APPLICATION_DATA] = &AbilityManagerStub::ClearUpApplicationDataInner; requestFuncMap_[LOCK_MISSION_FOR_CLEANUP] = &AbilityManagerStub::LockMissionForCleanupInner; requestFuncMap_[UNLOCK_MISSION_FOR_CLEANUP] = &AbilityManagerStub::UnlockMissionForCleanupInner; requestFuncMap_[REGISTER_MISSION_LISTENER] = &AbilityManagerStub::RegisterMissionListenerInner; @@ -363,6 +364,17 @@ int AbilityManagerStub::KillProcessInner(MessageParcel &data, MessageParcel &rep return NO_ERROR; } +int AbilityManagerStub::ClearUpApplicationDataInner(MessageParcel &data, MessageParcel &reply) +{ + std::string bundleName = Str16ToStr8(data.ReadString16()); + int result = ClearUpApplicationData(bundleName); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("ClearUpApplicationData error"); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int AbilityManagerStub::UninstallAppInner(MessageParcel &data, MessageParcel &reply) { std::string bundleName = Str16ToStr8(data.ReadString16()); diff --git a/services/abilitymgr/src/ability_stack_manager.cpp b/services/abilitymgr/src/ability_stack_manager.cpp index 554a090ba2..1b685326be 100644 --- a/services/abilitymgr/src/ability_stack_manager.cpp +++ b/services/abilitymgr/src/ability_stack_manager.cpp @@ -2770,8 +2770,7 @@ void AbilityStackManager::BackToLauncher() auto fullScreenStack = GetTopFullScreenStackIncludeSplitScreen(); CHECK_POINTER(fullScreenStack); auto currentTopAbility = fullScreenStack->GetTopAbilityRecord(); - if (currentTopAbility && (currentTopAbility->IsAbilityState(AbilityState::ACTIVE) || - currentTopAbility->IsAbilityState(AbilityState::ACTIVATING))) { + if (currentTopAbility && (currentTopAbility->IsAbilityState(AbilityState::ACTIVE))) { HILOG_WARN("Current top ability is active, no need to start launcher."); return; } @@ -2938,7 +2937,7 @@ void AbilityStackManager::OnTimeOut(uint32_t msgId, int64_t eventId) ActiveTopAbility(abilityRecord); break; case AbilityManagerService::ACTIVE_TIMEOUT_MSG: - DelayedStartLauncher(); + HandleActiveTimeout(abilityRecord); break; case AbilityManagerService::INACTIVE_TIMEOUT_MSG: case AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG: @@ -2949,6 +2948,31 @@ void AbilityStackManager::OnTimeOut(uint32_t msgId, int64_t eventId) } } +void AbilityStackManager::HandleActiveTimeout(const std::shared_ptr &ability) +{ + HILOG_DEBUG("Handle active timeout"); + CHECK_POINTER(ability); + DelayedSingleton::GetInstance()->AttachTimeOut(ability->GetToken()); + + if (ability->IsLauncherRoot()) { + HILOG_INFO("Launcher root load timeout, restart."); + BackToLauncher(); + return; + } + + auto missionRecord = ability->GetMissionRecord(); + CHECK_POINTER(missionRecord); + auto stack = missionRecord->GetMissionStack(); + CHECK_POINTER(stack); + missionRecord->RemoveAbilityRecord(ability); + if (missionRecord->IsEmpty()) { + RemoveMissionRecordById(missionRecord->GetMissionRecordId()); + JudgingIsRemoveMultiScreenStack(stack); + } + + BackToLauncher(); +} + int AbilityStackManager::MoveMissionToFloatingStack(const MissionOption &missionOption) { HILOG_DEBUG("Move mission to floating stack, missionId: %{public}d", missionOption.missionId); @@ -3620,7 +3644,7 @@ void AbilityStackManager::ActiveTopAbility(const std::shared_ptr if (abilityRecord->IsLauncherRoot()) { HILOG_INFO("Launcher root load timeout, restart."); - DelayedStartLauncher(); + BackToLauncher(); return; } if (abilityRecord->IsLockScreenRoot()) { diff --git a/services/abilitymgr/src/ams_configuration_parameter.cpp b/services/abilitymgr/src/ams_configuration_parameter.cpp index 225c9e480a..99ec0ec250 100644 --- a/services/abilitymgr/src/ams_configuration_parameter.cpp +++ b/services/abilitymgr/src/ams_configuration_parameter.cpp @@ -52,6 +52,16 @@ bool AmsConfigurationParameter::GetPhoneServiceState() const return canStartPhoneService_; } +bool AmsConfigurationParameter::GetStartContactsState() const +{ + return canStartContacts; +} + +bool AmsConfigurationParameter::GetStartMmsState() const +{ + return canStartMms; +} + bool AmsConfigurationParameter::NonConfigFile() const { return nonConfigFile_; @@ -124,6 +134,8 @@ int AmsConfigurationParameter::LoadAppConfigurationForStartUpService(nlohmann::j Object.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_NAVIGATION_BAR).get(); canStartPhoneService_ = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_PHONE_SERVICE).get(); + canStartContacts = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_CONTACTS).get(); + canStartMms = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_MMS).get(); missionSaveTime_ = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::MISSION_SAVE_TIME).get(); HILOG_INFO("get ams service config succes!"); ret = 0; diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index e2b7418159..6d8c49c463 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -173,6 +173,17 @@ int AppScheduler::KillApplication(const std::string &bundleName) return ERR_OK; } +int AppScheduler::ClearUpApplicationData(const std::string &bundleName) +{ + CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); + int ret = (int)appMgrClient_->ClearUpApplicationData(bundleName); + if (ret != ERR_OK) { + HILOG_ERROR("Fail to clear application data."); + return INNER_ERR; + } + return ERR_OK; +} + void AppScheduler::AttachTimeOut(const sptr &token) { CHECK_POINTER(appMgrClient_); @@ -215,5 +226,11 @@ void AppScheduler::GetSystemMemoryAttr(AppExecFwk::SystemMemoryAttr &memoryInfo, CHECK_POINTER(appMgrClient_); appMgrClient_->GetSystemMemoryAttr(memoryInfo, strConfig); } + +void AppScheduler::StartupResidentProcess() +{ + CHECK_POINTER(appMgrClient_); + appMgrClient_->StartupResidentProcess(); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/configuration_distributor.cpp b/services/abilitymgr/src/configuration_distributor.cpp index baf333896b..8f0a88e8e6 100644 --- a/services/abilitymgr/src/configuration_distributor.cpp +++ b/services/abilitymgr/src/configuration_distributor.cpp @@ -37,9 +37,13 @@ void ConfigurationDistributor::Atach(const std::weak_ptr &o HILOG_INFO("Atach ob is null"); return; } - int id = ob.lock()->GetId(); + auto ability = ob.lock(); + int id = ability->GetId(); HILOG_INFO("Atach ob id[%{public}d]", id); observerList_.emplace_back(ob); + + // Init ability thread configurtion object + ability->UpdateConfiguration(config_); } void ConfigurationDistributor::Detach(const std::weak_ptr &ob) @@ -77,5 +81,11 @@ void ConfigurationDistributor::UpdateConfiguration(const AppExecFwk::Configurati } HILOG_INFO("notify done"); } + +void ConfigurationDistributor::InitConfiguration(const AppExecFwk::Configuration &newConfig) +{ + std::lock_guard lock(configLock_); + config_ = newConfig; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/data_ability_manager.cpp b/services/abilitymgr/src/data_ability_manager.cpp index 1b2946d105..917b918db1 100644 --- a/services/abilitymgr/src/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability_manager.cpp @@ -65,11 +65,6 @@ sptr DataAbilityManager::Acquire( HILOG_ERROR("Data ability manager acquire: invalid client token."); return nullptr; } - if (abilityRequest.abilityInfo.bundleName == clientAbilityRecord->GetAbilityInfo().bundleName && - abilityRequest.abilityInfo.name == clientAbilityRecord->GetAbilityInfo().name) { - HILOG_ERROR("Data ability '%{public}s' cannot acquires itself.", dataAbilityName.c_str()); - return nullptr; - } HILOG_INFO("Ability '%{public}s' acquiring data ability '%{public}s'...", clientAbilityRecord->GetAbilityInfo().name.c_str(), dataAbilityName.c_str()); diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp index c4cfb452f2..a4fd4fab4a 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp @@ -139,6 +139,17 @@ void AppScheduler::GetSystemMemoryAttr(AppExecFwk::SystemMemoryAttr &memoryInfo, memoryInfo.threshold_ = testValue; } +void AppScheduler::StartupResidentProcess() +{ + HILOG_INFO("Test AppScheduler::StartupResidentProcess()"); +} + +int AppScheduler::ClearUpApplicationData(const std::string &bundleName) +{ + HILOG_INFO("Test AppScheduler::ClearUpApplicationData()"); + return ERR_OK; +} + void AppScheduler::UpdateAbilityState(const sptr &token, const AppExecFwk::AbilityState state) { HILOG_INFO("Test AppScheduler::UpdateAbilityState()"); diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h index 419d9d8af2..5a97de3a76 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -294,6 +294,11 @@ public: return 0; } + virtual int ClearUpApplicationData(const std::string &bundleName) override + { + return 0; + } + MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr &callerToken, int requestCode)); MOCK_METHOD3(StartAbility, int(const Want &want, const sptr &callerToken, int requestCode)); MOCK_METHOD2( diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 357062c87e..04daeb465f 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -304,6 +304,11 @@ public: { return 0; } + + virtual int ClearUpApplicationData(const std::string &bundleName) override + { + return 0; + } }; } // namespace AAFwk } // namespace OHOS diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index f7f61564d2..5274f1e696 100644 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -101,6 +101,7 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); + MOCK_METHOD1(ClearUpApplicationData, int(const std::string &)); void Wait() { diff --git a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp index 3aa63e87d6..15847138ab 100644 --- a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp +++ b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp @@ -1817,14 +1817,17 @@ HWTEST_F(AbilityMgrModuleTest, UpdateConfiguration_028, TestSize.Level1) int displeyId = 1001; std::string key = GlobalConfigurationKey::SYSTEM_LANGUAGE; - std::string val = "中文"; + std::string val = "Chinese"; auto Compare = [displeyId, key, val](const AppExecFwk::Configuration &config) { auto item = config.GetItem(displeyId, key); EXPECT_EQ(item, val); }; sptr scheduler(new MockAbilityScheduler()); - EXPECT_CALL(*scheduler, ScheduleUpdateConfiguration(_)).Times(1).WillOnce(Invoke(Compare)); + EXPECT_CALL(*scheduler, ScheduleUpdateConfiguration(_)) + .Times(2) + .WillOnce(Return()) + .WillOnce(Invoke(Compare)); auto ref = abilityMgrServ_->AttachAbilityThread(scheduler, abilityRecord->GetToken()); EXPECT_EQ(ref, 0); @@ -1872,14 +1875,72 @@ HWTEST_F(AbilityMgrModuleTest, UpdateConfiguration_029, TestSize.Level1) int displeyId = 1001; std::string key = GlobalConfigurationKey::SYSTEM_LANGUAGE; - std::string val = "德文"; + std::string val = "German"; auto Compare = [displeyId, key, val](const AppExecFwk::Configuration &config) { auto item = config.GetItem(displeyId, key); EXPECT_EQ(item, val); }; sptr scheduler(new MockAbilityScheduler()); - EXPECT_CALL(*scheduler, ScheduleUpdateConfiguration(_)).Times(1).WillOnce(Invoke(Compare)); + EXPECT_CALL(*scheduler, ScheduleUpdateConfiguration(_)) + .Times(2) + .WillOnce(Return()) + .WillOnce(Invoke(Compare)); + + abilityMgrServ_->AttachAbilityThread(scheduler, abilityRecord->GetToken()); + + int size = DelayedSingleton::GetInstance()->observerList_.size(); + EXPECT_TRUE(size > 0); + + AppExecFwk::Configuration newConfig; + newConfig.AddItem(displeyId, key, val); + + auto updateRef = abilityMgrServ_->UpdateConfiguration(newConfig); + EXPECT_EQ(updateRef, 0); + + PacMap saveData; + abilityMgrServ_->AbilityTransitionDone(abilityRecord->GetToken(), 0, saveData); + + int num = size - 1; + size = DelayedSingleton::GetInstance()->observerList_.size(); + EXPECT_EQ(size, num); +} + +/* + * Feature: AbilityManagerService + * Function: UpdateConfiguration + * SubFunction: NA + * FunctionPoints: NA + * EnvConditions: NA + * CaseDescription: luncher ability + */ +HWTEST_F(AbilityMgrModuleTest, UpdateConfiguration_030, TestSize.Level1) +{ + EXPECT_TRUE(abilityMgrServ_); + std::string abilityName = "luncher"; + std::string bundleName = "com.ix.hiworld"; + + SetActive(); + Want want = CreateWant(abilityName, bundleName); + auto startRef = abilityMgrServ_->StartAbility(want); + EXPECT_EQ(startRef, 0); + + std::shared_ptr abilityRecord = abilityMgrServ_->GetStackManager()->GetCurrentTopAbility(); + EXPECT_TRUE(abilityRecord); + + int displeyId = 1001; + std::string key = GlobalConfigurationKey::SYSTEM_LANGUAGE; + std::string val = "Italian"; + auto Compare = [displeyId, key, val](const AppExecFwk::Configuration &config) { + auto item = config.GetItem(displeyId, key); + EXPECT_EQ(item, val); + }; + + sptr scheduler(new MockAbilityScheduler()); + EXPECT_CALL(*scheduler, ScheduleUpdateConfiguration(_)) + .Times(2) + .WillOnce(Return()) + .WillOnce(Invoke(Compare)); abilityMgrServ_->AttachAbilityThread(scheduler, abilityRecord->GetToken()); diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 5064c4eccb..9ec12f2b88 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -127,6 +127,7 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); + MOCK_METHOD1(ClearUpApplicationData, int(const std::string &)); public: std::string powerState_; diff --git a/tools/zip/include/file_path.h b/tools/zip/include/file_path.h index 80d8806366..6019be5c24 100644 --- a/tools/zip/include/file_path.h +++ b/tools/zip/include/file_path.h @@ -75,7 +75,6 @@ private: std::string path_; void StripTrailingSeparatorsInternal(); - int FindDriveLetter(const std::string &path); bool AreAllSeparators(const std::string &input); }; } // namespace LIBZIP diff --git a/tools/zip/src/file_path.cpp b/tools/zip/src/file_path.cpp index aa16b4b719..13a5361cfd 100644 --- a/tools/zip/src/file_path.cpp +++ b/tools/zip/src/file_path.cpp @@ -106,14 +106,8 @@ void FilePath::GetComponents(std::vector &components) // Capture root, if any. base = current.BaseName(); - if (!base.path_.empty() && base.path_ != kCurrentDirectory) + if (!base.path_.empty() && base.path_ != kCurrentDirectory) { components.push_back(current.BaseName().path_); - - // Capture drive letter, if any. - FilePath dir = current.DirName(); - int letter = FindDriveLetter(dir.path_); - if (letter != static_cast(std::string::npos)) { - components.push_back(std::string(dir.path_, 0, letter + 1)); } } @@ -122,22 +116,22 @@ FilePath FilePath::DirName() FilePath newPath(path_); newPath.StripTrailingSeparatorsInternal(); - int letter = FindDriveLetter(newPath.path_); std::string::size_type lastSeparator = newPath.path_.find_last_of(kSeparators, std::string::npos, kSeparatorsLength - 1); - int one = 1; - int two = 2; - int three = 3; + std::string::size_type zero = 0; + std::string::size_type one = 1; + std::string::size_type two = 2; + if (lastSeparator == std::string::npos) { // path_ is in the current directory. - newPath.path_.resize(letter + one); - } else if (lastSeparator == letter + one) { + newPath.path_.resize(zero); + } else if (lastSeparator == zero) { // path_ is in the root directory. - newPath.path_.resize(letter + two); - } else if (lastSeparator == letter + two && IsSeparator(newPath.path_[letter + one])) { + newPath.path_.resize(one); + } else if (lastSeparator == one && IsSeparator(newPath.path_[zero])) { // path_ is in "//" (possibly with a drive letter); leave the double // separator intact indicating alternate root. - newPath.path_.resize(letter + three); + newPath.path_.resize(two); } else if (lastSeparator != 0) { // path_ is somewhere else, trim the basename. newPath.path_.resize(lastSeparator); @@ -154,11 +148,6 @@ FilePath FilePath::BaseName() { FilePath newPath(path_); newPath.StripTrailingSeparatorsInternal(); - // The drive letter, if any, is always stripped. - int letter = FindDriveLetter(newPath.path_); - if (letter != static_cast(std::string::npos)) { - newPath.path_.erase(0, letter + 1); - } // Keep everything after the final separator, but if the pathname is only // one character and it's a separator, leave it alone. @@ -178,10 +167,7 @@ void FilePath::StripTrailingSeparatorsInternal() } int one = 1; int two = 2; - int start = FindDriveLetter(path_) + two; - if (start <= 0) { - return; - } + int start = 1; std::string::size_type lastStripped = std::string::npos; for (std::string::size_type pos = path_.length(); pos > start && FilePath::IsSeparator(path_[pos - one]); --pos) { if (pos != start + one || lastStripped == start + two || !FilePath::IsSeparator(path_[start - one])) { @@ -191,11 +177,6 @@ void FilePath::StripTrailingSeparatorsInternal() } } -int FilePath::FindDriveLetter(const std::string &path) -{ - return (int)std::string::npos; -} - bool FilePath::AreAllSeparators(const std::string &input) { for (std::string::const_iterator it = input.begin(); it != input.end(); ++it) {