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

Commit 72bfcc9d authored by Kenneth Ford's avatar Kenneth Ford
Browse files

Uses the DisplayThread instead of creating a new thread to improve performance at startup

Bug: 197939343
Test: Build & atest DeviceStateManagerServiceTest
Change-Id: I811406be6011efb14cf4b838b05a2646f617adf7
parent 396f6667
Loading
Loading
Loading
Loading
+6 −10
Original line number Original line Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.devicestate;
import static android.Manifest.permission.CONTROL_DEVICE_STATE;
import static android.Manifest.permission.CONTROL_DEVICE_STATE;
import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE;
import static android.hardware.devicestate.DeviceStateManager.MAXIMUM_DEVICE_STATE;
import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE;
import static android.hardware.devicestate.DeviceStateManager.MINIMUM_DEVICE_STATE;
import static android.os.Process.THREAD_PRIORITY_DISPLAY;


import static com.android.server.devicestate.OverrideRequestController.STATUS_ACTIVE;
import static com.android.server.devicestate.OverrideRequestController.STATUS_ACTIVE;
import static com.android.server.devicestate.OverrideRequestController.STATUS_CANCELED;
import static com.android.server.devicestate.OverrideRequestController.STATUS_CANCELED;
@@ -36,7 +35,6 @@ import android.hardware.devicestate.IDeviceStateManager;
import android.hardware.devicestate.IDeviceStateManagerCallback;
import android.hardware.devicestate.IDeviceStateManagerCallback;
import android.os.Binder;
import android.os.Binder;
import android.os.Handler;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ResultReceiver;
@@ -48,8 +46,8 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.DisplayThread;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.ServiceThread;
import com.android.server.SystemService;
import com.android.server.SystemService;
import com.android.server.policy.DeviceStatePolicyImpl;
import com.android.server.policy.DeviceStatePolicyImpl;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
@@ -93,10 +91,9 @@ public final class DeviceStateManagerService extends SystemService {
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;


    private final Object mLock = new Object();
    private final Object mLock = new Object();
    // Internal system service thread used to dispatch calls to the policy and to registered
    // Handler on the {@link DisplayThread} used to dispatch calls to the policy and to registered
    // callbacks though its handler (mHandler). Provides a guarantee of callback order when
    // callbacks though its handler (mHandler). Provides a guarantee of callback order when
    // leveraging mHandler and also enables posting messages with the service lock held.
    // leveraging mHandler and also enables posting messages with the service lock held.
    private final HandlerThread mHandlerThread;
    private final Handler mHandler;
    private final Handler mHandler;
    @NonNull
    @NonNull
    private final DeviceStatePolicy mDeviceStatePolicy;
    private final DeviceStatePolicy mDeviceStatePolicy;
@@ -149,11 +146,10 @@ public final class DeviceStateManagerService extends SystemService {
    @VisibleForTesting
    @VisibleForTesting
    DeviceStateManagerService(@NonNull Context context, @NonNull DeviceStatePolicy policy) {
    DeviceStateManagerService(@NonNull Context context, @NonNull DeviceStatePolicy policy) {
        super(context);
        super(context);
        // Service thread assigned THREAD_PRIORITY_DISPLAY because this service indirectly drives
        // We use the DisplayThread because this service indirectly drives
        // display (on/off) and window (position) events through its callbacks.
        // display (on/off) and window (position) events through its callbacks.
        mHandlerThread = new ServiceThread(TAG, THREAD_PRIORITY_DISPLAY, false /* allowIo */);
        DisplayThread displayThread = DisplayThread.get();
        mHandlerThread.start();
        mHandler = new Handler(displayThread.getLooper());
        mHandler = mHandlerThread.getThreadHandler();
        mOverrideRequestController = new OverrideRequestController(
        mOverrideRequestController = new OverrideRequestController(
                this::onOverrideRequestStatusChangedLocked);
                this::onOverrideRequestStatusChangedLocked);
        mDeviceStatePolicy = policy;
        mDeviceStatePolicy = policy;
@@ -552,7 +548,7 @@ public final class DeviceStateManagerService extends SystemService {
            }
            }


            ProcessRecord record = new ProcessRecord(callback, pid, this::handleProcessDied,
            ProcessRecord record = new ProcessRecord(callback, pid, this::handleProcessDied,
                    mHandlerThread.getThreadHandler());
                    mHandler);
            try {
            try {
                callback.asBinder().linkToDeath(record, 0);
                callback.asBinder().linkToDeath(record, 0);
            } catch (RemoteException ex) {
            } catch (RemoteException ex) {