Replace LanguageTag.isLanguage with public API
Libcore will be modulized and updatable, and thus avoid using libcore's private API. No behavior change. Bug: 154796679 Test: HdmiCecControllerTest#testIsLanguage Change-Id: If9cc4df26182141d292a218a5f4cba442e802309
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.IHdmiCecCallback;
|
||||||
import android.hardware.tv.cec.V1_0.Result;
|
import android.hardware.tv.cec.V1_0.Result;
|
||||||
import android.hardware.tv.cec.V1_0.SendMessageResult;
|
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.Handler;
|
||||||
import android.os.IHwBinder;
|
import android.os.IHwBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -33,6 +35,7 @@ import android.os.RemoteException;
|
|||||||
import android.stats.hdmi.HdmiStatsEnums;
|
import android.stats.hdmi.HdmiStatsEnums;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.util.FrameworkStatsLog;
|
import com.android.internal.util.FrameworkStatsLog;
|
||||||
import com.android.internal.util.IndentingPrintWriter;
|
import com.android.internal.util.IndentingPrintWriter;
|
||||||
import com.android.server.hdmi.HdmiAnnotations.IoThreadOnly;
|
import com.android.server.hdmi.HdmiAnnotations.IoThreadOnly;
|
||||||
@@ -49,8 +52,6 @@ import java.util.List;
|
|||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import sun.util.locale.LanguageTag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages HDMI-CEC command and behaviors. It converts user's command into CEC command
|
* 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
|
* and pass it to CEC HAL so that it sends message to other device. For incoming
|
||||||
@@ -352,12 +353,30 @@ final class HdmiCecController {
|
|||||||
@ServiceThreadOnly
|
@ServiceThreadOnly
|
||||||
void setLanguage(String language) {
|
void setLanguage(String language) {
|
||||||
assertRunOnServiceThread();
|
assertRunOnServiceThread();
|
||||||
if (!LanguageTag.isLanguage(language)) {
|
if (!isLanguage(language)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mNativeWrapperImpl.nativeSetLanguage(language);
|
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.
|
* Configure ARC circuit in the hardware logic to start or stop the feature.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import static com.android.server.hdmi.Constants.ADDR_TV;
|
|||||||
import static com.android.server.hdmi.Constants.ADDR_UNREGISTERED;
|
import static com.android.server.hdmi.Constants.ADDR_UNREGISTERED;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertFalse;
|
||||||
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.hdmi.HdmiControlManager;
|
import android.hardware.hdmi.HdmiControlManager;
|
||||||
@@ -257,4 +259,19 @@ public class HdmiCecControllerTest {
|
|||||||
mTestLooper.dispatchAll();
|
mTestLooper.dispatchAll();
|
||||||
assertEquals(ADDR_UNREGISTERED, mLogicalAddress);
|
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