Merge "Replace LanguageTag.isLanguage with public API" am: 1db88034cc
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1531679 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I71a9d46ed0a2edb33bcd0d631b09ee04bc0e66f6
This commit is contained in:
@@ -26,6 +26,8 @@ import android.hardware.tv.cec.V1_0.IHdmiCec.getPhysicalAddressCallback;
|
||||
import android.hardware.tv.cec.V1_0.IHdmiCecCallback;
|
||||
import android.hardware.tv.cec.V1_0.Result;
|
||||
import android.hardware.tv.cec.V1_0.SendMessageResult;
|
||||
import android.icu.util.IllformedLocaleException;
|
||||
import android.icu.util.ULocale;
|
||||
import android.os.Handler;
|
||||
import android.os.IHwBinder;
|
||||
import android.os.Looper;
|
||||
@@ -33,6 +35,7 @@ import android.os.RemoteException;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.server.hdmi.HdmiAnnotations.IoThreadOnly;
|
||||
import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly;
|
||||
@@ -48,8 +51,6 @@ import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import sun.util.locale.LanguageTag;
|
||||
|
||||
/**
|
||||
* Manages HDMI-CEC command and behaviors. It converts user's command into CEC command
|
||||
* and pass it to CEC HAL so that it sends message to other device. For incoming
|
||||
@@ -369,12 +370,30 @@ final class HdmiCecController {
|
||||
@ServiceThreadOnly
|
||||
void setLanguage(String language) {
|
||||
assertRunOnServiceThread();
|
||||
if (!LanguageTag.isLanguage(language)) {
|
||||
if (!isLanguage(language)) {
|
||||
return;
|
||||
}
|
||||
mNativeWrapperImpl.nativeSetLanguage(language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the language code is well-formed.
|
||||
*/
|
||||
@VisibleForTesting static boolean isLanguage(String language) {
|
||||
// Handle null and empty string because because ULocale.Builder#setLanguage accepts them.
|
||||
if (language == null || language.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ULocale.Builder builder = new ULocale.Builder();
|
||||
try {
|
||||
builder.setLanguage(language);
|
||||
return true;
|
||||
} catch (IllformedLocaleException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure ARC circuit in the hardware logic to start or stop the feature.
|
||||
*
|
||||
|
||||
@@ -28,6 +28,8 @@ import static com.android.server.hdmi.Constants.ADDR_TV;
|
||||
import static com.android.server.hdmi.Constants.ADDR_UNREGISTERED;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.tv.cec.V1_0.SendMessageResult;
|
||||
@@ -189,4 +191,19 @@ public class HdmiCecControllerTest {
|
||||
mTestLooper.dispatchAll();
|
||||
assertEquals(ADDR_UNREGISTERED, mLogicalAddress);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsLanguage() {
|
||||
assertTrue(HdmiCecController.isLanguage("en"));
|
||||
assertTrue(HdmiCecController.isLanguage("eng"));
|
||||
assertTrue(HdmiCecController.isLanguage("ger"));
|
||||
assertTrue(HdmiCecController.isLanguage("zh"));
|
||||
assertTrue(HdmiCecController.isLanguage("zhi"));
|
||||
assertTrue(HdmiCecController.isLanguage("zho"));
|
||||
|
||||
assertFalse(HdmiCecController.isLanguage(null));
|
||||
assertFalse(HdmiCecController.isLanguage(""));
|
||||
assertFalse(HdmiCecController.isLanguage("e"));
|
||||
assertFalse(HdmiCecController.isLanguage("一")); // language code must be ASCII
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user