Skip to content

Commit 11e694a

Browse files
authored
Merge pull request #1325 from zhouxin627/bugfix/1241
SDL-0289 Support for Set Language Separately
2 parents 3699318 + 82c0e9b commit 11e694a

8 files changed

Lines changed: 142 additions & 27 deletions

File tree

android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,44 @@ public void onError(String info, Exception e) {
198198
}
199199

200200
@Override
201-
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language){
202-
String appName;
201+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
202+
return null;
203+
}
204+
205+
@Override
206+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
207+
boolean isNeedUpdate = false;
208+
String appName = APP_NAME;
209+
String ttsName = APP_NAME;
203210
switch (language) {
204211
case ES_MX:
212+
isNeedUpdate = true;
213+
ttsName = APP_NAME_ES;
214+
break;
215+
case FR_CA:
216+
isNeedUpdate = true;
217+
ttsName = APP_NAME_FR;
218+
break;
219+
default:
220+
break;
221+
}
222+
switch (hmiLanguage) {
223+
case ES_MX:
224+
isNeedUpdate = true;
205225
appName = APP_NAME_ES;
206226
break;
207227
case FR_CA:
228+
isNeedUpdate = true;
208229
appName = APP_NAME_FR;
209230
break;
210231
default:
211-
return null;
232+
break;
233+
}
234+
if (isNeedUpdate) {
235+
return new LifecycleConfigurationUpdate(appName, null, TTSChunkFactory.createSimpleTTSChunks(ttsName), null);
236+
} else {
237+
return null;
212238
}
213-
214-
return new LifecycleConfigurationUpdate(appName,null,TTSChunkFactory.createSimpleTTSChunks(appName), null);
215239
}
216240
};
217241

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ public void onError(String info, Exception e) {
110110
}
111111

