summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorGalia Peycheva <galinap@google.com>2021-05-25 12:05:42 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-05-25 12:05:42 +0000
commitee1219ac1dd7d69044e15a38c3c248b67ecdeda3 (patch)
tree1c1ab60bfa35da0d539e6ccb680495d34df9f9ef /core/java/android
parent94c64def14c1bec5e1dbd01fabf19ae8287eed91 (diff)
parentfde81bf22998e0cebf91f7d725bcd58a069d566b (diff)
Merge "Add TunnelModeStateListener in java+jni" into sc-dev
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/TunnelModeEnabledListener.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/core/java/android/view/TunnelModeEnabledListener.java b/core/java/android/view/TunnelModeEnabledListener.java
new file mode 100644
index 000000000000..c158da9dfa23
--- /dev/null
+++ b/core/java/android/view/TunnelModeEnabledListener.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2021 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 android.view;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Listens for tunnel mode enabled/disabled events from SurfaceFlinger.
+ * {@hide}
+ */
+public abstract class TunnelModeEnabledListener {
+
+ private long mNativeListener;
+ private final Executor mExecutor;
+
+ public TunnelModeEnabledListener(Executor executor) {
+ mExecutor = executor;
+ mNativeListener = nativeCreate(this);
+ }
+
+ /**
+ * Destroys the listener.
+ */
+ public void destroy() {
+ if (mNativeListener == 0) {
+ return;
+ }
+ unregister(this);
+ nativeDestroy(mNativeListener);
+ mNativeListener = 0;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ destroy();
+ } finally {
+ super.finalize();
+ }
+ }
+
+ /**
+ * Reports when tunnel mode has been enabled/disabled.
+ */
+ public abstract void onTunnelModeEnabledChanged(boolean tunnelModeEnabled);
+
+ /**
+ * Registers a listener.
+ */
+ public static void register(TunnelModeEnabledListener listener) {
+ if (listener.mNativeListener == 0) {
+ return;
+ }
+ nativeRegister(listener.mNativeListener);
+ }
+
+ /**
+ * Unregisters a listener.
+ */
+ public static void unregister(TunnelModeEnabledListener listener) {
+ if (listener.mNativeListener == 0) {
+ return;
+ }
+ nativeUnregister(listener.mNativeListener);
+ }
+
+ /**
+ * Dispatch tunnel mode enabled.
+ *
+ * Called from native code on a binder thread.
+ */
+ @VisibleForTesting
+ public static void dispatchOnTunnelModeEnabledChanged(TunnelModeEnabledListener listener,
+ boolean tunnelModeEnabled) {
+ listener.mExecutor.execute(() -> listener.onTunnelModeEnabledChanged(tunnelModeEnabled));
+ }
+
+ private static native long nativeCreate(TunnelModeEnabledListener thiz);
+ private static native void nativeDestroy(long ptr);
+ private static native void nativeRegister(long ptr);
+ private static native void nativeUnregister(long ptr);
+}