mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 16:15:55 +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
|
@Override
|
||||||
public void handleCommand(final XiaomiProto.Command cmd) {
|
public void handleCommand(final XiaomiProto.Command cmd) {
|
||||||
if (cmd.getType() != COMMAND_TYPE) {
|
if (cmd.getType() != COMMAND_TYPE) {
|
||||||
@ -117,16 +133,20 @@ public class XiaomiAuthService extends AbstractXiaomiService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CMD_AUTH: {
|
case CMD_AUTH:
|
||||||
LOG.info("Authenticated!");
|
case CMD_SEND_USERID: {
|
||||||
|
if (cmd.getSubtype() == CMD_AUTH || cmd.getAuth().getStatus() == 1) {
|
||||||
|
LOG.info("Authenticated!");
|
||||||
|
|
||||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("phase 2 initialize");
|
final TransactionBuilder builder = getSupport().createTransactionBuilder("phase 2 initialize");
|
||||||
builder.add(new SetDeviceStateAction(getSupport().getDevice(), GBDevice.State.INITIALIZED, getSupport().getContext()));
|
builder.add(new SetDeviceStateAction(getSupport().getDevice(), GBDevice.State.INITIALIZED, getSupport().getContext()));
|
||||||
getSupport().phase2Initialize(builder);
|
getSupport().phase2Initialize(builder);
|
||||||
builder.queue(getSupport().getQueue());
|
builder.queue(getSupport().getQueue());
|
||||||
|
} else {
|
||||||
|
LOG.warn("could not authenticate");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LOG.warn("Unknown auth payload subtype {}", cmd.getSubtype());
|
LOG.warn("Unknown auth payload subtype {}", cmd.getSubtype());
|
||||||
}
|
}
|
||||||
|
@ -78,25 +78,12 @@ public class XiaomiPlaintextSupport extends XiaomiSupport {
|
|||||||
getDevice().setFirmwareVersion("...");
|
getDevice().setFirmwareVersion("...");
|
||||||
//getDevice().setFirmwareVersion2("...");
|
//getDevice().setFirmwareVersion2("...");
|
||||||
|
|
||||||
enableNotifications(builder, true);
|
|
||||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
||||||
|
enableNotifications(builder, true);
|
||||||
builder.requestMtu(247);
|
builder.requestMtu(247);
|
||||||
|
|
||||||
String userId = getUserId(gbDevice);
|
String userId = getUserId(gbDevice);
|
||||||
|
authService.startClearTextHandshake(builder, userId);
|
||||||
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()));
|
|
||||||
|
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ message Command {
|
|||||||
|
|
||||||
message Auth {
|
message Auth {
|
||||||
optional string userId = 7;
|
optional string userId = 7;
|
||||||
|
optional uint32 status = 8;
|
||||||
// 1, 26
|
// 1, 26
|
||||||
optional PhoneNonce phoneNonce = 30;
|
optional PhoneNonce phoneNonce = 30;
|
||||||
optional WatchNonce watchNonce = 31;
|
optional WatchNonce watchNonce = 31;
|
||||||
|
Loading…
Reference in New Issue
Block a user