Merge "Support CSV values in the package names for the TV Remote Provider." into rvc-dev am: 3875de7c94 am: c84d1e6c89
Change-Id: I54aaa1fde7fbe7d7d0e7fec53124e1be1256320c
This commit is contained in:
@@ -3447,8 +3447,9 @@
|
||||
TODO: move to input HAL once ready. -->
|
||||
<string name="config_doubleTouchGestureEnableFile"></string>
|
||||
|
||||
<!-- Package of the unbundled tv remote service which can connect to tv
|
||||
remote provider -->
|
||||
<!-- Comma-separated list of unbundled packages which can connect to the
|
||||
tv remote provider. The tv remote service is an example of such a
|
||||
service. -->
|
||||
<string name="config_tvRemoteServicePackage" translatable="false"></string>
|
||||
|
||||
<!-- True if the device supports persisting security logs across reboots.
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils.SimpleStringSplitter;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
|
||||
@@ -34,6 +35,8 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Watches for emote provider services to be installed.
|
||||
@@ -51,8 +54,8 @@ final class TvRemoteProviderWatcher {
|
||||
private final PackageManager mPackageManager;
|
||||
private final ArrayList<TvRemoteProviderProxy> mProviderProxies = new ArrayList<>();
|
||||
private final int mUserId;
|
||||
private final String mUnbundledServicePackage;
|
||||
private final Object mLock;
|
||||
private final Set<String> mUnbundledServicePackages = new HashSet<>();
|
||||
|
||||
private boolean mRunning;
|
||||
|
||||
@@ -61,9 +64,19 @@ final class TvRemoteProviderWatcher {
|
||||
mHandler = new Handler(true);
|
||||
mUserId = UserHandle.myUserId();
|
||||
mPackageManager = context.getPackageManager();
|
||||
mUnbundledServicePackage = context.getString(
|
||||
com.android.internal.R.string.config_tvRemoteServicePackage);
|
||||
mLock = lock;
|
||||
|
||||
// Unbundled package names supports a comma-separated list
|
||||
SimpleStringSplitter splitter = new SimpleStringSplitter(',');
|
||||
splitter.setString(context.getString(
|
||||
com.android.internal.R.string.config_tvRemoteServicePackage));
|
||||
|
||||
splitter.forEach(packageName -> {
|
||||
packageName = packageName.trim();
|
||||
if (!packageName.isEmpty()) {
|
||||
mUnbundledServicePackages.add(packageName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@@ -157,7 +170,7 @@ final class TvRemoteProviderWatcher {
|
||||
}
|
||||
|
||||
// Check if package name is white-listed here.
|
||||
if (!serviceInfo.packageName.equals(mUnbundledServicePackage)) {
|
||||
if (!mUnbundledServicePackages.contains(serviceInfo.packageName)) {
|
||||
Slog.w(TAG, "Ignoring atv remote provider service because the package has not "
|
||||
+ "been set and/or whitelisted: "
|
||||
+ serviceInfo.packageName + "/" + serviceInfo.name);
|
||||
|
||||
@@ -83,6 +83,22 @@ public class TvRemoteProviderWatcherTest {
|
||||
mTvRemoteProviderWatcher = new TvRemoteProviderWatcher(mMockContext, new Object());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsValidCsvPackageName() {
|
||||
// Test intentionally includes empty spacing for a more complex test
|
||||
when(mMockResources.getString(com.android.internal.R.string.config_tvRemoteServicePackage))
|
||||
.thenReturn(",,foo, " + TV_REMOTE_SERVICE_PACKAGE_NAME + ",bar, baz,,");
|
||||
assertTrue(mTvRemoteProviderWatcher.verifyServiceTrusted(createTvServiceInfo()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsInvalidCsvPackageName() {
|
||||
// Checks include empty strings to validate that processing as well
|
||||
when(mMockResources.getString(com.android.internal.R.string.config_tvRemoteServicePackage))
|
||||
.thenReturn(",,foo,, ,bar, baz,,");
|
||||
assertFalse(mTvRemoteProviderWatcher.verifyServiceTrusted(createTvServiceInfo()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tvServiceIsTrusted() {
|
||||
assertTrue(mTvRemoteProviderWatcher.verifyServiceTrusted(createTvServiceInfo()));
|
||||
|
||||
Reference in New Issue
Block a user