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