OSDN Git Service

Add extensionController based on PackageManager FEATURE
authorLujiang Xue <rogerxue@google.com>
Tue, 22 Aug 2017 21:13:45 +0000 (14:13 -0700)
committerLujiang Xue <rogerxue@google.com>
Thu, 24 Aug 2017 17:15:50 +0000 (10:15 -0700)
Bug: 64818339

Test: make and flash on 6P and headunit, verified in car mode the phone keep phone status bar, and on headunit, it use car status bar all the time
Change-Id: I6b3de99f4c21a50eb8521bf61f640f12cd6c3f02

packages/SystemUI/res/values-car/dimens.xml [deleted file]
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionController.java
packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionControllerImpl.java
packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeExtensionController.java

diff --git a/packages/SystemUI/res/values-car/dimens.xml b/packages/SystemUI/res/values-car/dimens.xml
deleted file mode 100644 (file)
index b2e7bd1..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- * Copyright (c) 2017, 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.
-*/
--->
-<resources>
-    <!-- The height of the quick settings footer that holds the user switcher, settings icon,
-         etc. in the car setting.-->
-    <dimen name="qs_footer_height">74dp</dimen>
-</resources>
index 4fb5754..db45453 100644 (file)
@@ -19,7 +19,6 @@ package com.android.systemui.statusbar.phone;
 import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN;
 import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
 import static android.app.StatusBarManager.windowStateToString;
-import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
 
 import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
 import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWAKE;
@@ -1169,7 +1168,8 @@ public class StatusBar extends SystemUI implements DemoMode,
             ExtensionFragmentListener.attachExtensonToFragment(container, QS.TAG, R.id.qs_frame,
                     Dependency.get(ExtensionController.class).newExtension(QS.class)
                             .withPlugin(QS.class)
-                            .withUiMode(UI_MODE_TYPE_CAR, () -> new CarQSFragment())
+                            .withFeature(
+                                    PackageManager.FEATURE_AUTOMOTIVE, () -> new CarQSFragment())
                             .withDefault(() -> new QSFragment())
                             .build());
             final QSTileHost qsh = SystemUIFactory.getInstance().createQSTileHost(mContext, this,
index ede8411..cade5dc 100644 (file)
@@ -56,6 +56,7 @@ public interface ExtensionController {
         ExtensionBuilder<T> withDefault(Supplier<T> def);
         ExtensionBuilder<T> withCallback(Consumer<T> callback);
         ExtensionBuilder<T> withUiMode(int mode, Supplier<T> def);
+        ExtensionBuilder<T> withFeature(String feature, Supplier<T> def);
         Extension build();
     }
 
index cc10775..6d75cfc 100644 (file)
@@ -38,8 +38,9 @@ public class ExtensionControllerImpl implements ExtensionController {
 
     public static final int SORT_ORDER_PLUGIN  = 0;
     public static final int SORT_ORDER_TUNER   = 1;
-    public static final int SORT_ORDER_UI_MODE = 2;
-    public static final int SORT_ORDER_DEFAULT = 3;
+    public static final int SORT_ORDER_FEATURE = 2;
+    public static final int SORT_ORDER_UI_MODE = 3;
+    public static final int SORT_ORDER_DEFAULT = 4;
 
     private final Context mDefaultContext;
 
@@ -92,6 +93,7 @@ public class ExtensionControllerImpl implements ExtensionController {
             return this;
         }
 
+        @Override
         public ExtensionController.ExtensionBuilder<T> withUiMode(int uiMode,
                 Supplier<T> supplier) {
             mExtension.addUiMode(uiMode, supplier);
@@ -99,6 +101,13 @@ public class ExtensionControllerImpl implements ExtensionController {
         }
 
         @Override
+        public ExtensionController.ExtensionBuilder<T> withFeature(String feature,
+                Supplier<T> supplier) {
+            mExtension.addFeature(feature, supplier);
+            return this;
+        }
+
+        @Override
         public ExtensionController.ExtensionBuilder<T> withCallback(
                 Consumer<T> callback) {
             mExtension.mCallbacks.add(callback);
@@ -107,7 +116,7 @@ public class ExtensionControllerImpl implements ExtensionController {
 
         @Override
         public ExtensionController.Extension build() {
-            // Manually sort, plugins first, tuners second, defaults last.
+            // Sort items in ascending order
             Collections.sort(mExtension.mProducers, Comparator.comparingInt(Item::sortOrder));
             mExtension.notifyChanged();
             return mExtension;
@@ -188,6 +197,10 @@ public class ExtensionControllerImpl implements ExtensionController {
             mProducers.add(new UiModeItem(uiMode, mode));
         }
 
+        public void addFeature(String feature, Supplier<T> mode) {
+            mProducers.add(new FeatureItem<>(feature, mode));
+        }
+
         private class PluginItem<P extends Plugin> implements Item<T>, PluginListener<P> {
             private final PluginConverter<T, P> mConverter;
             private T mItem;
@@ -305,6 +318,32 @@ public class ExtensionControllerImpl implements ExtensionController {
             }
         }
 
+        private class FeatureItem<T> implements Item<T> {
+            private final String mFeature;
+            private final Supplier<T> mSupplier;
+
+            public FeatureItem(String feature, Supplier<T> supplier) {
+                mSupplier = supplier;
+                mFeature = feature;
+            }
+
+            @Override
+            public T get() {
+                return mDefaultContext.getPackageManager().hasSystemFeature(mFeature)
+                        ? mSupplier.get() : null;
+            }
+
+            @Override
+            public void destroy() {
+
+            }
+
+            @Override
+            public int sortOrder() {
+                return SORT_ORDER_FEATURE;
+            }
+        }
+
         private class Default<T> implements Item<T> {
             private final Supplier<T> mSupplier;
 
index 586a424..ab16e3b 100644 (file)
@@ -81,6 +81,11 @@ public class FakeExtensionController implements ExtensionController {
         }
 
         @Override
+        public ExtensionBuilder<T> withFeature(String feature, Supplier<T> def) {
+            return null;
+        }
+
+        @Override
         public Extension build() {
             return new FakeExtension(mAllocation);
         }