Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3005e17b authored by George Mount's avatar George Mount
Browse files

Fix monkey NPE

Bug 33177567

Monkey was causing a commit() while the activity was shutting down.
This protects from an NPE in this unlikely situation.

Test: cts-tradefed run singleCommand cts -d --skip-preconditions
      --skip-connectivity-check -m CtsFragmentTestCases

Change-Id: I832cfa8fb187c61b4d2f5a8a4d0f508d7a435171
parent 1dddc057
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
@@ -349,9 +351,17 @@ final class BackStackRecord extends FragmentTransaction implements

    public BackStackRecord(FragmentManagerImpl manager) {
        mManager = manager;
        int targetSdkVersion = manager.mHost.getContext().getApplicationInfo().targetSdkVersion;
        // TODO: make the check N_MR1 or O
        mAllowOptimization = targetSdkVersion > Build.VERSION_CODES.N;
        FragmentHostCallback host = manager.mHost;
        if (host != null) {
            Context context = host.getContext();
            if (context != null) {
                ApplicationInfo info = context.getApplicationInfo();
                if (info != null) {
                    int targetSdkVersion = info.targetSdkVersion;
                    mAllowOptimization = targetSdkVersion > Build.VERSION_CODES.N_MR1;
                }
            }
        }
    }

    public int getId() {