Merge "Implement dumpsys for CompanionDeviceManagerService.CompanionDeviceManagerImpl" into tm-dev

This commit is contained in:
Raphael Kim
2022-06-01 00:03:42 +00:00
committed by Android (Google) Code Review
4 changed files with 109 additions and 8 deletions

View File

@@ -29,6 +29,7 @@ import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.CollectionUtils;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -267,6 +268,21 @@ class AssociationStoreImpl implements AssociationStore {
}
}
/**
* Dumps current companion device association states.
*/
public void dump(@NonNull PrintWriter out) {
out.append("Companion Device Associations: ");
if (getAssociations().isEmpty()) {
out.append("<empty>\n");
} else {
out.append("\n");
for (AssociationInfo a : getAssociations()) {
out.append(" ").append(a.toString()).append('\n');
}
}
}
private void broadcastChange(@ChangeType int changeType, AssociationInfo association) {
synchronized (mListeners) {
for (OnChangeListener listener : mListeners) {

View File

@@ -33,6 +33,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.infra.PerUser;
import com.android.internal.util.CollectionUtils;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -234,6 +235,28 @@ class CompanionApplicationController {
primaryServiceConnector.postOnDeviceDisappeared(association);
}
void dump(@NonNull PrintWriter out) {
out.append("Companion Device Application Controller: \n");
synchronized (mBoundCompanionApplications) {
out.append(" Bound Companion Applications: ");
if (mBoundCompanionApplications.size() == 0) {
out.append("<empty>\n");
} else {
out.append("\n");
mBoundCompanionApplications.dump(out);
}
}
out.append(" Companion Applications Scheduled For Rebinding: ");
if (mScheduledForRebindingCompanionApplications.size() == 0) {
out.append("<empty>\n");
} else {
out.append("\n");
mScheduledForRebindingCompanionApplications.dump(out);
}
}
private void onPrimaryServiceBindingDied(@UserIdInt int userId, @NonNull String packageName) {
if (DEBUG) Log.i(TAG, "onPrimaryServiceBindingDied() u" + userId + "/" + packageName);
@@ -333,5 +356,23 @@ class CompanionApplicationController {
}
}
}
private void dump(@NonNull PrintWriter out) {
for (int i = 0; i < size(); i++) {
final int userId = keyAt(i);
final Map<String, T> forUser = get(userId);
if (forUser.isEmpty()) {
out.append(" u").append(String.valueOf(userId)).append(": <empty>\n");
}
for (Map.Entry<String, T> packageValue : forUser.entrySet()) {
final String packageName = packageValue.getKey();
final T value = packageValue.getValue();
out.append(" u").append(String.valueOf(userId)).append("\\")
.append(packageName).append(" -> ")
.append(value.toString()).append('\n');
}
}
}
}
}

View File

@@ -764,14 +764,9 @@ public class CompanionDeviceManagerService extends SystemService {
return;
}
// TODO(b/218615185): mAssociationStore.dump() instead
out.append("Companion Device Associations:").append('\n');
for (AssociationInfo a : mAssociationStore.getAssociations()) {
out.append(" ").append(a.toString()).append('\n');
}
// TODO(b/218615185): mDevicePresenceMonitor.dump()
// TODO(b/218615185): mCompanionAppController.dump()
mAssociationStore.dump(out);
mDevicePresenceMonitor.dump(out);
mCompanionAppController.dump(out);
}
}

View File

@@ -33,6 +33,7 @@ import android.util.Log;
import com.android.server.companion.AssociationStore;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
@@ -293,6 +294,54 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange
throw new SecurityException("Caller is neither Shell nor Root");
}
/**
* Dumps system information about devices that are marked as "present".
*/
public void dump(@NonNull PrintWriter out) {
out.append("Companion Device Present: ");
if (mConnectedBtDevices.isEmpty()
&& mNearbyBleDevices.isEmpty()
&& mReportedSelfManagedDevices.isEmpty()) {
out.append("<empty>\n");
return;
} else {
out.append("\n");
}
out.append(" Connected Bluetooth Devices: ");
if (mConnectedBtDevices.isEmpty()) {
out.append("<empty>\n");
} else {
out.append("\n");
for (int associationId : mConnectedBtDevices) {
AssociationInfo a = mAssociationStore.getAssociationById(associationId);
out.append(" ").append(a.toShortString()).append('\n');
}
}
out.append(" Nearby BLE Devices: ");
if (mNearbyBleDevices.isEmpty()) {
out.append("<empty>\n");
} else {
out.append("\n");
for (int associationId : mNearbyBleDevices) {
AssociationInfo a = mAssociationStore.getAssociationById(associationId);
out.append(" ").append(a.toShortString()).append('\n');
}
}
out.append(" Self-Reported Devices: ");
if (mReportedSelfManagedDevices.isEmpty()) {
out.append("<empty>\n");
} else {
out.append("\n");
for (int associationId : mReportedSelfManagedDevices) {
AssociationInfo a = mAssociationStore.getAssociationById(associationId);
out.append(" ").append(a.toShortString()).append('\n');
}
}
}
private class SimulatedDevicePresenceSchedulerHelper extends Handler {
SimulatedDevicePresenceSchedulerHelper() {
super(Looper.getMainLooper());