Removes logic to disable gesture nav when default home app changes

Bug: 137197916
Test: Manual test with setting a 3P launcher as default
Test: make RunSettingsRoboTests ROBOTEST_FILTER=SystemNavigationGestureSettingsTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=SystemNavigationPreferenceControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=RadioButtonPreferenceWithExtraWidgetTest
Change-Id: Id397cfa1c2439222aa21a7b7fe5f69818bf1fe97
diff --git a/src/com/android/settings/gestures/GestureNavigationNotAvailableDialog.java b/src/com/android/settings/gestures/GestureNavigationNotAvailableDialog.java
deleted file mode 100644
index 6e8b414..0000000
--- a/src/com/android/settings/gestures/GestureNavigationNotAvailableDialog.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.settings.gestures;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.os.Bundle;
-
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-
-/**
- * Dialog to notify user that gesture navigation is not available because of unsupported launcher.
- */
-public class GestureNavigationNotAvailableDialog extends InstrumentedDialogFragment {
-    private static final String TAG = "GestureNavigationNotAvailableDialog";
-
-    public static void show(SystemNavigationGestureSettings parent) {
-        if (!parent.isAdded()) {
-            return;
-        }
-
-        final GestureNavigationNotAvailableDialog dialog =
-                new GestureNavigationNotAvailableDialog();
-        dialog.setTargetFragment(parent, 0);
-        dialog.show(parent.getFragmentManager(), TAG);
-    }
-
-    @Override
-    public int getMetricsCategory() {
-        return SettingsEnums.SETTINGS_GESTURE_NAV_NOT_AVAILABLE_DLG;
-    }
-
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        final Context context = getActivity();
-        final String defaultHomeAppName = SystemNavigationPreferenceController
-                .getDefaultHomeAppName(context);
-        final String message = getString(R.string.gesture_not_supported_dialog_message,
-                defaultHomeAppName);
-        return new AlertDialog.Builder(context)
-                .setMessage(message)
-                .setPositiveButton(R.string.okay, null)
-                .create();
-    }
-}
\ No newline at end of file
diff --git a/src/com/android/settings/gestures/SystemNavigationGestureSettings.java b/src/com/android/settings/gestures/SystemNavigationGestureSettings.java
index b3d090d..3def780 100644
--- a/src/com/android/settings/gestures/SystemNavigationGestureSettings.java
+++ b/src/com/android/settings/gestures/SystemNavigationGestureSettings.java
@@ -22,7 +22,6 @@
 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
 
 import static com.android.settings.widget.RadioButtonPreferenceWithExtraWidget.EXTRA_WIDGET_VISIBILITY_GONE;
-import static com.android.settings.widget.RadioButtonPreferenceWithExtraWidget.EXTRA_WIDGET_VISIBILITY_INFO;
 import static com.android.settings.widget.RadioButtonPreferenceWithExtraWidget.EXTRA_WIDGET_VISIBILITY_SETTING;
 
 import android.accessibilityservice.AccessibilityServiceInfo;
@@ -160,17 +159,9 @@
 
         RadioButtonPreferenceWithExtraWidget p = (RadioButtonPreferenceWithExtraWidget) pref;
         if (info.getKey() == KEY_SYSTEM_NAV_GESTURAL) {
-            if (SystemNavigationPreferenceController.isGestureNavSupportedByDefaultLauncher(
-                    getContext())) {
-                p.setExtraWidgetVisibility(EXTRA_WIDGET_VISIBILITY_SETTING);
-                p.setExtraWidgetOnClickListener((v) -> GestureNavigationBackSensitivityDialog
-                        .show(this, getBackSensitivity(getContext(), mOverlayManager)));
-            } else {
-                p.setEnabled(false);
-                p.setExtraWidgetVisibility(EXTRA_WIDGET_VISIBILITY_INFO);
-                p.setExtraWidgetOnClickListener((v) ->
-                        GestureNavigationNotAvailableDialog.show(this));
-            }
+            p.setExtraWidgetVisibility(EXTRA_WIDGET_VISIBILITY_SETTING);
+            p.setExtraWidgetOnClickListener((v) -> GestureNavigationBackSensitivityDialog
+                    .show(this, getBackSensitivity(getContext(), mOverlayManager)));
         } else {
             p.setExtraWidgetVisibility(EXTRA_WIDGET_VISIBILITY_GONE);
         }
