Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix voiceapp move to background fail #2

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading