Skip to content
Snippets Groups Projects
Commit f1e7f12d authored by David Lin's avatar David Lin Committed by Android (Google) Code Review
Browse files

Merge "Add requestSessionStats API." into 24D1-dev

parents da945139 0f1e6a29
No related branches found
No related tags found
No related merge requests found
......@@ -191,6 +191,14 @@ public final class SatelliteManager {
public static final String KEY_SATELLITE_CAPABILITIES = "satellite_capabilities";
/**
* 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)}.
......@@ -2493,6 +2501,65 @@ public final class SatelliteManager {
}
}
/**
* 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
......
/*
* 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
/*
* 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);
}
}
}
......@@ -3384,4 +3384,14 @@ interface ITelephony {
* @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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment