Merge "[CDM] Add shell cmd to create a dummy transport" into udc-dev

This commit is contained in:
Treehugger Robot
2023-04-13 19:41:20 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 7 deletions

View File

@@ -899,12 +899,9 @@ public class CompanionDeviceManagerService extends SystemService {
public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
String[] args, ShellCallback callback, ResultReceiver resultReceiver)
throws RemoteException {
enforceCallerCanManageCompanionDevice(getContext(), "onShellCommand");
final CompanionDeviceShellCommand cmd = new CompanionDeviceShellCommand(
CompanionDeviceManagerService.this,
mAssociationStore,
mDevicePresenceMonitor);
cmd.exec(this, in, out, err, args, callback, resultReceiver);
new CompanionDeviceShellCommand(CompanionDeviceManagerService.this, mAssociationStore,
mDevicePresenceMonitor, mTransportManager)
.exec(this, in, out, err, args, callback, resultReceiver);
}
@Override

View File

@@ -22,6 +22,7 @@ import android.os.Binder;
import android.os.ShellCommand;
import com.android.server.companion.presence.CompanionDevicePresenceMonitor;
import com.android.server.companion.transport.CompanionTransportManager;
import java.io.PrintWriter;
import java.util.List;
@@ -32,13 +33,16 @@ class CompanionDeviceShellCommand extends ShellCommand {
private final CompanionDeviceManagerService mService;
private final AssociationStore mAssociationStore;
private final CompanionDevicePresenceMonitor mDevicePresenceMonitor;
private final CompanionTransportManager mTransportManager;
CompanionDeviceShellCommand(CompanionDeviceManagerService service,
AssociationStore associationStore,
CompanionDevicePresenceMonitor devicePresenceMonitor) {
CompanionDevicePresenceMonitor devicePresenceMonitor,
CompanionTransportManager transportManager) {
mService = service;
mAssociationStore = associationStore;
mDevicePresenceMonitor = devicePresenceMonitor;
mTransportManager = transportManager;
}
@Override
@@ -107,6 +111,12 @@ class CompanionDeviceShellCommand extends ShellCommand {
}
break;
case "create-dummy-transport":
// This command creates a RawTransport in order to test Transport listeners
associationId = getNextIntArgRequired();
mTransportManager.createDummyTransport(associationId);
break;
default:
return handleDefaultCommands(cmd);
}
@@ -165,5 +175,8 @@ class CompanionDeviceShellCommand extends ShellCommand {
pw.println(" for a long time (90 days or as configured via ");
pw.println(" \"debug.cdm.cdmservice.cleanup_time_window\" system property). ");
pw.println(" USE FOR DEBUGGING AND/OR TESTING PURPOSES ONLY.");
pw.println(" create-dummy-transport <ASSOCIATION_ID>");
pw.println(" Create a dummy RawTransport for testing puspose only");
}
}

View File

@@ -44,6 +44,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.server.LocalServices;
import com.android.server.companion.AssociationStore;
import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
@@ -350,6 +351,21 @@ public class CompanionTransportManager {
this.mSecureTransportEnabled = enabled;
}
/**
* For testing purpose only.
*
* Create a dummy RawTransport and notify onTransportChanged listeners.
*/
public void createDummyTransport(int associationId) {
synchronized (mTransports) {
FileDescriptor fd = new FileDescriptor();
ParcelFileDescriptor pfd = new ParcelFileDescriptor(fd);
Transport transport = new RawTransport(associationId, pfd, mContext);
mTransports.put(associationId, transport);
notifyOnTransportsChanged();
}
}
private boolean isSecureTransportEnabled() {
boolean enabled = !Build.IS_DEBUGGABLE || mSecureTransportEnabled;