Merge "Handle null callbacks, add missing breaks."
This commit is contained in:
@@ -1161,17 +1161,17 @@ public final class CompanionDeviceManager {
|
||||
public void stop() {
|
||||
mStopped = true;
|
||||
|
||||
IoUtils.closeQuietly(mRemoteIn);
|
||||
IoUtils.closeQuietly(mRemoteOut);
|
||||
IoUtils.closeQuietly(mLocalIn);
|
||||
IoUtils.closeQuietly(mLocalOut);
|
||||
|
||||
try {
|
||||
mService.detachSystemDataTransport(mContext.getPackageName(),
|
||||
mContext.getUserId(), mAssociationId);
|
||||
} catch (RemoteException e) {
|
||||
Log.w(LOG_TAG, "Failed to detach transport", e);
|
||||
}
|
||||
|
||||
IoUtils.closeQuietly(mRemoteIn);
|
||||
IoUtils.closeQuietly(mRemoteOut);
|
||||
IoUtils.closeQuietly(mLocalIn);
|
||||
IoUtils.closeQuietly(mLocalOut);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ import static android.content.ComponentName.createRelative;
|
||||
import static com.android.server.companion.Utils.prepareForIpc;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.PendingIntent;
|
||||
import android.companion.AssociationInfo;
|
||||
@@ -191,20 +192,9 @@ public class SystemDataTransferProcessor {
|
||||
// TODO: refactor to work with streams of data
|
||||
mPermissionControllerManager.getRuntimePermissionBackup(UserHandle.of(userId),
|
||||
mExecutor, backup -> {
|
||||
Future<?> result = mTransportManager
|
||||
Future<?> future = mTransportManager
|
||||
.requestPermissionRestore(associationId, backup);
|
||||
try {
|
||||
result.get(15, TimeUnit.SECONDS);
|
||||
try {
|
||||
callback.onResult();
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
callback.onError(e.getMessage());
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
translateFutureToCallback(future, callback);
|
||||
});
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(callingIdentityToken);
|
||||
@@ -225,6 +215,26 @@ public class SystemDataTransferProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private static void translateFutureToCallback(@NonNull Future<?> future,
|
||||
@Nullable ISystemDataTransferCallback callback) {
|
||||
try {
|
||||
future.get(15, TimeUnit.SECONDS);
|
||||
try {
|
||||
if (callback != null) {
|
||||
callback.onResult();
|
||||
}
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (callback != null) {
|
||||
callback.onError(e.getMessage());
|
||||
}
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final ResultReceiver mOnSystemDataTransferRequestConfirmationReceiver =
|
||||
new ResultReceiver(Handler.getMain()) {
|
||||
@Override
|
||||
|
||||
@@ -260,7 +260,7 @@ public class CompanionTransportManager {
|
||||
} else if (isResponse(message)) {
|
||||
processResponse(message, sequence, data);
|
||||
} else {
|
||||
Slog.w(TAG, "Unknown message " + Integer.toHexString(message));
|
||||
Slog.w(TAG, "Unknown message 0x" + Integer.toHexString(message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ public class CompanionTransportManager {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Slog.w(TAG, "Unknown request " + Integer.toHexString(message));
|
||||
Slog.w(TAG, "Unknown request 0x" + Integer.toHexString(message));
|
||||
sendMessage(MESSAGE_RESPONSE_FAILURE, sequence, EmptyArray.BYTE);
|
||||
break;
|
||||
}
|
||||
@@ -308,12 +308,14 @@ public class CompanionTransportManager {
|
||||
switch (message) {
|
||||
case MESSAGE_RESPONSE_SUCCESS: {
|
||||
future.complete(data);
|
||||
break;
|
||||
}
|
||||
case MESSAGE_RESPONSE_FAILURE: {
|
||||
future.completeExceptionally(new RuntimeException("Remote failure"));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Slog.w(TAG, "Ignoring unknown response " + Integer.toHexString(message));
|
||||
Slog.w(TAG, "Ignoring unknown response 0x" + Integer.toHexString(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user