Device | Serial Number | State | Thing | Family | Type | Customer Id | |
---|---|---|---|---|---|---|---|
"); - html.append(HtmlEscape.escapeHtml4(nullReplacement(device.accountName))); - html.append(" | "); - html.append(HtmlEscape.escapeHtml4(nullReplacement(device.serialNumber))); + for (DeviceTO device : this.accountHandler.getLastKnownDevices()) { + html.append(" | ||||||
").append(nullReplacement(device.accountName)); + html.append(" | ").append(nullReplacement(device.serialNumber)); + html.append(" | ").append(device.online ? "Online" : "Offline"); html.append(" | "); - html.append(HtmlEscape.escapeHtml4(device.online ? "Online" : "Offline")); - html.append(" | "); - Thing accountHandler = this.accountHandler.findThingBySerialNumber(device.serialNumber); - if (accountHandler != null) { + Thing thing = this.accountHandler.findThingBySerialNumber(device.serialNumber); + if (thing != null) { html.append("") - .append(HtmlEscape.escapeHtml4(accountHandler.getLabel())).append(""); + .append(escapeHtml4(thing.getLabel())).append(""); } else { - html.append("") - .append(HtmlEscape.escapeHtml4("Not defined")).append(""); + html.append("not defined"); } html.append(" | "); - html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceFamily))); + html.append(nullReplacement(device.deviceFamily)); html.append(" | "); String deviceTypeId = nullReplacement(device.deviceType); - html.append(HtmlEscape.escapeHtml4(DEVICE_TYPES.getOrDefault(deviceTypeId, deviceTypeId))); + html.append(DEVICE_TYPES.getOrDefault(deviceTypeId, deviceTypeId)); html.append(" | "); - html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceOwnerCustomerId))); + html.append(nullReplacement(device.deviceOwnerCustomerId)); html.append(" | "); html.append("
Name |
---|
").append(HtmlEscape.escapeHtml4(capability)).append(" |
").append(escapeHtml4(capability)).append(" |
Name | Value |
---|---|
"); - html.append(HtmlEscape.escapeHtml4(displayName)); - html.append(" | "); - html.append(HtmlEscape.escapeHtml4(providerId)); - html.append(" |
").append(escapeHtml4(displayName)).append(" | ") + .append(escapeHtml4(providerId)).append(" |
Name | Value |
---|---|
"); - html.append(HtmlEscape.escapeHtml4(notificationSound.displayName)); + html.append(escapeHtml4(notificationSound.displayName)); html.append(" | "); - html.append(HtmlEscape.escapeHtml4(providerSoundId)); + html.append(escapeHtml4(providerSoundId)); html.append(" |
Name | Value |
---|---|
"); - html.append(HtmlEscape.escapeHtml4(nullReplacement(pairedDevice.friendlyName))); - html.append(" | "); - html.append(HtmlEscape.escapeHtml4(nullReplacement(pairedDevice.address))); - html.append(" |
Name | Value |
---|---|
") + .append(nullReplacement(pairedDevice.friendlyName)).append(" | ") + .append(nullReplacement(pairedDevice.address)).append(" |
true
when the session tokens have been renewed, false
otherwise
* @throws ConnectionException when an error occurred
@@ -468,7 +405,7 @@ public boolean checkRenewSession() throws ConnectionException {
String renewTokenPostData = "app_name=Amazon%20Alexa" //
+ "&app_version=" + AmazonEchoControlBindingConstants.API_VERSION //
+ "&di.sdk.version=" + AmazonEchoControlBindingConstants.DI_SDK_VERSION //
- + "&source_token=" + URLEncoder.encode(loginData.refreshToken, StandardCharsets.UTF_8) //
+ + "&source_token=" + URLEncoder.encode(loginData.getRefreshToken(), StandardCharsets.UTF_8) //
+ "&package_name=com.amazon.echo" //
+ "&di.hw.version=iPhone" //
+ "&platform=iOS" //
@@ -478,8 +415,8 @@ public boolean checkRenewSession() throws ConnectionException {
+ "&di.os.version=" + AmazonEchoControlBindingConstants.DI_OS_VERSION //
+ "¤t_version=6.12.4";
- JsonRenewTokenResponse tokenResponse = requestBuilder.post("https://api.amazon.com/auth/token")
- .withContent(renewTokenPostData).syncSend(JsonRenewTokenResponse.class);
+ AuthTokenResponseTO tokenResponse = requestBuilder.post("https://api.amazon.com/auth/token")
+ .withContent(renewTokenPostData).syncSend(AuthTokenResponseTO.class);
if (tokenResponse == null) {
return false;
@@ -494,32 +431,30 @@ public boolean checkRenewSession() throws ConnectionException {
// renew at 80% expired
accessTokenExpiryTime = System.currentTimeMillis() + (long) ((tokenResponse.expiresIn * 1000.0) / 0.8);
- if (this.macDms == null) {
- // if macDms is not set, this is a new connection we need to register it as app
- registerConnectionAsApp(accessToken);
- } else if (System.currentTimeMillis() > this.connectionExpiryTime) {
- exchangeToken();
+ if (System.currentTimeMillis() > this.connectionExpiryTime) {
+ exchangeToken(loginData.getRetailDomain());
}
return true;
}
return false;
}
- public boolean getIsLoggedIn() {
- return loginData.loginTime != null;
+ public boolean isLoggedIn() {
+ return loginData.getLoginTime() != null;
}
public String getLoginPage() throws ConnectionException {
// clear session data
logout();
- logger.debug("Start Login to {}", alexaServer);
+ logger.debug("Start Login to {}", getAlexaServer());
String mapMdJson = "{\"device_user_dictionary\":[],\"device_registration_data\":{\"software_version\":\"1\"},\"app_identifier\":{\"app_version\":\"2.2.443692\",\"bundle_id\":\"com.amazon.echo\"}}";
String mapMdCookie = Base64.getEncoder().encodeToString(mapMdJson.getBytes());
cookieManager.getCookieStore().add(URI.create("https://www.amazon.com"), new HttpCookie("map-md", mapMdCookie));
- cookieManager.getCookieStore().add(URI.create("https://www.amazon.com"), new HttpCookie("frc", loginData.frc));
+ cookieManager.getCookieStore().add(URI.create("https://www.amazon.com"),
+ new HttpCookie("frc", loginData.getFrc()));
String url = "https://www.amazon.com/ap/signin" //
+ "?openid.return_to=https://www.amazon.com/ap/maplanding" //
@@ -530,7 +465,7 @@ public String getLoginPage() throws ConnectionException {
+ "&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select" //
+ "&openid.mode=checkid_setup" //
+ "&openid.ns.oa2=http://www.amazon.com/ap/ext/oauth/2" //
- + "&openid.oa2.client_id=device:" + loginData.deviceId//
+ + "&openid.oa2.client_id=device:" + loginData.getDeviceId() //
+ "&openid.ns.pape=http://specs.openid.net/extensions/pape/1.0" //
+ "&openid.oa2.response_type=token" //
+ "&openid.ns=http://specs.openid.net/auth/2.0&openid.pape.max_auth_age=0" //
@@ -543,18 +478,15 @@ public String getLoginPage() throws ConnectionException {
}
public boolean verifyLogin() throws ConnectionException {
- if (this.loginData.refreshToken == null) {
+ if (this.loginData.getRefreshToken() == null || !tryGetBootstrap()) {
+ verifyTime = null;
return false;
}
- Authentication authentication = tryGetBootstrap();
- if (authentication != null && authentication.authenticated) {
- verifyTime = new Date();
- if (loginData.loginTime == null) {
- loginData.loginTime = verifyTime;
- }
- return true;
+ verifyTime = new Date();
+ if (loginData.getLoginTime() == null) {
+ loginData.setLoginTime(verifyTime);
}
- return false;
+ return true;
}
// current value in compute can be null
@@ -570,8 +502,8 @@ private void replaceTimer(TimerType type, @Nullable ScheduledFuture> newTimer)
public void logout() {
cookieManager.getCookieStore().removeAll();
// reset all members
- loginData.refreshToken = null;
- loginData.loginTime = null;
+ loginData.setRefreshToken(null);
+ loginData.setLoginTime(null);
verifyTime = null;
replaceTimer(TimerType.ANNOUNCEMENT, null);
@@ -605,27 +537,20 @@ public void logout() {
}
// commands and states
- public List