Merge "Fix unit test for TVRemoteProviderWatcherTest.java." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
bbf2a29472
@@ -59,9 +59,9 @@ final class TvRemoteProviderWatcher {
|
|||||||
|
|
||||||
private boolean mRunning;
|
private boolean mRunning;
|
||||||
|
|
||||||
TvRemoteProviderWatcher(Context context, Object lock) {
|
TvRemoteProviderWatcher(Context context, Object lock, Handler handler) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mHandler = new Handler(true);
|
mHandler = handler;
|
||||||
mUserId = UserHandle.myUserId();
|
mUserId = UserHandle.myUserId();
|
||||||
mPackageManager = context.getPackageManager();
|
mPackageManager = context.getPackageManager();
|
||||||
mLock = lock;
|
mLock = lock;
|
||||||
@@ -79,6 +79,10 @@ final class TvRemoteProviderWatcher {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TvRemoteProviderWatcher(Context context, Object lock) {
|
||||||
|
this(context, lock, new Handler(true));
|
||||||
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
if (DEBUG) Slog.d(TAG, "start()");
|
if (DEBUG) Slog.d(TAG, "start()");
|
||||||
if (!mRunning) {
|
if (!mRunning) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
@@ -88,7 +89,12 @@ public class TvRemoteProviderWatcherTest {
|
|||||||
// Test intentionally includes empty spacing for a more complex test
|
// Test intentionally includes empty spacing for a more complex test
|
||||||
when(mMockResources.getString(com.android.internal.R.string.config_tvRemoteServicePackage))
|
when(mMockResources.getString(com.android.internal.R.string.config_tvRemoteServicePackage))
|
||||||
.thenReturn(",,foo, " + TV_REMOTE_SERVICE_PACKAGE_NAME + ",bar, baz,,");
|
.thenReturn(",,foo, " + TV_REMOTE_SERVICE_PACKAGE_NAME + ",bar, baz,,");
|
||||||
assertTrue(mTvRemoteProviderWatcher.verifyServiceTrusted(createTvServiceInfo()));
|
|
||||||
|
// Re-create the object since package name is loaded in the constructor
|
||||||
|
TvRemoteProviderWatcher watcher =
|
||||||
|
new TvRemoteProviderWatcher(
|
||||||
|
mMockContext, new Object(), new Handler(Looper.getMainLooper()));
|
||||||
|
assertTrue(watcher.verifyServiceTrusted(createTvServiceInfo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -96,7 +102,12 @@ public class TvRemoteProviderWatcherTest {
|
|||||||
// Checks include empty strings to validate that processing as well
|
// Checks include empty strings to validate that processing as well
|
||||||
when(mMockResources.getString(com.android.internal.R.string.config_tvRemoteServicePackage))
|
when(mMockResources.getString(com.android.internal.R.string.config_tvRemoteServicePackage))
|
||||||
.thenReturn(",,foo,, ,bar, baz,,");
|
.thenReturn(",,foo,, ,bar, baz,,");
|
||||||
assertFalse(mTvRemoteProviderWatcher.verifyServiceTrusted(createTvServiceInfo()));
|
|
||||||
|
// Re-create the object since package name is loaded in the constructor
|
||||||
|
TvRemoteProviderWatcher watcher =
|
||||||
|
new TvRemoteProviderWatcher(
|
||||||
|
mMockContext, new Object(), new Handler(Looper.getMainLooper()));
|
||||||
|
assertFalse(watcher.verifyServiceTrusted(createTvServiceInfo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -139,14 +150,9 @@ public class TvRemoteProviderWatcherTest {
|
|||||||
public void whitelistingPackageNameIsRequired() {
|
public void whitelistingPackageNameIsRequired() {
|
||||||
reset(mMockResources);
|
reset(mMockResources);
|
||||||
when(mMockResources.getString(anyInt())).thenReturn("");
|
when(mMockResources.getString(anyInt())).thenReturn("");
|
||||||
|
|
||||||
// Create a new watcher, as the resources are read in the constructor of the class
|
|
||||||
if (Looper.myLooper() == null) {
|
|
||||||
Looper.prepare();
|
|
||||||
}
|
|
||||||
|
|
||||||
TvRemoteProviderWatcher watcher =
|
TvRemoteProviderWatcher watcher =
|
||||||
new TvRemoteProviderWatcher(mMockContext, new Object());
|
new TvRemoteProviderWatcher(
|
||||||
|
mMockContext, new Object(), new Handler(Looper.getMainLooper()));
|
||||||
assertFalse(watcher.verifyServiceTrusted(createTvServiceInfo()));
|
assertFalse(watcher.verifyServiceTrusted(createTvServiceInfo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user