Handle Aware sensor status for Always On

- "Always On" preference will be hiden when aware
sensor is available
- Extract NavModeCandidateInfo from SystemNavigationGestureSettings

Bug: 136610131
Test: robotest & manual
Change-Id: If58c70549339b66116f19df7193d85bb04e3f1b7
diff --git a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
index 6a9e9fc..a0b1f44 100644
--- a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
+++ b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
@@ -17,6 +17,7 @@
 
 import android.content.Context;
 import android.hardware.display.AmbientDisplayConfiguration;
+import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.provider.Settings;
 import android.text.TextUtils;
@@ -29,6 +30,7 @@
     private final int OFF = 0;
 
     private static final int MY_USER = UserHandle.myUserId();
+    private static final String PROP_AWARE_AVAILABLE = "ro.vendor.aware_available";
 
     private AmbientDisplayConfiguration mConfig;
     private OnPreferenceChangedCallback mCallback;
@@ -43,7 +45,9 @@
 
     @Override
     public int getAvailabilityStatus() {
-        return isAvailable(getConfig()) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+        return isAvailable(getConfig())
+                && !SystemProperties.getBoolean(PROP_AWARE_AVAILABLE, false) ?
+                AVAILABLE : UNSUPPORTED_ON_DEVICE;
     }
 
     @Override
diff --git a/src/com/android/settings/gestures/SystemNavigationGestureSettings.java b/src/com/android/settings/gestures/SystemNavigationGestureSettings.java
index 3def780..9e35529 100644
--- a/src/com/android/settings/gestures/SystemNavigationGestureSettings.java
+++ b/src/com/android/settings/gestures/SystemNavigationGestureSettings.java
@@ -31,7 +31,6 @@
 import android.content.SharedPreferences;
 import android.content.om.IOverlayManager;
 import android.content.om.OverlayInfo;
-import android.graphics.drawable.Drawable;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.provider.SearchIndexableResource;
@@ -48,6 +47,7 @@
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
+import com.android.settings.utils.CandidateInfoExtra;
 import com.android.settings.widget.RadioButtonPickerFragment;
 import com.android.settings.widget.RadioButtonPreference;
 import com.android.settings.widget.RadioButtonPreferenceWithExtraWidget;
@@ -150,12 +150,12 @@
     @Override
     public void bindPreferenceExtra(RadioButtonPreference pref,
             String key, CandidateInfo info, String defaultKey, String systemDefaultKey) {
-        if (!(info instanceof NavModeCandidateInfo)
+        if (!(info instanceof CandidateInfoExtra)
                 || !(pref instanceof RadioButtonPreferenceWithExtraWidget)) {
             return;
         }
 
-        pref.setSummary(((NavModeCandidateInfo) info).loadSummary());
+        pref.setSummary(((CandidateInfoExtra) info).loadSummary());
 
         RadioButtonPreferenceWithExtraWidget p = (RadioButtonPreferenceWithExtraWidget) pref;
         if (info.getKey() == KEY_SYSTEM_NAV_GESTURAL) {
@@ -175,25 +175,25 @@
     @Override
     protected List<? extends CandidateInfo> getCandidates() {
         final Context c = getContext();
-        List<NavModeCandidateInfo> candidates = new ArrayList<>();
+        List<CandidateInfoExtra> candidates = new ArrayList<>();
 
         if (SystemNavigationPreferenceController.isOverlayPackageAvailable(c,
                 NAV_BAR_MODE_GESTURAL_OVERLAY)) {
-            candidates.add(new NavModeCandidateInfo(
+            candidates.add(new CandidateInfoExtra(
                     c.getText(R.string.edge_to_edge_navigation_title),
                     c.getText(R.string.edge_to_edge_navigation_summary),
                     KEY_SYSTEM_NAV_GESTURAL, true /* enabled */));
         }
         if (SystemNavigationPreferenceController.isOverlayPackageAvailable(c,
                 NAV_BAR_MODE_2BUTTON_OVERLAY)) {
-            candidates.add(new NavModeCandidateInfo(
+            candidates.add(new CandidateInfoExtra(
                     c.getText(R.string.swipe_up_to_switch_apps_title),
                     c.getText(R.string.swipe_up_to_switch_apps_summary),
                     KEY_SYSTEM_NAV_2BUTTONS, true /* enabled */));
         }
         if (SystemNavigationPreferenceController.isOverlayPackageAvailable(c,
                 NAV_BAR_MODE_3BUTTON_OVERLAY)) {
-            candidates.add(new NavModeCandidateInfo(
+            candidates.add(new CandidateInfoExtra(
                     c.getText(R.string.legacy_navigation_title),
                     c.getText(R.string.legacy_navigation_summary),
                     KEY_SYSTEM_NAV_3BUTTONS, true /* enabled */));
@@ -325,39 +325,6 @@
                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 1;
     }
 
-    static class NavModeCandidateInfo extends CandidateInfo {
-        private final CharSequence mLabel;
-        private final CharSequence mSummary;
-        private final String mKey;
-
-        NavModeCandidateInfo(CharSequence label, CharSequence summary, String key,
-                boolean enabled) {
-            super(enabled);
-            mLabel = label;
-            mSummary = summary;
-            mKey = key;
-        }
-
-        @Override
-        public CharSequence loadLabel() {
-            return mLabel;
-        }
-
-        public CharSequence loadSummary() {
-            return mSummary;
-        }
-
-        @Override
-        public Drawable loadIcon() {
-            return null;
-        }
-
-        @Override
-        public String getKey() {
-            return mKey;
-        }
-    }
-
     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
             new BaseSearchIndexProvider() {
                 @Override
diff --git a/src/com/android/settings/utils/CandidateInfoExtra.java b/src/com/android/settings/utils/CandidateInfoExtra.java
new file mode 100644
index 0000000..5bccea6
--- /dev/null
+++ b/src/com/android/settings/utils/CandidateInfoExtra.java
@@ -0,0 +1,54 @@
+/*
+ * 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.utils;
+
+import android.graphics.drawable.Drawable;
+
+import com.android.settingslib.widget.CandidateInfo;
+
+public class CandidateInfoExtra extends CandidateInfo {
+    private final CharSequence mLabel;
+    private final CharSequence mSummary;
+    private final String mKey;
+
+    public CandidateInfoExtra(CharSequence label, CharSequence summary, String key,
+            boolean enabled) {
+        super(enabled);
+        mLabel = label;
+        mSummary = summary;
+        mKey = key;
+    }
+
+    @Override
+    public CharSequence loadLabel() {
+        return mLabel;
+    }
+
+    public CharSequence loadSummary() {
+        return mSummary;
+    }
+
+    @Override
+    public Drawable loadIcon() {
+        return null;
+    }
+
+    @Override
+    public String getKey() {
+        return mKey;
+    }
+}