AmbientDisplay: Fixed threading
Change-Id: Iee8d2b12145f3f1ab98099631539f6421e99f910
This commit is contained in:
@@ -16,8 +16,9 @@
|
||||
|
||||
package com.android.systemui;
|
||||
|
||||
import com.android.systemui.util.Assert;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.Choreographer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -50,7 +51,7 @@ public class DejankUtils {
|
||||
* <p>Needs to be called from the main thread.
|
||||
*/
|
||||
public static void postAfterTraversal(Runnable r) {
|
||||
throwIfNotCalledOnMainThread();
|
||||
Assert.isMainThread();
|
||||
sPendingRunnables.add(r);
|
||||
postAnimationCallback();
|
||||
}
|
||||
@@ -61,7 +62,7 @@ public class DejankUtils {
|
||||
* <p>Needs to be called from the main thread.
|
||||
*/
|
||||
public static void removeCallbacks(Runnable r) {
|
||||
throwIfNotCalledOnMainThread();
|
||||
Assert.isMainThread();
|
||||
sPendingRunnables.remove(r);
|
||||
sHandler.removeCallbacks(r);
|
||||
}
|
||||
@@ -70,10 +71,4 @@ public class DejankUtils {
|
||||
sChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, sAnimationCallbackRunnable,
|
||||
null);
|
||||
}
|
||||
|
||||
private static void throwIfNotCalledOnMainThread() {
|
||||
if (!Looper.getMainLooper().isCurrentThread()) {
|
||||
throw new IllegalStateException("should be called from the main thread.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,14 +208,15 @@ public class DozeSensors {
|
||||
@Override
|
||||
@AnyThread
|
||||
public void onTrigger(TriggerEvent event) {
|
||||
mWakeLock.acquire();
|
||||
try {
|
||||
if (DEBUG) Log.d(TAG, "onTrigger: " + triggerEventToString(event));
|
||||
mHandler.post(mWakeLock.wrap(() -> {
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "onTrigger: " + triggerEventToString(event));
|
||||
boolean sensorPerformsProxCheck = false;
|
||||
if (mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) {
|
||||
int subType = (int) event.values[0];
|
||||
MetricsLogger.action(
|
||||
mContext, MetricsProto.MetricsEvent.ACTION_AMBIENT_GESTURE, subType);
|
||||
mContext, MetricsProto.MetricsEvent.ACTION_AMBIENT_GESTURE,
|
||||
subType);
|
||||
sensorPerformsProxCheck =
|
||||
mDozeParameters.getPickupSubtypePerformsProxCheck(subType);
|
||||
}
|
||||
@@ -223,9 +224,7 @@ public class DozeSensors {
|
||||
mRegistered = false;
|
||||
mCallback.onSensorPulse(mPulseReason, sensorPerformsProxCheck);
|
||||
updateListener(); // reregister, this sensor only fires once
|
||||
} finally {
|
||||
mWakeLock.release();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void registerSettingsObserver(ContentObserver settingsObserver) {
|
||||
|
||||
@@ -35,8 +35,11 @@ import android.util.Log;
|
||||
import android.view.Display;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.systemui.DejankUtils;
|
||||
import com.android.systemui.SystemUIApplication;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.util.Assert;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
@@ -188,6 +191,7 @@ public class DozeService extends DreamService implements DozeSensors.Callback {
|
||||
}
|
||||
|
||||
private void requestPulse(final int reason, boolean performedProxCheck) {
|
||||
Assert.isMainThread();
|
||||
if (mHost != null && mDreaming && !mPulsing) {
|
||||
// Let the host know we want to pulse. Wait for it to be ready, then
|
||||
// turn the screen on. When finished, turn the screen off again.
|
||||
|
||||
31
packages/SystemUI/src/com/android/systemui/util/Assert.java
Normal file
31
packages/SystemUI/src/com/android/systemui/util/Assert.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.util;
|
||||
|
||||
import android.os.Looper;
|
||||
|
||||
/**
|
||||
* Helper providing common assertions.
|
||||
*/
|
||||
public class Assert {
|
||||
|
||||
public static void isMainThread() {
|
||||
if (!Looper.getMainLooper().isCurrentThread()) {
|
||||
throw new IllegalStateException("should be called from the main thread.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user