From 2efaa0923cb9fef9c25d99aef2ac79879a228620 Mon Sep 17 00:00:00 2001 From: Mehdi Alizadeh Date: Fri, 21 Jun 2019 15:38:40 -0700 Subject: [PATCH] Accept all system packages as supported home apps for gesture nav Bug: 135769778 Test: Manual test during phone setup Change-Id: I24d414820b0f3d8f5878ca73206844966a6035cf --- .../phone/NavigationModeController.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationModeController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationModeController.java index 11242201d8931..4d7cf2715f9c0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationModeController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationModeController.java @@ -33,6 +33,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.om.IOverlayManager; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.ApkAssets; import android.os.PatternMatcher; @@ -69,6 +70,8 @@ public class NavigationModeController implements Dumpable { private static final String TAG = NavigationModeController.class.getSimpleName(); private static final boolean DEBUG = false; + private static final int SYSTEM_APP_MASK = + ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; static final String SHARED_PREFERENCES_NAME = "navigation_mode_controller_preferences"; static final String PREFS_SWITCHED_FROM_GESTURE_NAV_KEY = "switched_from_gesture_nav"; @@ -315,6 +318,10 @@ public class NavigationModeController implements Dumpable { return; } + Log.d(TAG, "Switching system navigation to 3-button mode:" + + " defaultLauncher=" + getDefaultLauncherPackageName(mCurrentUserContext) + + " contextUser=" + mCurrentUserContext.getUserId()); + setModeOverlay(NAV_BAR_MODE_3BUTTON_OVERLAY, USER_CURRENT); showNotification(mCurrentUserContext, R.string.notification_content_system_nav_changed); mCurrentUserContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) @@ -355,9 +362,10 @@ public class NavigationModeController implements Dumpable { if (defaultLauncherPackageName == null) { return null; } - ComponentName recentsComponentName = ComponentName.unflattenFromString( - context.getString(com.android.internal.R.string.config_recentsComponentName)); - return recentsComponentName.getPackageName().equals(defaultLauncherPackageName); + if (isSystemApp(context, defaultLauncherPackageName)) { + return true; + } + return false; } private String getDefaultLauncherPackageName(Context context) { @@ -368,6 +376,17 @@ public class NavigationModeController implements Dumpable { return cn.getPackageName(); } + /** Returns true if the app for the given package name is a system app for this device */ + private boolean isSystemApp(Context context, String packageName) { + try { + ApplicationInfo ai = context.getPackageManager().getApplicationInfo(packageName, + PackageManager.GET_META_DATA); + return ai != null && ((ai.flags & SYSTEM_APP_MASK) != 0); + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + private void showNotification(Context context, int resId) { final CharSequence message = context.getResources().getString(resId); if (DEBUG) {