Merge "Add extensionController based on PackageManager FEATURE" into oc-mr1-dev

am: 130d850614

Change-Id: Ie5848073bb6462166ad0c09c84d9a95ac4dbe26a
This commit is contained in:
Lujiang Xue
2017-08-24 20:03:31 +00:00
committed by android-build-merger
5 changed files with 50 additions and 27 deletions

View File

@@ -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>

View 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,

View 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();
}

View 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,12 +93,20 @@ public class ExtensionControllerImpl implements ExtensionController {
return this;
}
@Override
public ExtensionController.ExtensionBuilder<T> withUiMode(int uiMode,
Supplier<T> supplier) {
mExtension.addUiMode(uiMode, supplier);
return this;
}
@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) {
@@ -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;

View File

@@ -80,6 +80,11 @@ public class FakeExtensionController implements ExtensionController {
return null;
}
@Override
public ExtensionBuilder<T> withFeature(String feature, Supplier<T> def) {
return null;
}
@Override
public Extension build() {
return new FakeExtension(mAllocation);