Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f2c1376 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

New Executor implementaiton for SystemUI.

The implementation is DelayableExecutor. It looks and feels a lot like
a Handler (it is currently powered by a Handler under the covers).

Developers can now as for an Executor to be injected. By default, this
injects the "Background" Executor, but they can also ask for the
@Main or @Background Executor explicitly.

A FakeExecutor implementation is provided that implements a
synchronous version of DelayableExecutor. It can be configured to run
everything passed to it immediately, or can queue items to run in a
controlled, precise manner.

The new Executor is substituted into one place - TileQueryHelper -in
place of Handlers as a demonstration of its use. The test for
TileQueryHelper no longer requires the @RunWithLooper annotation as a
result.

Bug: 145135056
Test: atest SystemUITests
Change-Id: I76a8a9b2efa4c49e9b06492aca5b336726dc380e
parent 02ef708e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.systemui.statusbar.phone.KeyguardLiftController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.phone.StatusBarComponent;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.util.concurrency.ConcurrencyModule;
import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.time.SystemClock;
import com.android.systemui.util.time.SystemClockImpl;
@@ -53,6 +54,7 @@ import dagger.Provides;
 * implementation.
 */
@Module(includes = {AssistModule.class,
                    ConcurrencyModule.class,
                    PeopleHubModule.class},
        subcomponents = {StatusBarComponent.class})
public abstract class SystemUIModule {
+30 −0
Original line number Diff line number Diff line
/*
 * 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.systemui.dagger.qualifiers;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Qualifier;

@Qualifier
@Documented
@Retention(RUNTIME)
public @interface Background {
}
+30 −0
Original line number Diff line number Diff line
/*
 * 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.systemui.dagger.qualifiers;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Qualifier;

@Qualifier
@Documented
@Retention(RUNTIME)
public @interface Main {
}
+11 −11
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
@@ -34,8 +33,8 @@ import android.util.ArraySet;
import android.widget.Button;

import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.BgHandler;
import com.android.systemui.dagger.qualifiers.MainHandler;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.qs.QSTile.State;
import com.android.systemui.qs.QSTileHost;
@@ -47,6 +46,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executor;

import javax.inject.Inject;

@@ -55,8 +55,8 @@ public class TileQueryHelper {

    private final ArrayList<TileInfo> mTiles = new ArrayList<>();
    private final ArraySet<String> mSpecs = new ArraySet<>();
    private final Handler mBgHandler;
    private final Handler mMainHandler;
    private final Executor mMainExecutor;
    private final Executor mBgExecutor;
    private final Context mContext;
    private TileStateListener mListener;

@@ -64,10 +64,10 @@ public class TileQueryHelper {

    @Inject
    public TileQueryHelper(Context context,
            @MainHandler Handler mainHandler, @BgHandler Handler bgHandler) {
            @Main Executor mainExecutor, @Background Executor bgExecutor) {
        mContext = context;
        mMainHandler = mainHandler;
        mBgHandler = bgHandler;
        mMainExecutor = mainExecutor;
        mBgExecutor = bgExecutor;
    }

    public void setListener(TileStateListener listener) {
@@ -126,7 +126,7 @@ public class TileQueryHelper {
            tilesToAdd.add(tile);
        }

        mBgHandler.post(() -> {
        mBgExecutor.execute(() -> {
            for (QSTile tile : tilesToAdd) {
                final QSTile.State state = tile.getState().copy();
                // Ignore the current state and get the generic label instead.
@@ -139,7 +139,7 @@ public class TileQueryHelper {
    }

    private void addPackageTiles(final QSTileHost host) {
        mBgHandler.post(() -> {
        mBgExecutor.execute(() -> {
            Collection<QSTile> params = host.getTiles();
            PackageManager pm = mContext.getPackageManager();
            List<ResolveInfo> services = pm.queryIntentServicesAsUser(
@@ -185,7 +185,7 @@ public class TileQueryHelper {

    private void notifyTilesChanged(final boolean finished) {
        final ArrayList<TileInfo> tilesToReturn = new ArrayList<>(mTiles);
        mMainHandler.post(() -> {
        mMainExecutor.execute(() -> {
            if (mListener != null) {
                mListener.onTilesChanged(tilesToReturn);
            }
+4 −5
Original line number Diff line number Diff line
@@ -17,14 +17,13 @@
package com.android.systemui.statusbar;

import android.annotation.NonNull;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.provider.DeviceConfig;
import android.util.ArrayMap;

import com.android.systemui.dagger.qualifiers.BgHandler;
import com.android.systemui.dagger.qualifiers.Background;

import java.util.Map;
import java.util.concurrent.Executor;

import javax.inject.Inject;
import javax.inject.Singleton;
@@ -49,10 +48,10 @@ public class FeatureFlags {
    private final Map<String, Boolean> mCachedDeviceConfigFlags = new ArrayMap<>();

    @Inject
    public FeatureFlags(@BgHandler Handler bgHandler) {
    public FeatureFlags(@Background Executor executor) {
        DeviceConfig.addOnPropertiesChangedListener(
                "systemui",
                new HandlerExecutor(bgHandler),
                executor,
                this::onPropertiesChanged);
    }

Loading