112112
@Override
113-
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language){
113+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
114+
return null;
115+
}
116+
117+
@Override
118+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
114119
return null;
115120
}
116121
};
@@ -166,6 +171,7 @@ public void testManagerSetters() {
166171
assertEquals("heyApp", sdlManager.getShortAppName());
167172
assertEquals(appType, sdlManager.getAppTypes());
168173
assertEquals(Language.EN_US, sdlManager.getHmiLanguage());
174+
assertEquals(Language.EN_US, sdlManager.getLanguage());
169175
assertEquals(transport, sdlManager.getTransport());
170176
assertEquals(templateColorScheme, sdlManager.getDayColorScheme());
171177
assertEquals(templateColorScheme, sdlManager.getNightColorScheme());

android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,23 @@ public void onComplete(boolean success) {
244244
@Override
245245
protected void checkLifecycleConfiguration(){
246246
final Language actualLanguage = this.getRegisterAppInterfaceResponse().getLanguage();
247+
final Language actualHMILanguage = this.getRegisterAppInterfaceResponse().getHmiDisplayLanguage();
247248

248-
if (actualLanguage != null && !actualLanguage.equals(hmiLanguage)) {
249+
if ((actualLanguage != null && !actualLanguage.equals(language)) || (actualHMILanguage != null && !actualHMILanguage.equals(hmiLanguage))) {
249250

250-
final LifecycleConfigurationUpdate lcu = managerListener.managerShouldUpdateLifecycle(actualLanguage);
251+
LifecycleConfigurationUpdate lcuNew = managerListener.managerShouldUpdateLifecycle(actualLanguage, actualHMILanguage);
252+
LifecycleConfigurationUpdate lcuOld = managerListener.managerShouldUpdateLifecycle(actualLanguage);
253+
final LifecycleConfigurationUpdate lcu;
254+
ChangeRegistration changeRegistration;
255+
if (lcuNew == null) {
256+
lcu = lcuOld;
257+
changeRegistration = new ChangeRegistration(actualLanguage, actualLanguage);
258+
} else {
259+
lcu = lcuNew;
260+
changeRegistration = new ChangeRegistration(actualLanguage, actualHMILanguage);
261+
}
251262

252263
if (lcu != null) {
253-
ChangeRegistration changeRegistration = new ChangeRegistration(actualLanguage, actualLanguage);
254264
changeRegistration.setAppName(lcu.getAppName());
255265
changeRegistration.setNgnMediaScreenAppName(lcu.getShortAppName());
256266
changeRegistration.setTtsName(lcu.getTtsName());
@@ -260,7 +270,8 @@ protected void checkLifecycleConfiguration(){
260270
public void onResponse(int correlationId, RPCResponse response) {
261271
if (response.getSuccess()){
262272
// go through and change sdlManager properties that were changed via the LCU update
263-
hmiLanguage = actualLanguage;
273+
hmiLanguage = actualHMILanguage;
274+
language = actualLanguage;
264275

265276
if (lcu.getAppName() != null) {
266277
appName = lcu.getAppName();
@@ -1028,8 +1039,9 @@ public Builder setMinimumRPCVersion(final Version minimumRPCVersion) {
10281039
* Sets the Language of the App
10291040
* @param hmiLanguage the desired language to be used on the display/HMI of the connected module
10301041
*/
1031-
public Builder setLanguage(final Language hmiLanguage){
1042+
public Builder setLanguage(final Language hmiLanguage) {
10321043
sdlManager.hmiLanguage = hmiLanguage;
1044+
sdlManager.language = hmiLanguage;
10331045
return this;
10341046
}
10351047

@@ -1225,6 +1237,7 @@ public SdlManager build() {
12251237

12261238
if (sdlManager.hmiLanguage == null){
12271239
sdlManager.hmiLanguage = Language.EN_US;
1240+
sdlManager.language = Language.EN_US;
12281241
}
12291242

12301243
if (sdlManager.minimumProtocolVersion == null){

android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManagerListener.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ public interface SdlManagerListener extends BaseSdlManagerListener{
6464
* @param language The language of the connected head unit the manager is trying to update the configuration.
6565
* @return An object of LifecycleConfigurationUpdate if the head unit language is supported,
6666
* otherwise null to indicate that the language is not supported.
67+
* @deprecated use {@link #managerShouldUpdateLifecycle(Language language, Language hmiLanguage)} instead
6768
*/
69+
@Deprecated
6870
LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language);
71+
72+
/**
73+
* Called when the SDL manager detected a language mismatch. In case of a language mismatch the
74+
* manager should change the apps registration by updating the lifecycle configuration to the
75+
* specified language. If the app can support the specified language it should return an Object
76+
* of LifecycleConfigurationUpdate, otherwise it should return null to indicate that the language
77+
* is not supported.
78+
*
79+
* @param language The VR+TTS language of the connected head unit the manager is trying to update the configuration.
80+
* @param hmiLanguage The HMI display language of the connected head unit the manager is trying to update the configuration.
81+
* @return An object of LifecycleConfigurationUpdate if the head unit language is supported,
82+
* otherwise null to indicate that the language is not supported.
83+
*/
84+
LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage);
6985
}

base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ abstract class BaseSdlManager {
6868
String appId, appName, shortAppName;
6969
boolean isMediaApp;
7070
Language hmiLanguage;
71+
Language language;
7172
Vector<AppHMIType> hmiTypes;
7273
BaseTransportConfig transport;
7374
Vector<String> vrSynonyms;
@@ -93,6 +94,8 @@ abstract class BaseSdlManager {
9394

9495
protected Language getHmiLanguage() { return hmiLanguage; }
9596

97+
protected Language getLanguage() { return language; }
98+
9699
protected TemplateColorScheme getDayColorScheme() { return dayColorScheme; }
97100

98101
protected TemplateColorScheme getNightColorScheme() { return nightColorScheme; }

hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,44 @@ public void onError(SdlManager sdlManager, String info, Exception e) {
138138
}
139139

140140
@Override
141-
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language){
142-
String appName;
141+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
142+
return null;
143+
}
144+
145+
@Override
146+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
147+
boolean isNeedUpdate = false;
148+
String appName = APP_NAME;
149+
String ttsName = APP_NAME;
143150
switch (language) {
144151
case ES_MX:
152+
isNeedUpdate = true;
153+
ttsName = APP_NAME_ES;
154+
break;
155+
case FR_CA:
156+
isNeedUpdate = true;
157+
ttsName = APP_NAME_FR;
158+
break;
159+
default:
160+
break;
161+
}
162+
switch (hmiLanguage) {
163+
case ES_MX:
164+
isNeedUpdate = true;
145165
appName = APP_NAME_ES;
146166
break;
147167
case FR_CA:
168+
isNeedUpdate = true;
148169
appName = APP_NAME_FR;
149170
break;
150171
default:
151-
return null;
172+
break;
173+
}
174+
if (isNeedUpdate) {
175+
return new LifecycleConfigurationUpdate(appName, null, TTSChunkFactory.createSimpleTTSChunks(ttsName), null);
176+
} else {
177+
return null;
152178
}
153-
154-
return new LifecycleConfigurationUpdate(appName,null,TTSChunkFactory.createSimpleTTSChunks(appName), null);
155179
}
156180
};
157181

javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,25 +231,36 @@ public void onComplete(boolean success) {
231231
}
232232

233233
@Override
234-
protected void checkLifecycleConfiguration() {
235-
final Language actualLanguage = lifecycleManager.getRegisterAppInterfaceResponse().getLanguage();
236-
237-
if (actualLanguage != null && !actualLanguage.equals(hmiLanguage)) {
238-
239-
final LifecycleConfigurationUpdate lcu = managerListener.managerShouldUpdateLifecycle(actualLanguage);
234+
protected void checkLifecycleConfiguration(){
235+
final Language actualLanguage = this.getRegisterAppInterfaceResponse().getLanguage();
236+
final Language actualHMILanguage = this.getRegisterAppInterfaceResponse().getHmiDisplayLanguage();
237+
238+
if ((actualLanguage != null && !actualLanguage.equals(language)) || (actualHMILanguage != null && !actualHMILanguage.equals(hmiLanguage))) {
239+
240+
LifecycleConfigurationUpdate lcuNew = managerListener.managerShouldUpdateLifecycle(actualLanguage, actualHMILanguage);
241+
LifecycleConfigurationUpdate lcuOld = managerListener.managerShouldUpdateLifecycle(actualLanguage);
242+
final LifecycleConfigurationUpdate lcu;
243+
ChangeRegistration changeRegistration;
244+
if (lcuNew == null) {
245+
lcu = lcuOld;
246+
changeRegistration = new ChangeRegistration(actualLanguage, actualLanguage);
247+
} else {
248+
lcu = lcuNew;
249+
changeRegistration = new ChangeRegistration(actualLanguage, actualHMILanguage);
250+
}
240251

241252
if (lcu != null) {
242-
ChangeRegistration changeRegistration = new ChangeRegistration(actualLanguage, actualLanguage);
243253
changeRegistration.setAppName(lcu.getAppName());
244254
changeRegistration.setNgnMediaScreenAppName(lcu.getShortAppName());
245255
changeRegistration.setTtsName(lcu.getTtsName());
246256
changeRegistration.setVrSynonyms(lcu.getVoiceRecognitionCommandNames());
247257
changeRegistration.setOnRPCResponseListener(new OnRPCResponseListener() {
248258
@Override
249259
public void onResponse(int correlationId, RPCResponse response) {
250-
if (response.getSuccess()) {
260+
if (response.getSuccess()){
251261
// go through and change sdlManager properties that were changed via the LCU update
252-
hmiLanguage = actualLanguage;
262+
hmiLanguage = actualHMILanguage;
263+
language = actualLanguage;
253264

254265
if (lcu.getAppName() != null) {
255266
appName = lcu.getAppName();
@@ -642,8 +653,9 @@ public Builder setMinimumRPCVersion(final Version minimumRPCVersion) {
642653
* Sets the Language of the App
643654
* @param hmiLanguage the desired language to be used on the display/HMI of the connected module
644655
*/
645-
public Builder setLanguage(final Language hmiLanguage){
656+
public Builder setLanguage(final Language hmiLanguage) {
646657
sdlManager.hmiLanguage = hmiLanguage;
658+
sdlManager.language = hmiLanguage;
647659
return this;
648660
}
649661

@@ -801,8 +813,9 @@ public SdlManager build() {
801813
sdlManager.fileManagerConfig = new FileManagerConfig();
802814
}
803815

804-
if (sdlManager.hmiLanguage == null){
816+
if (sdlManager.hmiLanguage == null) {
805817
sdlManager.hmiLanguage = Language.EN_US;
818+
sdlManager.language = Language.EN_US;
806819
}
807820

808821
if (sdlManager.minimumProtocolVersion == null){

javaSE/src/main/java/com/smartdevicelink/managers/SdlManagerListener.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ public interface SdlManagerListener extends BaseSdlManagerListener {
6363
* @param language The language of the connected head unit the manager is trying to update the configuration.
6464
* @return An object of LifecycleConfigurationUpdate if the head unit language is supported,
6565
* otherwise null to indicate that the language is not supported.
66+
* @deprecated use {@link #managerShouldUpdateLifecycle(Language language, Language hmiLanguage)} instead
6667
*/
68+
@Deprecated
6769
LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language);
70+
71+
/**
72+
* Called when the SDL manager detected a language mismatch. In case of a language mismatch the
73+
* manager should change the apps registration by updating the lifecycle configuration to the
74+
* specified language. If the app can support the specified language it should return an Object
75+
* of LifecycleConfigurationUpdate, otherwise it should return null to indicate that the language
76+
* is not supported.
77+
*
78+
* @param language The VR+TTS language of the connected head unit the manager is trying to update the configuration.
79+
* @param hmiLanguage The HMI display language of the connected head unit the manager is trying to update the configuration.
80+
* @return An object of LifecycleConfigurationUpdate if the head unit language is supported,
81+
* otherwise null to indicate that the language is not supported.
82+
*/
83+
LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage);
6884
}

0 commit comments

Comments
 (0)