Do not load/release back gesture ML model after every device fold/unfold.

Previously, the model's state was being updated every time mIsEnabled changed, causing either a resource load or resource release depending on the direction of the change. However, mIsEnabled changes every time EdgeBackGestureHandler attaches or detaches, which happens every time a foldable folds or unfolds. Releasing and reloading the model's resources every fold/unfold is needless and wasteful.

Now, the model resources only load when the process starts or when the user enables Gesture Navigation mode. The model resources only get released when the user disabled Gesture Navigation mode.

This change is safe because no new behavior is added.

There is also an additional safety check added: now, if the model is currently loading, it will not be asked to predict.

Fix: 214938229
Test: manual

Change-Id: I6127b4a5acfa57e9faa0966d021bd951cf2d7bee
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
index d03ac3b..13c5b48 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
@@ -635,8 +635,9 @@
     }
 
     private void updateMLModelState() {
-        boolean newState = mIsEnabled && DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
-                SystemUiDeviceConfigFlags.USE_BACK_GESTURE_ML_MODEL, false);
+        boolean newState =
+                mIsGesturalModeEnabled && DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
+                        SystemUiDeviceConfigFlags.USE_BACK_GESTURE_ML_MODEL, false);
 
         if (newState == mUseMLModel) {
             return;
@@ -766,7 +767,7 @@
             // ML model
             boolean withinMinRange = x < mMLEnableWidth + mLeftInset
                     || x >= (mDisplaySize.x - mMLEnableWidth - mRightInset);
-            if (!withinMinRange && mUseMLModel
+            if (!withinMinRange && mUseMLModel && !mMLModelIsLoading
                     && (results = getBackGesturePredictionsCategory(x, y, app)) != -1) {
                 withinRange = (results == 1);
             }