aboutsummaryrefslogtreecommitdiff
path: root/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestErrorCallbackActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestErrorCallbackActivity.java')
-rw-r--r--apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestErrorCallbackActivity.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestErrorCallbackActivity.java b/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestErrorCallbackActivity.java
new file mode 100644
index 00000000..b3b4497d
--- /dev/null
+++ b/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestErrorCallbackActivity.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2022 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.mobileer.oboetester;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.view.View;
+import android.widget.TextView;
+
+public class TestErrorCallbackActivity extends Activity {
+
+ private TextView mStatusDeleteCallback;
+ // This must match the value in TestErrorCallback.h
+ private static final int MAGIC_GOOD = 0x600DCAFE;
+ private MyStreamSniffer mStreamSniffer;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_error_callback);
+
+ mStreamSniffer = new MyStreamSniffer();
+ mStatusDeleteCallback = (TextView) findViewById(R.id.text_callback_status);
+ }
+
+ public void onTestDeleteCrash(View view) {
+ mStatusDeleteCallback.setText(getString(R.string.plug_or_unplug));
+ mStreamSniffer.startStreamSniffer();
+ testDeleteCrash();
+ }
+
+
+ // Periodically query the status of the streams.
+ protected class MyStreamSniffer {
+ public static final int SNIFFER_UPDATE_PERIOD_MSEC = 150;
+ public static final int SNIFFER_UPDATE_DELAY_MSEC = 300;
+
+ private Handler mHandler;
+
+ // Display status info for the stream.
+ private Runnable runnableCode = new Runnable() {
+ @Override
+ public void run() {
+ int magic = getCallbackMagic();
+ updateMagicDisplay(magic);
+ mHandler.postDelayed(runnableCode, SNIFFER_UPDATE_PERIOD_MSEC);
+ }
+ };
+
+ private void startStreamSniffer() {
+ stopStreamSniffer();
+ mHandler = new Handler(Looper.getMainLooper());
+ // Start the initial runnable task by posting through the handler
+ mHandler.postDelayed(runnableCode, SNIFFER_UPDATE_DELAY_MSEC);
+ }
+
+ private void stopStreamSniffer() {
+ if (mHandler != null) {
+ mHandler.removeCallbacks(runnableCode);
+ }
+ }
+ }
+
+ private void updateMagicDisplay(int magic) {
+ if (magic != 0) {
+ String text = getString(R.string.report_magic_pass, MAGIC_GOOD);
+ if (magic != MAGIC_GOOD) {
+ text = getString(R.string.report_magic_fail,
+ magic, MAGIC_GOOD);
+ }
+ mStatusDeleteCallback.setText(text);
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mStreamSniffer.stopStreamSniffer();
+ }
+
+ private native void testDeleteCrash();
+ private native int getCallbackMagic();
+
+}