Merge "Add requestSessionStats API." into 24D1-dev am: f1e7f12da5
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/27673400
Change-Id: Ia9ab3de91c9c6d4038ef366d667acef788a78348
Signed-off-by: Automerger Merge Worker <[email protected]>
diff --git a/telephony/java/android/telephony/satellite/SatelliteManager.java b/telephony/java/android/telephony/satellite/SatelliteManager.java
index 47f53f3..2a359cd5 100644
--- a/telephony/java/android/telephony/satellite/SatelliteManager.java
+++ b/telephony/java/android/telephony/satellite/SatelliteManager.java
@@ -193,6 +193,14 @@
/**
* Bundle key to get the response from
+ * {@link #requestSessionStats(Executor, OutcomeReceiver)}.
+ * @hide
+ */
+
+ public static final String KEY_SESSION_STATS = "session_stats";
+
+ /**
+ * Bundle key to get the response from
* {@link #requestIsProvisioned(Executor, OutcomeReceiver)}.
* @hide
*/
@@ -2493,6 +2501,65 @@
}
}
+ /**
+ * Request to get the {@link SatelliteSessionStats} of the satellite service.
+ *
+ * @param executor The executor on which the callback will be called.
+ * @param callback The callback object to which the result will be delivered.
+ * If the request is successful, {@link OutcomeReceiver#onResult(Object)}
+ * will return the {@link SatelliteSessionStats} of the satellite service.
+ * If the request is not successful, {@link OutcomeReceiver#onError(Throwable)}
+ * will return a {@link SatelliteException} with the {@link SatelliteResult}.
+ *
+ * @throws SecurityException if the caller doesn't have required permission.
+ * @hide
+ */
+ @RequiresPermission(allOf = {Manifest.permission.PACKAGE_USAGE_STATS,
+ Manifest.permission.MODIFY_PHONE_STATE})
+ @FlaggedApi(Flags.FLAG_OEM_ENABLED_SATELLITE_FLAG)
+ public void requestSessionStats(@NonNull @CallbackExecutor Executor executor,
+ @NonNull OutcomeReceiver<SatelliteSessionStats, SatelliteException> callback) {
+ Objects.requireNonNull(executor);
+ Objects.requireNonNull(callback);
+
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null) {
+ ResultReceiver receiver = new ResultReceiver(null) {
+ @Override
+ protected void onReceiveResult(int resultCode, Bundle resultData) {
+ if (resultCode == SATELLITE_RESULT_SUCCESS) {
+ if (resultData.containsKey(KEY_SESSION_STATS)) {
+ SatelliteSessionStats stats =
+ resultData.getParcelable(KEY_SESSION_STATS,
+ SatelliteSessionStats.class);
+ executor.execute(() -> Binder.withCleanCallingIdentity(() ->
+ callback.onResult(stats)));
+ } else {
+ loge("KEY_SESSION_STATS does not exist.");
+ executor.execute(() -> Binder.withCleanCallingIdentity(() ->
+ callback.onError(new SatelliteException(
+ SATELLITE_RESULT_REQUEST_FAILED))));
+ }
+ } else {
+ executor.execute(() -> Binder.withCleanCallingIdentity(() ->
+ callback.onError(new SatelliteException(resultCode))));
+ }
+ }
+ };
+ telephony.requestSatelliteSessionStats(mSubId, receiver);
+ } else {
+ loge("requestSessionStats() invalid telephony");
+ executor.execute(() -> Binder.withCleanCallingIdentity(() -> callback.onError(
+ new SatelliteException(SATELLITE_RESULT_ILLEGAL_STATE))));
+ }
+ } catch (RemoteException ex) {
+ loge("requestSessionStats() RemoteException: " + ex);
+ executor.execute(() -> Binder.withCleanCallingIdentity(() -> callback.onError(
+ new SatelliteException(SATELLITE_RESULT_ILLEGAL_STATE))));
+ }
+ }
+
@Nullable
private static ITelephony getITelephony() {
ITelephony binder = ITelephony.Stub.asInterface(TelephonyFrameworkInitializer
diff --git a/telephony/java/android/telephony/satellite/SatelliteSessionStats.aidl b/telephony/java/android/telephony/satellite/SatelliteSessionStats.aidl
new file mode 100644
index 0000000..4175125
--- /dev/null
+++ b/telephony/java/android/telephony/satellite/SatelliteSessionStats.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2024, 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.telephony.satellite;
+
+ parcelable SatelliteSessionStats;
\ No newline at end of file
diff --git a/telephony/java/android/telephony/satellite/SatelliteSessionStats.java b/telephony/java/android/telephony/satellite/SatelliteSessionStats.java
new file mode 100644
index 0000000..aabb058
--- /dev/null
+++ b/telephony/java/android/telephony/satellite/SatelliteSessionStats.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2024 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.telephony.satellite;
+
+import android.annotation.NonNull;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Objects;
+
+/**
+ * SatelliteSessionStats is used to represent the usage stats of the satellite service.
+ * @hide
+ */
+public class SatelliteSessionStats implements Parcelable {
+ private int mCountOfSuccessfulUserMessages;
+ private int mCountOfUnsuccessfulUserMessages;
+ private int mCountOfTimedOutUserMessagesWaitingForConnection;
+ private int mCountOfTimedOutUserMessagesWaitingForAck;
+ private int mCountOfUserMessagesInQueueToBeSent;
+
+ /**
+ * SatelliteSessionStats constructor
+ * @param builder Builder to create SatelliteSessionStats object/
+ */
+ public SatelliteSessionStats(@NonNull Builder builder) {
+ mCountOfSuccessfulUserMessages = builder.mCountOfSuccessfulUserMessages;
+ mCountOfUnsuccessfulUserMessages = builder.mCountOfUnsuccessfulUserMessages;
+ mCountOfTimedOutUserMessagesWaitingForConnection =
+ builder.mCountOfTimedOutUserMessagesWaitingForConnection;
+ mCountOfTimedOutUserMessagesWaitingForAck =
+ builder.mCountOfTimedOutUserMessagesWaitingForAck;
+ mCountOfUserMessagesInQueueToBeSent = builder.mCountOfUserMessagesInQueueToBeSent;
+ }
+
+ private SatelliteSessionStats(Parcel in) {
+ readFromParcel(in);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel out, int flags) {
+ out.writeInt(mCountOfSuccessfulUserMessages);
+ out.writeInt(mCountOfUnsuccessfulUserMessages);
+ out.writeInt(mCountOfTimedOutUserMessagesWaitingForConnection);
+ out.writeInt(mCountOfTimedOutUserMessagesWaitingForAck);
+ out.writeInt(mCountOfUserMessagesInQueueToBeSent);
+ }
+
+ @NonNull
+ public static final Creator<SatelliteSessionStats> CREATOR = new Parcelable.Creator<>() {
+
+ @Override
+ public SatelliteSessionStats createFromParcel(Parcel in) {
+ return new SatelliteSessionStats(in);
+ }
+
+ @Override
+ public SatelliteSessionStats[] newArray(int size) {
+ return new SatelliteSessionStats[size];
+ }
+ };
+
+ @Override
+ @NonNull
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("countOfSuccessfulUserMessages:");
+ sb.append(mCountOfSuccessfulUserMessages);
+ sb.append(",");
+
+ sb.append("countOfUnsuccessfulUserMessages:");
+ sb.append(mCountOfUnsuccessfulUserMessages);
+ sb.append(",");
+
+ sb.append("countOfTimedOutUserMessagesWaitingForConnection:");
+ sb.append(mCountOfTimedOutUserMessagesWaitingForConnection);
+ sb.append(",");
+
+ sb.append("countOfTimedOutUserMessagesWaitingForAck:");
+ sb.append(mCountOfTimedOutUserMessagesWaitingForAck);
+ sb.append(",");
+
+ sb.append("countOfUserMessagesInQueueToBeSent:");
+ sb.append(mCountOfUserMessagesInQueueToBeSent);
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ SatelliteSessionStats that = (SatelliteSessionStats) o;
+ return mCountOfSuccessfulUserMessages == that.mCountOfSuccessfulUserMessages
+ && mCountOfUnsuccessfulUserMessages == that.mCountOfUnsuccessfulUserMessages
+ && mCountOfTimedOutUserMessagesWaitingForConnection
+ == that.mCountOfTimedOutUserMessagesWaitingForConnection
+ && mCountOfTimedOutUserMessagesWaitingForAck
+ == that.mCountOfTimedOutUserMessagesWaitingForAck
+ && mCountOfUserMessagesInQueueToBeSent
+ == that.mCountOfUserMessagesInQueueToBeSent;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mCountOfSuccessfulUserMessages, mCountOfUnsuccessfulUserMessages,
+ mCountOfTimedOutUserMessagesWaitingForConnection,
+ mCountOfTimedOutUserMessagesWaitingForAck,
+ mCountOfUserMessagesInQueueToBeSent);
+ }
+
+ public int getCountOfSuccessfulUserMessages() {
+ return mCountOfSuccessfulUserMessages;
+ }
+
+ public int getCountOfUnsuccessfulUserMessages() {
+ return mCountOfUnsuccessfulUserMessages;
+ }
+
+ public int getCountOfTimedOutUserMessagesWaitingForConnection() {
+ return mCountOfTimedOutUserMessagesWaitingForConnection;
+ }
+
+ public int getCountOfTimedOutUserMessagesWaitingForAck() {
+ return mCountOfTimedOutUserMessagesWaitingForAck;
+ }
+
+ public int getCountOfUserMessagesInQueueToBeSent() {
+ return mCountOfUserMessagesInQueueToBeSent;
+ }
+
+ private void readFromParcel(Parcel in) {
+ mCountOfSuccessfulUserMessages = in.readInt();
+ mCountOfUnsuccessfulUserMessages = in.readInt();
+ mCountOfTimedOutUserMessagesWaitingForConnection = in.readInt();
+ mCountOfTimedOutUserMessagesWaitingForAck = in.readInt();
+ mCountOfUserMessagesInQueueToBeSent = in.readInt();
+ }
+
+ /**
+ * A builder class to create {@link SatelliteSessionStats} data object.
+ */
+ public static final class Builder {
+ private int mCountOfSuccessfulUserMessages;
+ private int mCountOfUnsuccessfulUserMessages;
+ private int mCountOfTimedOutUserMessagesWaitingForConnection;
+ private int mCountOfTimedOutUserMessagesWaitingForAck;
+ private int mCountOfUserMessagesInQueueToBeSent;
+
+ /**
+ * Sets countOfSuccessfulUserMessages value of {@link SatelliteSessionStats}
+ * and then returns the Builder class.
+ */
+ @NonNull
+ public Builder setCountOfSuccessfulUserMessages(int count) {
+ mCountOfSuccessfulUserMessages = count;
+ return this;
+ }
+
+ /**
+ * Sets countOfUnsuccessfulUserMessages value of {@link SatelliteSessionStats}
+ * and then returns the Builder class.
+ */
+ @NonNull
+ public Builder setCountOfUnsuccessfulUserMessages(int count) {
+ mCountOfUnsuccessfulUserMessages = count;
+ return this;
+ }
+
+ /**
+ * Sets countOfTimedOutUserMessagesWaitingForConnection value of
+ * {@link SatelliteSessionStats} and then returns the Builder class.
+ */
+ @NonNull
+ public Builder setCountOfTimedOutUserMessagesWaitingForConnection(int count) {
+ mCountOfTimedOutUserMessagesWaitingForConnection = count;
+ return this;
+ }
+
+ /**
+ * Sets countOfTimedOutUserMessagesWaitingForAck value of {@link SatelliteSessionStats}
+ * and then returns the Builder class.
+ */
+ @NonNull
+ public Builder setCountOfTimedOutUserMessagesWaitingForAck(int count) {
+ mCountOfTimedOutUserMessagesWaitingForAck = count;
+ return this;
+ }
+
+ /**
+ * Sets countOfUserMessagesInQueueToBeSent value of {@link SatelliteSessionStats}
+ * and then returns the Builder class.
+ */
+ @NonNull
+ public Builder setCountOfUserMessagesInQueueToBeSent(int count) {
+ mCountOfUserMessagesInQueueToBeSent = count;
+ return this;
+ }
+
+ /** Returns SatelliteSessionStats object. */
+ @NonNull
+ public SatelliteSessionStats build() {
+ return new SatelliteSessionStats(this);
+ }
+ }
+}
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 9af73ea..9b01b71 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -3390,4 +3390,14 @@
* @return {@code true} if the setting is successful, {@code false} otherwise.
*/
boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(in String state);
+
+ /**
+ * Request to get the session stats of the satellite service.
+ *
+ * @param subId The subId of the subscription to get the session stats for.
+ * @param receiver Result receiver to get the error code of the request and the requested
+ * session stats of the satellite service.
+ * @hide
+ */
+ void requestSatelliteSessionStats(int subId, in ResultReceiver receiver);
}