diff options
author | 2017-08-24 20:22:31 +0000 | |
---|---|---|
committer | 2017-08-24 20:22:31 +0000 | |
commit | 82765d5f298d71242ede48c81d92696b285d48e9 (patch) | |
tree | 893de2b76235f0f19edad8b569abafd8a5274d1b | |
parent | 81c76a98f97fce850b273b5a4cb95921f886a21f (diff) | |
parent | ccc4e327be528d6446909a13ac4e21e4214403ed (diff) |
Merge "Add extensionController based on PackageManager FEATURE" into oc-mr1-dev am: 130d850614
am: ccc4e327be
Change-Id: Ie47cd2521aa4d21fc2dce3a57d6eff28b1d03f7a
5 files changed, 50 insertions, 27 deletions
diff --git a/packages/SystemUI/res/values-car/dimens.xml b/packages/SystemUI/res/values-car/dimens.xml deleted file mode 100644 index b2e7bd1b881e..000000000000 --- a/packages/SystemUI/res/values-car/dimens.xml +++ /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> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 2e2422df6cd1..3fd620b1b509 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -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, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionController.java index ede8411f3c9f..cade5dc46388 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionController.java @@ -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(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionControllerImpl.java index cc10775a8385..6d75cfcb38f3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ExtensionControllerImpl.java @@ -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; diff --git a/packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeExtensionController.java b/packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeExtensionController.java index 586a424cb816..ab16e3bd163e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeExtensionController.java +++ b/packages/SystemUI/tests/src/com/android/systemui/utils/leaks/FakeExtensionController.java @@ -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); } |