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

Commit aaeb44bf authored by Ned Burns's avatar Ned Burns
Browse files

Migrate DumpController -> DumpManager

Unify "everything that needs to dump stuff" to use the DumpManager.

Test: atest, manual
Change-Id: Ib475aba4eeccb24bd49ab909896f7d779a8e1b04
parent e33b495c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -88,12 +88,12 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.WirelessUtils;
import com.android.settingslib.fuelgauge.BatteryStatus;
import com.android.systemui.DejankUtils;
import com.android.systemui.DumpController;
import com.android.systemui.Dumpable;
import com.android.systemui.R;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.TaskStackChangeListener;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
@@ -1475,14 +1475,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            Context context,
            @Main Looper mainLooper,
            BroadcastDispatcher broadcastDispatcher,
            DumpController dumpController,
            DumpManager dumpManager,
            @Background Executor backgroundExecutor) {
        mContext = context;
        mSubscriptionManager = SubscriptionManager.from(context);
        mDeviceProvisioned = isDeviceProvisionedInSettingsDb();
        mStrongAuthTracker = new StrongAuthTracker(context, this::notifyStrongAuthStateChanged);
        dumpController.registerDumpable(this);
        mBackgroundExecutor = backgroundExecutor;
        dumpManager.registerDumpable(getClass().getName(), this);

        mHandler = new Handler(mainLooper) {
            @Override
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui

import android.util.Log
import com.android.internal.annotations.GuardedBy
import com.android.systemui.dump.DumpManager
import java.io.FileDescriptor
import java.io.PrintWriter
import java.lang.ref.WeakReference
@@ -32,7 +33,7 @@ import javax.inject.Singleton
 * boot is completed.
 */
@Singleton
class BootCompleteCacheImpl @Inject constructor(private val dumpController: DumpController) :
class BootCompleteCacheImpl @Inject constructor(dumpManager: DumpManager) :
        BootCompleteCache, Dumpable {

    companion object {
@@ -41,7 +42,7 @@ class BootCompleteCacheImpl @Inject constructor(private val dumpController: Dump
    }

    init {
        dumpController.registerDumpable(TAG, this)
        dumpManager.registerDumpable(TAG, this)
    }

    @GuardedBy("listeners")
+0 −2
Original line number Diff line number Diff line
@@ -312,7 +312,6 @@ public class Dependency {
    @Inject Lazy<DevicePolicyManagerWrapper> mDevicePolicyManagerWrapper;
    @Inject Lazy<PackageManagerWrapper> mPackageManagerWrapper;
    @Inject Lazy<SensorPrivacyController> mSensorPrivacyController;
    @Inject Lazy<DumpController> mDumpController;
    @Inject Lazy<DockManager> mDockManager;
    @Inject Lazy<ChannelEditorDialogController> mChannelEditorDialogController;
    @Inject Lazy<INotificationManager> mINotificationManager;
@@ -506,7 +505,6 @@ public class Dependency {
        mProviders.put(DevicePolicyManagerWrapper.class, mDevicePolicyManagerWrapper::get);
        mProviders.put(PackageManagerWrapper.class, mPackageManagerWrapper::get);
        mProviders.put(SensorPrivacyController.class, mSensorPrivacyController::get);
        mProviders.put(DumpController.class, mDumpController::get);
        mProviders.put(DockManager.class, mDockManager::get);
        mProviders.put(ChannelEditorDialogController.class, mChannelEditorDialogController::get);
        mProviders.put(INotificationManager.class, mINotificationManager::get);
+0 −120
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

import android.util.ArraySet
import android.util.Log
import androidx.annotation.GuardedBy
import java.io.FileDescriptor
import java.io.PrintWriter
import java.lang.ref.WeakReference
import java.util.Objects.requireNonNull
import javax.inject.Inject
import javax.inject.Singleton

// TODO: Move all Dumpable dependencies to use DumpController
/**
 * Controller that allows any [Dumpable] to subscribe and be dumped along with other SystemUI
 * dependencies.
 *
 * To dump a specific dumpable on-demand:
 *
 * ```
 * $ adb shell dumpsys activity service com.android.systemui/.SystemUIService dependency DumpController <tag1>,<tag2>,<tag3>
 * ```
 *
 * Where tag1, tag2, etc. are the tags of the dumpables you want to dump.
 */
@Singleton
class DumpController @Inject constructor() : Dumpable {

    companion object {
        private const val TAG = "DumpController"
        private const val DEBUG = false
    }

    @GuardedBy("listeners")
    private val listeners = mutableListOf<RegisteredDumpable>()
    val numListeners: Int
        get() = listeners.size

    /**
     * Adds a [Dumpable] dumpable to be dumped.
     *
     * @param dumpable the [Dumpable] to be added
     */
    fun registerDumpable(dumpable: Dumpable) {
        requireNonNull(dumpable, "The dumpable to be added cannot be null")
        registerDumpable(dumpable.javaClass.simpleName, dumpable)
    }

    /**
     * Adds a [Dumpable] dumpable to be dumped.
     *
     * @param tag a string tag to associate with this dumpable. Tags must be globally unique; this
     *      method will throw if the same tag has already been registered. Tags can be used to
     *      filter output when debugging.
     * @param dumpable the [Dumpable] to be added
     */
    fun registerDumpable(tag: String, dumpable: Dumpable) {
        requireNonNull(dumpable, "The dumpable to be added cannot be null")
        if (DEBUG) Log.v(TAG, "*** register callback for $dumpable")
        synchronized<Unit>(listeners) {
            if (listeners.any { it.tag == tag }) {
                throw IllegalArgumentException("Duplicate dumpable tag registered: $tag")
            } else {
                listeners.add(RegisteredDumpable(tag, WeakReference(dumpable)))
            }
        }
    }

    /**
     * Removes a dumpable from the list of elements to be dumped.
     *
     * @param dumpable the [Dumpable] to be removed.
     */
    fun unregisterDumpable(dumpable: Dumpable) {
        if (DEBUG) Log.v(TAG, "*** unregister callback for $dumpable")
        synchronized(listeners) {
            listeners.removeAll { it.dumpable.get() == dumpable || it.dumpable.get() == null }
        }
    }

    /**
     * Dump all the [Dumpable] registered with the controller
     */
    override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<String>) {
        pw.println("DumpController state:")

        val filter = if (args.size >= 3 && args[0].toLowerCase() == "dependency" &&
                args[1] == "DumpController") {
            ArraySet(args[2].split(',').map { it.toLowerCase() })
        } else {
            null
        }

        synchronized(listeners) {
            listeners.forEach {
                if (filter == null || filter.contains(it.tag.toLowerCase())) {
                    it.dumpable.get()?.dump(fd, pw, args)
                }
            }
        }
    }

    data class RegisteredDumpable(val tag: String, val dumpable: WeakReference<Dumpable>)
}
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ package com.android.systemui;

import androidx.annotation.NonNull;

import com.android.systemui.dump.DumpManager;

import java.io.FileDescriptor;
import java.io.PrintWriter;

@@ -23,7 +25,7 @@ import java.io.PrintWriter;
 * Implemented by classes who want to be in:
 *   {@code adb shell dumpsys activity service com.android.systemui}
 *
 * @see DumpController
 * @see DumpManager
 */
public interface Dumpable {

Loading