Skip to content

Commit

Permalink
fix voiceapp move to background fail
Browse files Browse the repository at this point in the history
  • Loading branch information
qls152 authored and zhangziyi10 committed Jan 20, 2025
1 parent 5a3a4a1 commit 498fe0e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
19 changes: 15 additions & 4 deletions server/ActivityManagerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,9 @@ int ActivityManagerInner::startActivity(const sp<IBinder>& caller, const Intent&
}

auto taskmanager = getTaskManager(packageInfo.isSystemUI);
ActivityStackHandler apptask;
ActivityStackHandler apptask = taskmanager->findTask(packageInfo.packageName);
/** check activity name */
if (activityName.empty()) {
apptask = taskmanager->findTask(packageInfo.packageName);
if (!apptask) {
activityName = packageInfo.entry;
}
Expand Down Expand Up @@ -331,6 +330,17 @@ int ActivityManagerInner::startActivityReal(ITaskManager* taskmanager, const str
std::make_shared<ActivityRecord>(activityUniqueName, caller, requestCode,
launchMode, targetTask, intent, mWindowManager,
taskmanager, &mPendTask);
if (intent.mAction == Intent::ACTION_BOOT_GUIDE) {
newActivity->setCallback([this]() { startHomeActivity(); });
}
bool is_home_task =
std::any_of(packageInfo.activitiesInfo.begin(), packageInfo.activitiesInfo.end(),
[](const auto& activity) {
return std::any_of(activity.actions.begin(), activity.actions.end(),
[](const auto& action) {
return action == Intent::ACTION_HOME;
});
});
const auto appInfo = mAppInfo.findAppInfoWithAlive(packageInfo.packageName);
if (appInfo) {
newActivity->setAppThread(appInfo);
Expand All @@ -344,8 +354,8 @@ int ActivityManagerInner::startActivityReal(ITaskManager* taskmanager, const str
}

const ProcessPriority priority = (ProcessPriority)packageInfo.priority;
const auto task = [this, taskmanager, targetTask, newActivity, startFlag,
priority](const AppAttachTask::Event* e) {
const auto task = [this, taskmanager, targetTask, newActivity, startFlag, priority,
is_home_task](const AppAttachTask::Event* e) {
mPriorityPolicy.add(e->mPid, true, priority);
newActivity->setAppThread(e->mAppRecord);
taskmanager->pushNewActivity(targetTask, newActivity, startFlag);
Expand Down Expand Up @@ -551,6 +561,7 @@ void ActivityManagerInner::reportActivityStatus(const sp<IBinder>& token, int32_
}
case ActivityRecord::DESTROYED: {
activity->setStatus(ActivityRecord::DESTROYED);
activity->executeCallback();
if (const auto appRecord = activity->getAppRecord()) {
bool isSystemUI = appRecord->mIsSystemUI;
if (!isSystemUI) {
Expand Down
9 changes: 9 additions & 0 deletions server/ActivityRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class ActivityRecord : public std::enable_shared_from_this<ActivityRecord> {

friend std::ostream& operator<<(std::ostream& os, const ActivityRecord& record);

void setCallback(std::function<void()> launcher) {
mLauncher = launcher;
}
void executeCallback() {
if (mLauncher) mLauncher();
}

private:
void create();
void start();
Expand All @@ -122,6 +129,8 @@ class ActivityRecord : public std::enable_shared_from_this<ActivityRecord> {
sp<::os::wm::IWindowManager> mWindowService;
ITaskManager* mTaskManager;
TaskBoard* mPendTask;

std::function<void()> mLauncher;
};

using ActivityHandler = std::shared_ptr<ActivityRecord>;
Expand Down
1 change: 1 addition & 0 deletions server/TaskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ITaskManager {
virtual std::ostream& print(std::ostream& os) {
return os;
}
virtual void setHomeTask(const ActivityStackHandler& task) {}
};

class TaskManagerFactory {
Expand Down
17 changes: 16 additions & 1 deletion server/TaskStackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,23 @@ bool TaskStackManager::moveTaskToBackground(const ActivityStackHandler& targetSt
return false;
}

// If it's above HomeTask, move it below HomeTask, otherwise no need to move it
auto hometask_index = std::find(mAllTasks.begin(), mAllTasks.end(), mHomeTask);
if (hometask_index == mAllTasks.end()) {
mAllTasks.remove(targetStack);
mAllTasks.push_back(targetStack);
} else {
for (auto iter = mAllTasks.begin(); iter != hometask_index; ++iter) {
if (*iter == targetStack) {
mAllTasks.erase(iter);
mAllTasks.insert(++hometask_index, targetStack);
break;
}
}
}

if (targetStack == activeTask) {
isBeforeHomeTask = true;
// isBeforeHomeTask = true;
auto topActivity = targetStack->getTopActivity();
topActivity->lifecycleTransition(ActivityRecord::PAUSED);
targetStack->setForeground(false);
Expand Down
3 changes: 3 additions & 0 deletions server/TaskStackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class TaskStackManager : public ITaskManager {

friend std::ostream& operator<<(std::ostream& os, const TaskStackManager& task);
std::ostream& print(std::ostream& os) override;
void setHomeTask(const ActivityStackHandler& task) override {
mHomeTask = task;
}

private:
std::list<ActivityStackHandler> mAllTasks;
Expand Down

0 comments on commit 498fe0e

Please sign in to comment.