@@ -219,12 +210,6 @@
     @Override
     protected boolean setDefaultKey(String key) {
         final Context c = getContext();
-        if (key == KEY_SYSTEM_NAV_GESTURAL &&
-                !SystemNavigationPreferenceController.isGestureNavSupportedByDefaultLauncher(c)) {
-            // This should not happen since the preference is disabled. Return to be safe.
-            return false;
-        }
-
         setCurrentSystemNavigationMode(c, mOverlayManager, key);
         setIllustrationVideo(mVideoPreference, key);
         if (TextUtils.equals(KEY_SYSTEM_NAV_GESTURAL, key) && (
diff --git a/src/com/android/settings/gestures/SystemNavigationPreferenceController.java b/src/com/android/settings/gestures/SystemNavigationPreferenceController.java
index a151dc1..d0d8155 100644
--- a/src/com/android/settings/gestures/SystemNavigationPreferenceController.java
+++ b/src/com/android/settings/gestures/SystemNavigationPreferenceController.java
@@ -22,14 +22,11 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
 
-import java.util.ArrayList;
-
 public class SystemNavigationPreferenceController extends BasePreferenceController {
 
     static final String PREF_KEY_SYSTEM_NAVIGATION = "gesture_system_navigation";
@@ -101,31 +98,4 @@
         return NAV_BAR_MODE_GESTURAL == context.getResources().getInteger(
                 com.android.internal.R.integer.config_navBarInteractionMode);
     }
-
-    static boolean isGestureNavSupportedByDefaultLauncher(Context context) {
-        final ComponentName cn = context.getPackageManager().getHomeActivities(new ArrayList<>());
-        if (cn == null) {
-            // There is no default home app set for the current user, don't make any changes yet.
-            return true;
-        }
-        ComponentName recentsComponentName = ComponentName.unflattenFromString(context.getString(
-                com.android.internal.R.string.config_recentsComponentName));
-        return recentsComponentName.getPackageName().equals(cn.getPackageName());
-    }
-
-    static String getDefaultHomeAppName(Context context) {
-        final PackageManager pm = context.getPackageManager();
-        final ComponentName cn = pm.getHomeActivities(new ArrayList<>());
-        if (cn != null) {
-            try {
-                ApplicationInfo ai = pm.getApplicationInfo(cn.getPackageName(), 0);
-                if (ai != null) {
-                    return pm.getApplicationLabel(ai).toString();
-                }
-            } catch (final PackageManager.NameNotFoundException e) {
-                // Do nothing
-            }
-        }
-        return "";
-    }
 }
diff --git a/tests/robotests/src/com/android/settings/gestures/SystemNavigationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SystemNavigationPreferenceControllerTest.java
index 79f1850..3163f9a 100644
--- a/tests/robotests/src/com/android/settings/gestures/SystemNavigationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SystemNavigationPreferenceControllerTest.java
@@ -24,7 +24,6 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
 import android.content.ComponentName;
@@ -181,46 +180,4 @@
         assertThat(TextUtils.equals(mController.getSummary(), mContext.getText(
                 com.android.settings.R.string.swipe_up_to_switch_apps_title))).isTrue();
     }
-
-    @Test
-    public void testIsGestureNavSupportedByDefaultLauncher_noDefaultLauncher() {
-        when(mMockPackageManager.getHomeActivities(any())).thenReturn(null);
-        assertThat(SystemNavigationPreferenceController
-                .isGestureNavSupportedByDefaultLauncher(mMockContext)).isTrue();
-    }
-
-    @Test
-    public void testIsGestureNavSupportedByDefaultLauncher_supported() {
-        when(mMockPackageManager.getHomeActivities(any())).thenReturn(
-                ComponentName.unflattenFromString(TEST_RECENTS_COMPONENT_NAME));
-        assertThat(SystemNavigationPreferenceController
-                .isGestureNavSupportedByDefaultLauncher(mMockContext)).isTrue();
-    }
-
-    @Test
-    public void testIsGestureNavSupportedByDefaultLauncher_notSupported() {
-        when(mMockPackageManager.getHomeActivities(any())).thenReturn(
-                new ComponentName("unsupported", "launcher"));
-        assertThat(SystemNavigationPreferenceController
-                .isGestureNavSupportedByDefaultLauncher(mMockContext)).isFalse();
-    }
-
-    @Test
-    public void testGetDefaultHomeAppName_noDefaultLauncher() {
-        when(mMockPackageManager.getHomeActivities(any())).thenReturn(null);
-        assertThat(SystemNavigationPreferenceController
-                .getDefaultHomeAppName(mMockContext)).isEqualTo("");
-    }
-
-    @Test
-    public void testGetDefaultHomeAppName_defaultLauncherExists() throws Exception {
-        when(mMockPackageManager.getHomeActivities(any())).thenReturn(
-                new ComponentName("supported", "launcher"));
-        ApplicationInfo info = new ApplicationInfo();
-        when(mMockPackageManager.getApplicationInfo("supported", 0)).thenReturn(info);
-        when(mMockPackageManager.getApplicationLabel(info)).thenReturn("Test Home App");
-
-        assertThat(SystemNavigationPreferenceController
-                .getDefaultHomeAppName(mMockContext)).isEqualTo("Test Home App");
-    }
 }
\ No newline at end of file