Loading src/com/android/settings/gestures/GestureNavigationNotAvailableDialog.javadeleted 100644 → 0 +0 −62 Original line number Diff line number Diff line /* * 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 src/com/android/settings/gestures/SystemNavigationGestureSettings.java +3 −18 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVE 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; Loading Loading @@ -160,17 +159,9 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment { 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)); } } else { p.setExtraWidgetVisibility(EXTRA_WIDGET_VISIBILITY_GONE); } Loading Loading @@ -219,12 +210,6 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment { @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) && ( Loading src/com/android/settings/gestures/SystemNavigationPreferenceController.java +0 −30 Original line number Diff line number Diff line Loading @@ -22,14 +22,11 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL; 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"; Loading Loading @@ -101,31 +98,4 @@ public class SystemNavigationPreferenceController extends BasePreferenceControll 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 ""; } } tests/robotests/src/com/android/settings/gestures/SystemNavigationPreferenceControllerTest.java +0 −43 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import static com.android.settings.gestures.SystemNavigationPreferenceController import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import android.content.ComponentName; Loading Loading @@ -181,46 +180,4 @@ public class SystemNavigationPreferenceControllerTest { 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 Loading
src/com/android/settings/gestures/GestureNavigationNotAvailableDialog.javadeleted 100644 → 0 +0 −62 Original line number Diff line number Diff line /* * 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
src/com/android/settings/gestures/SystemNavigationGestureSettings.java +3 −18 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVE 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; Loading Loading @@ -160,17 +159,9 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment { 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)); } } else { p.setExtraWidgetVisibility(EXTRA_WIDGET_VISIBILITY_GONE); } Loading Loading @@ -219,12 +210,6 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment { @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) && ( Loading
src/com/android/settings/gestures/SystemNavigationPreferenceController.java +0 −30 Original line number Diff line number Diff line Loading @@ -22,14 +22,11 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL; 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"; Loading Loading @@ -101,31 +98,4 @@ public class SystemNavigationPreferenceController extends BasePreferenceControll 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 ""; } }
tests/robotests/src/com/android/settings/gestures/SystemNavigationPreferenceControllerTest.java +0 −43 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import static com.android.settings.gestures.SystemNavigationPreferenceController import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import android.content.ComponentName; Loading Loading @@ -181,46 +180,4 @@ public class SystemNavigationPreferenceControllerTest { 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