mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Mi Watch Lite: authenticate via use XiaomiAuthService, handle subtype 5 send user id reply
This makes device info and battery status work since AuthService calls phase2Initialize()
This commit is contained in:
parent
f3d6be2f96
commit
7de94432d0
@ -90,6 +90,22 @@ public class XiaomiAuthService extends AbstractXiaomiService {
|
||||
);
|
||||
}
|
||||
|
||||
protected void startClearTextHandshake(final TransactionBuilder builder, String userId) {
|
||||
builder.add(new SetDeviceStateAction(getSupport().getDevice(), GBDevice.State.AUTHENTICATING, getSupport().getContext()));
|
||||
|
||||
final XiaomiProto.Auth auth = XiaomiProto.Auth.newBuilder()
|
||||
.setUserId(userId)
|
||||
.build();
|
||||
|
||||
final XiaomiProto.Command command = XiaomiProto.Command.newBuilder()
|
||||
.setType(XiaomiAuthService.COMMAND_TYPE)
|
||||
.setSubtype(XiaomiAuthService.CMD_SEND_USERID)
|
||||
.setAuth(auth)
|
||||
.build();
|
||||
|
||||
getSupport().sendCommand(builder, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(final XiaomiProto.Command cmd) {
|
||||
if (cmd.getType() != COMMAND_TYPE) {
|
||||
@ -117,16 +133,20 @@ public class XiaomiAuthService extends AbstractXiaomiService {
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_AUTH: {
|
||||
LOG.info("Authenticated!");
|
||||
case CMD_AUTH:
|
||||
case CMD_SEND_USERID: {
|
||||
if (cmd.getSubtype() == CMD_AUTH || cmd.getAuth().getStatus() == 1) {
|
||||
LOG.info("Authenticated!");
|
||||
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("phase 2 initialize");
|
||||
builder.add(new SetDeviceStateAction(getSupport().getDevice(), GBDevice.State.INITIALIZED, getSupport().getContext()));
|
||||
getSupport().phase2Initialize(builder);
|
||||
builder.queue(getSupport().getQueue());
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("phase 2 initialize");
|
||||
builder.add(new SetDeviceStateAction(getSupport().getDevice(), GBDevice.State.INITIALIZED, getSupport().getContext()));
|
||||
getSupport().phase2Initialize(builder);
|
||||
builder.queue(getSupport().getQueue());
|
||||
} else {
|
||||
LOG.warn("could not authenticate");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
LOG.warn("Unknown auth payload subtype {}", cmd.getSubtype());
|
||||
}
|
||||
|
@ -78,25 +78,12 @@ public class XiaomiPlaintextSupport extends XiaomiSupport {
|
||||
getDevice().setFirmwareVersion("...");
|
||||
//getDevice().setFirmwareVersion2("...");
|
||||
|
||||
enableNotifications(builder, true);
|
||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
||||
enableNotifications(builder, true);
|
||||
builder.requestMtu(247);
|
||||
|
||||
String userId = getUserId(gbDevice);
|
||||
|
||||
final XiaomiProto.Auth auth = XiaomiProto.Auth.newBuilder()
|
||||
.setUserId(userId)
|
||||
.build();
|
||||
|
||||
final XiaomiProto.Command command = XiaomiProto.Command.newBuilder()
|
||||
.setType(XiaomiAuthService.COMMAND_TYPE)
|
||||
.setSubtype(XiaomiAuthService.CMD_SEND_USERID)
|
||||
.setAuth(auth)
|
||||
.build();
|
||||
|
||||
sendCommand(builder, command);
|
||||
|
||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||
|
||||
authService.startClearTextHandshake(builder, userId);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ message Command {
|
||||
|
||||
message Auth {
|
||||
optional string userId = 7;
|
||||
optional uint32 status = 8;
|
||||
// 1, 26
|
||||
optional PhoneNonce phoneNonce = 30;
|
||||
optional WatchNonce watchNonce = 31;
|
||||
|
Loading…
Reference in New Issue
Block a user