Enhancement for Satellite TestApp
Need to to have a simpler process to test send and receive.
Bug: 287566047
Test: mm
Change-Id: Ib13351386110d23481270b175b85806d2a458f7d
diff --git a/testapps/TestSatelliteApp/AndroidManifest.xml b/testapps/TestSatelliteApp/AndroidManifest.xml
index 40954b4..4a6076b 100644
--- a/testapps/TestSatelliteApp/AndroidManifest.xml
+++ b/testapps/TestSatelliteApp/AndroidManifest.xml
@@ -44,5 +44,6 @@
<activity android:name=".Datagram" />
<activity android:name=".Provisioning" />
<activity android:name=".MultipleSendReceive" />
+ <activity android:name=".SendReceive" />
</application>
</manifest>
diff --git a/testapps/TestSatelliteApp/res/layout/activity_SatelliteTestApp.xml b/testapps/TestSatelliteApp/res/layout/activity_SatelliteTestApp.xml
index 2ed4a24..d32916f 100644
--- a/testapps/TestSatelliteApp/res/layout/activity_SatelliteTestApp.xml
+++ b/testapps/TestSatelliteApp/res/layout/activity_SatelliteTestApp.xml
@@ -57,6 +57,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="4dp"
- android:text="@string/SatelliteModemState"/>
+ android:text="@string/MultipleSendReceive"/>
+ <Button
+ android:id="@+id/SendReceive"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingRight="4dp"
+ android:text="@string/SendReceive"/>
</LinearLayout>
</LinearLayout>
diff --git a/testapps/TestSatelliteApp/res/layout/activity_SendReceive.xml b/testapps/TestSatelliteApp/res/layout/activity_SendReceive.xml
new file mode 100644
index 0000000..6490e5d
--- /dev/null
+++ b/testapps/TestSatelliteApp/res/layout/activity_SendReceive.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2023 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
+ -->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:gravity="center"
+ android:paddingLeft="4dp">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:layout_weight="0"
+ android:textColor="@android:color/holo_blue_dark"
+ android:textSize="20dp"
+ android:text="Send and Receive APIs"/>
+ <Button
+ android:id="@+id/sendMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingRight="4dp"
+ android:text="@string/sendMessage"/>
+ <Button
+ android:id="@+id/receiveMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingRight="4dp"
+ android:text="@string/receiveMessage"/>
+ <EditText
+ android:id="@+id/enterText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:hint="Enter message to send"
+ android:inputType="text" />
+ <Button
+ android:id="@+id/Back"
+ android:onClick="Back"
+ android:textColor="@android:color/holo_blue_dark"
+ android:layout_marginTop="100dp"
+ android:layout_gravity="center"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingRight="4dp"
+ android:text="@string/Back"/>
+ <TextView
+ android:id="@+id/showErrorStatus"
+ android:layout_width="400dp"
+ android:layout_height="50dp"
+ android:capitalize="characters"
+ android:textColor="@android:color/holo_blue_light"
+ android:textSize="15dp" />
+ <TextView
+ android:id="@+id/devicePosition"
+ android:layout_width="400dp"
+ android:layout_height="65dp"
+ android:capitalize="characters"
+ android:textColor="@android:color/holo_blue_light"
+ android:layout_centerVertical="true"
+ android:textSize="15dp" />
+ <TextView
+ android:id="@+id/satellitePosition"
+ android:layout_width="400dp"
+ android:layout_height="65dp"
+ android:capitalize="characters"
+ android:textColor="@android:color/holo_blue_light"
+ android:layout_centerVertical="true"
+ android:textSize="15dp" />
+ <TextView
+ android:id="@+id/messageStatus"
+ android:layout_width="400dp"
+ android:layout_height="65dp"
+ android:capitalize="characters"
+ android:textColor="@android:color/holo_blue_light"
+ android:layout_centerVertical="true"
+ android:textSize="15dp" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml b/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
index 8585102..f2c1f57 100644
--- a/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
+++ b/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
@@ -19,7 +19,8 @@
<string name="SatelliteControl">SatelliteControl APIs</string>
<string name="Datagram">Datagram APIs</string>
<string name="Provisioning">Provisioning APIs</string>
- <string name="SatelliteModemState">SatelliteModemState APIs</string>
+ <string name="MultipleSendReceive">Test multiple poll and send</string>
+ <string name="SendReceive">Send and Receive datagrams</string>
<string name="enableSatellite">enableSatellite</string>
<string name="disableSatellite">disableSatellite</string>
@@ -53,5 +54,8 @@
<string name="multipleSendSatelliteDatagram">multipleSendSatelliteDatagram</string>
<string name="multipleSendReceiveSatelliteDatagram">multipleSendReceiveSatelliteDatagram</string>
+ <string name="sendMessage">sendMessage</string>
+ <string name="receiveMessage">receiveMessage</string>
+
<string name="Back">Back</string>
</resources>
diff --git a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SatelliteControl.java b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SatelliteControl.java
index 14f3b6b..1ab9f7c 100644
--- a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SatelliteControl.java
+++ b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SatelliteControl.java
@@ -22,7 +22,7 @@
import android.os.OutcomeReceiver;
import android.telephony.satellite.SatelliteCapabilities;
import android.telephony.satellite.SatelliteManager;
-import android.util.Log;
+import android.telephony.satellite.stub.SatelliteError;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
@@ -37,7 +37,7 @@
*/
public class SatelliteControl extends Activity {
- private static final String TAG = "SatelliteControl";
+ private static final long TIMEOUT = 3000;
private SatelliteManager mSatelliteManager;
@@ -75,34 +75,38 @@
private void enableSatelliteApp(View view) {
LinkedBlockingQueue<Integer> error = new LinkedBlockingQueue<>(1);
mSatelliteManager.requestSatelliteEnabled(true, true, Runnable::run, error::offer);
+ TextView textView = findViewById(R.id.text_id);
try {
- Integer value = error.poll(1000, TimeUnit.MILLISECONDS);
- TextView textView = findViewById(R.id.text_id);
- if (value == 0) {
- textView.setText("Enable satellite is successful");
- } else {
- textView.setText("Status for requestSatelliteEnabled: "
+ Integer value = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
+ if (value == null) {
+ textView.setText("Timed out to enable the satellite");
+ } else if (value != SatelliteError.ERROR_NONE) {
+ textView.setText("Failed to enable the satellite, error ="
+ SatelliteErrorUtils.mapError(value));
+ } else {
+ textView.setText("Successfully enabled the satellite");
}
} catch (InterruptedException e) {
- Log.e(TAG, "exception caught =" + e);
+ textView.setText("Enable SatelliteService exception caught =" + e);
}
}
private void disableSatelliteApp(View view) {
LinkedBlockingQueue<Integer> error = new LinkedBlockingQueue<>(1);
mSatelliteManager.requestSatelliteEnabled(false, true, Runnable::run, error::offer);
+ TextView textView = findViewById(R.id.text_id);
try {
- Integer value = error.poll(1000, TimeUnit.MILLISECONDS);
- TextView textView = findViewById(R.id.text_id);
- if (value == 0) {
- textView.setText("Disable satellite is successful");
- } else {
- textView.setText("Status for requestSatelliteEnabled: "
+ Integer value = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
+ if (value == null) {
+ textView.setText("Timed out to disable the satellite");
+ } else if (value != SatelliteError.ERROR_NONE) {
+ textView.setText("Failed to disable the satellite, error ="
+ SatelliteErrorUtils.mapError(value));
+ } else {
+ textView.setText("Successfully disabled the satellite");
}
} catch (InterruptedException e) {
- Log.e(TAG, "exception caught =" + e);
+ textView.setText("Disable SatelliteService exception caught =" + e);
}
}
diff --git a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SatelliteTestApp.java b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SatelliteTestApp.java
index d98e8fb..ac1dcfb 100644
--- a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SatelliteTestApp.java
+++ b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SatelliteTestApp.java
@@ -37,7 +37,7 @@
public class SatelliteTestApp extends Activity {
private static final String TAG = "SatelliteTestApp";
- private static TestSatelliteService sSatelliteService;
+ public static TestSatelliteService sSatelliteService;
private final Object mSendDatagramLock = new Object();
private TestSatelliteServiceConnection mSatelliteServiceConn;
@@ -82,6 +82,13 @@
startActivity(intent);
}
});
+ findViewById(R.id.SendReceive).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(SatelliteTestApp.this, SendReceive.class);
+ startActivity(intent);
+ }
+ });
}
private final ILocalSatelliteListener mSatelliteListener =
diff --git a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SendReceive.java b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SendReceive.java
new file mode 100644
index 0000000..3bd3775
--- /dev/null
+++ b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/SendReceive.java
@@ -0,0 +1,283 @@
+/*
+ * Copyright (C) 2023 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.phone.testapps.satellitetestapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.CancellationSignal;
+import android.os.OutcomeReceiver;
+import android.telephony.satellite.PointingInfo;
+import android.telephony.satellite.SatelliteCapabilities;
+import android.telephony.satellite.SatelliteDatagram;
+import android.telephony.satellite.SatelliteDatagramCallback;
+import android.telephony.satellite.SatelliteManager;
+import android.telephony.satellite.SatelliteTransmissionUpdateCallback;
+import android.telephony.satellite.stub.SatelliteError;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+
+/**
+ * Activity related to Send and Receiving of message APIs for satellite.
+ */
+public class SendReceive extends Activity {
+
+ private static final String TAG = "SendReceive";
+
+ private SatelliteManager mSatelliteManager;
+ private SendReceive.SatelliteDatagramCallbackTestApp mCallback;
+
+ private PointingInfo mPointingInfo;
+ private String mMessageInput = "";
+ private String mMessageOutput = "";
+ private static final long TIMEOUT = 3000;
+
+ private EditText mEnterMessage;
+ private TextView mMessageStatusTextView;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mSatelliteManager = getSystemService(SatelliteManager.class);
+ mCallback = new SendReceive.SatelliteDatagramCallbackTestApp();
+
+ setContentView(R.layout.activity_SendReceive);
+ findViewById(R.id.sendMessage).setOnClickListener(this::sendStatusApp);
+ findViewById(R.id.receiveMessage).setOnClickListener(this::receiveStatusApp);
+ mEnterMessage = (EditText) findViewById(R.id.enterText);
+ mMessageStatusTextView = findViewById(R.id.messageStatus);
+ findViewById(R.id.Back).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ startActivity(new Intent(SendReceive.this, SatelliteTestApp.class));
+ }
+ });
+ }
+
+ protected class SatelliteDatagramCallbackTestApp implements SatelliteDatagramCallback {
+ @Override
+ public void onSatelliteDatagramReceived(long datagramId, SatelliteDatagram datagram,
+ int pendingCount, Consumer<Void> callback) {
+ Log.d(TAG, "onSatelliteDatagramReceived in TestApp: datagramId =" + datagramId
+ + ", datagram =" + datagram + ", pendingCount=" + pendingCount);
+ mMessageStatusTextView.setText("Last received satellite message is = "
+ + new String(datagram.getSatelliteDatagram()));
+ }
+ }
+
+ protected class SatelliteTransmissionUpdateCallbackTestApp implements
+ SatelliteTransmissionUpdateCallback {
+ @Override
+ public void onSatellitePositionChanged(PointingInfo pointingInfo) {
+ mPointingInfo = pointingInfo;
+ Log.d(TAG, "onSatellitePositionChanged in TestApp for sendReceive: pointingInfo = "
+ + mPointingInfo);
+ TextView satellitePositionTextView = findViewById(R.id.satellitePosition);
+ satellitePositionTextView.setText("Successfully received the satellite position : "
+ + mPointingInfo);
+ }
+
+ @Override
+ public void onSendDatagramStateChanged(int state, int sendPendingCount, int errorCode) {
+ Log.d(TAG, "onSendDatagramStateChanged in TestApp for sendReceive: state = "
+ + state + ", sendPendingCount =" + sendPendingCount + ", errorCode="
+ + errorCode);
+ }
+
+ @Override
+ public void onReceiveDatagramStateChanged(
+ int state, int receivePendingCount, int errorCode) {
+ Log.d(TAG, "onReceiveDatagramStateChanged in TestApp for sendReceive: state = "
+ + state + ", " + "receivePendingCount=" + receivePendingCount + ", errorCode="
+ + errorCode);
+ }
+ }
+
+ private void sendStatusApp(View view) {
+ LinkedBlockingQueue<Integer> error = new LinkedBlockingQueue<>(1);
+ mMessageInput = mEnterMessage.getText().toString();
+ mMessageOutput = mEnterMessage.getText().toString();
+ byte[] testProvisionData = mMessageInput.getBytes();
+ setupForTransferringDatagram(testProvisionData);
+
+ SatelliteDatagram datagram = new SatelliteDatagram(mMessageInput.getBytes());
+ //Sending Message
+ mSatelliteManager.sendSatelliteDatagram(SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE,
+ datagram, true, Runnable::run, error::offer);
+ TextView messageStatusTextView = findViewById(R.id.messageStatus);
+ try {
+ Integer value = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
+ if (value == null) {
+ messageStatusTextView.setText("Timed out to send the message");
+ } else if (value != SatelliteError.ERROR_NONE) {
+ messageStatusTextView.setText("Failed to send the message, error ="
+ + SatelliteErrorUtils.mapError(value));
+ } else {
+ messageStatusTextView.setText("Successfully sent the message = "
+ + mEnterMessage.getText().toString());
+ }
+ } catch (InterruptedException e) {
+ messageStatusTextView.setText("sendSatelliteDatagram exception caught = " + e);
+ }
+ }
+
+ private void receiveStatusApp(View view) {
+ LinkedBlockingQueue<Integer> resultListener = new LinkedBlockingQueue<>(1);
+ byte[] testProvisionData = mMessageOutput.getBytes();
+ setupForTransferringDatagram(testProvisionData);
+
+ int result = mSatelliteManager.registerForSatelliteDatagram(Runnable::run, mCallback);
+ TextView showErrorStatusTextView = findViewById(R.id.showErrorStatus);
+ if (result != SatelliteError.ERROR_NONE) {
+ showErrorStatusTextView.setText("Status for registerForSatelliteDatagram : "
+ + SatelliteErrorUtils.mapError(result));
+ }
+ if (SatelliteTestApp.getTestSatelliteService() != null) {
+ SatelliteTestApp.getTestSatelliteService().sendOnPendingDatagrams();
+ }
+ mSatelliteManager.requestSatelliteEnabled(true, true, Runnable::run, resultListener::offer);
+ try {
+ Integer value = resultListener.poll(TIMEOUT, TimeUnit.MILLISECONDS);
+ if (value == null) {
+ showErrorStatusTextView.setText("Timed out to enable the satellite");
+ } else if (value != SatelliteError.ERROR_NONE) {
+ showErrorStatusTextView.setText("Failed to enable satellite, error = "
+ + SatelliteErrorUtils.mapError(value));
+ return;
+ }
+ resultListener.clear();
+ } catch (InterruptedException e) {
+ showErrorStatusTextView.setText("Enable SatelliteService exception caught = " + e);
+ return;
+ }
+
+ mSatelliteManager.pollPendingSatelliteDatagrams(Runnable::run, resultListener::offer);
+ try {
+ Integer value = resultListener.poll(TIMEOUT, TimeUnit.MILLISECONDS);
+ if (value == null) {
+ mMessageStatusTextView.setText("Timed out to poll pending messages");
+ } else if (value != SatelliteError.ERROR_NONE) {
+ mMessageStatusTextView.setText("Failed to poll pending messages, error = "
+ + SatelliteErrorUtils.mapError(value));
+ } else {
+ mMessageStatusTextView.setText("Successfully polled pending messages");
+ }
+ } catch (InterruptedException e) {
+ mMessageStatusTextView.setText("pollPendingSatelliteDatagrams exception caught = " + e);
+ }
+ }
+
+ private void setupForTransferringDatagram(byte[] provisionData) {
+ TextView showErrorStatusTextView = findViewById(R.id.showErrorStatus);
+ CancellationSignal cancellationSignal = new CancellationSignal();
+ LinkedBlockingQueue<Integer> error = new LinkedBlockingQueue<>(1);
+
+ //Provisioning
+ mSatelliteManager.provisionSatelliteService("SATELLITE_TOKEN", provisionData,
+ cancellationSignal, Runnable::run, error::offer);
+ try {
+ Integer value = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
+ if (value == null) {
+ showErrorStatusTextView.setText("Timed out to provision the satellite");
+ } else if (value != SatelliteError.ERROR_NONE) {
+ showErrorStatusTextView.setText("Failed to provision satellite, error = "
+ + SatelliteErrorUtils.mapError(value));
+ return;
+ }
+ } catch (InterruptedException e) {
+ showErrorStatusTextView.setText("Provision SatelliteService exception caught = " + e);
+ return;
+ }
+ error.clear();
+
+ //Static position of device
+ final AtomicReference<SatelliteCapabilities> capabilities = new AtomicReference<>();
+ final AtomicReference<Integer> errorCode = new AtomicReference<>();
+ OutcomeReceiver<SatelliteCapabilities, SatelliteManager.SatelliteException> receiver =
+ new OutcomeReceiver<>() {
+ @Override
+ public void onResult(SatelliteCapabilities result) {
+ capabilities.set(result);
+ TextView devicePositionTextView = findViewById(R.id.devicePosition);
+ devicePositionTextView.setText("Successfully receive the device position : "
+ + capabilities.get().getAntennaPositionMap());
+ }
+
+ @Override
+ public void onError(SatelliteManager.SatelliteException exception) {
+ errorCode.set(exception.getErrorCode());
+ TextView devicePositionTextView = findViewById(R.id.devicePosition);
+ devicePositionTextView.setText("Unable to fetch device position error is : "
+ + SatelliteErrorUtils.mapError(errorCode.get()));
+ }
+ };
+ mSatelliteManager.requestSatelliteCapabilities(Runnable::run, receiver);
+
+ //Satellite Position
+ SatelliteTransmissionUpdateCallbackTestApp callback =
+ new SatelliteTransmissionUpdateCallbackTestApp();
+ mSatelliteManager.requestSatelliteEnabled(true, true, Runnable::run, error::offer);
+ try {
+ Integer value = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
+ if (value == null) {
+ showErrorStatusTextView.setText("Timed out to enable the satellite");
+ } else if (value != SatelliteError.ERROR_NONE) {
+ showErrorStatusTextView.setText("Failed to enable satellite, error = "
+ + SatelliteErrorUtils.mapError(value));
+ return;
+ }
+ } catch (InterruptedException e) {
+ showErrorStatusTextView.setText("Enable SatelliteService exception caught = " + e);
+ return;
+ }
+ error.clear();
+
+ mSatelliteManager.startSatelliteTransmissionUpdates(Runnable::run, error::offer, callback);
+ // Position update
+ android.telephony.satellite.stub.PointingInfo pointingInfo =
+ new android.telephony.satellite.stub.PointingInfo();
+ pointingInfo.satelliteAzimuth = 50.5f;
+ pointingInfo.satelliteElevation = 20.36f;
+ if (SatelliteTestApp.getTestSatelliteService() != null) {
+ SatelliteTestApp.getTestSatelliteService().sendOnSatellitePositionChanged(pointingInfo);
+ }
+ TextView satellitePositionTextView = findViewById(R.id.satellitePosition);
+ try {
+ Integer value = error.poll(TIMEOUT, TimeUnit.MILLISECONDS);
+ if (value == null) {
+ satellitePositionTextView.setText("Failed to register for satellite transmission"
+ + "updates");
+ } else if (value != SatelliteError.ERROR_NONE) {
+ satellitePositionTextView.setText("Failed to register for satellite transmission "
+ + "updates, error = " + SatelliteErrorUtils.mapError(value));
+ }
+ } catch (InterruptedException e) {
+ satellitePositionTextView.setText("startSatelliteTransmissionUpdates exception caught ="
+ + e);
+ }
+ //Device is aligned with the satellite for demo mode
+ mSatelliteManager.onDeviceAlignedWithSatellite(true);
+ }
+}