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

Invalid task, not in foreground #14

Open
wilmxre opened this issue Apr 2, 2024 · 0 comments
Open

Invalid task, not in foreground #14

wilmxre opened this issue Apr 2, 2024 · 0 comments

Comments

@wilmxre
Copy link
Contributor

wilmxre commented Apr 2, 2024

Sometimes, when you call RNLockTask.startLockTask(), you can get this error: Invalid task, not in foreground. I don't know a clear reproducible way to trigger this error yet, but i got a lot of error reportings on Sentry.

From further investigation i found out that this error is thrown in this part of the ActivityManagerService implementation
(line 8853: https://android.googlesource.com/platform/frameworks/base/+/android-5.0.2_r1/services/core/java/com/android/server/am/ActivityManagerService.java):

 void startLockTaskMode(TaskRecord task) {
  final String pkg;
  synchronized(this) {
    pkg = task.intent.getComponent().getPackageName();
  }
  boolean isSystemInitiated = Binder.getCallingUid() == Process.SYSTEM_UID;
  if (!isSystemInitiated && !isLockTaskAuthorized(pkg)) {
    final TaskRecord taskRecord = task;
    mHandler.post(new Runnable() {
      @Override
      public void run() {
        mLockToAppRequest.showLockTaskPrompt(taskRecord);
      }
    });
    return;
  }
  long ident = Binder.clearCallingIdentity();
  try {
    synchronized(this) {
      // Since we lost lock on task, make sure it is still there.
      task = mStackSupervisor.anyTaskForIdLocked(task.taskId);
      if (task != null) {
        if (!isSystemInitiated &&
          ((mFocusedActivity == null) || (task != mFocusedActivity.task))) {
          throw new IllegalArgumentException("Invalid task, not in foreground");
        }
        mStackSupervisor.setLockTaskModeLocked(task, !isSystemInitiated);
      }
    }
  } finally {
    Binder.restoreCallingIdentity(ident);
  }
}

it seems that there is no focused activity, but i am almost 100% sure the startLockTask() is called when the app is in foreground.

i submitted this ticket to raise awareness and maybe if someone has faced this issue, they might have some good insight to handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant