aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jni/minijail/Android.bp32
-rw-r--r--jni/minijail/Android.mk32
-rw-r--r--src/com/android/tv/SetupPassthroughActivity.java13
-rw-r--r--tests/func/Android.bp21
-rw-r--r--tests/func/Android.mk26
-rw-r--r--tests/robotests/src/com/android/tv/SetupPassthroughActivityTest.java57
6 files changed, 102 insertions, 79 deletions
diff --git a/jni/minijail/Android.bp b/jni/minijail/Android.bp
new file mode 100644
index 00000000..cb921159
--- /dev/null
+++ b/jni/minijail/Android.bp
@@ -0,0 +1,32 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_library_shared {
+ name: "libminijail_jni",
+ srcs: ["minijail.cpp"],
+ stl: "none",
+ header_libs: ["jni_headers"],
+ static_libs: [
+ "libc++_static",
+ "libminijail",
+ ],
+ shared_libs: ["liblog"],
+}
diff --git a/jni/minijail/Android.mk b/jni/minijail/Android.mk
deleted file mode 100644
index 3d8e2b35..00000000
--- a/jni/minijail/Android.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright (C) 2017 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-# --------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libminijail_jni
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SRC_FILES := minijail.cpp
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_CXX_STL := none
-LOCAL_HEADER_LIBRARIES := jni_headers
-LOCAL_STATIC_LIBRARIES := libc++_static libminijail
-LOCAL_LDLIBS := -llog
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/src/com/android/tv/SetupPassthroughActivity.java b/src/com/android/tv/SetupPassthroughActivity.java
index 25049f1d..e7f89108 100644
--- a/src/com/android/tv/SetupPassthroughActivity.java
+++ b/src/com/android/tv/SetupPassthroughActivity.java
@@ -118,13 +118,12 @@ public class SetupPassthroughActivity extends Activity {
setupIntent.putExtras(extras);
try {
ComponentName callingActivity = getCallingActivity();
- if (callingActivity != null
- && !callingActivity.getPackageName().equals(CommonConstants.BASE_PACKAGE)) {
- Log.w(
- TAG,
- "Calling activity "
- + callingActivity.getPackageName()
- + " is not trusted. Not forwarding intent.");
+ if (callingActivity == null
+ || !callingActivity.getPackageName().equals(CommonConstants.BASE_PACKAGE)) {
+ String name =
+ callingActivity == null ? "null" : callingActivity.getPackageName();
+ Log.w(TAG,
+ "Calling activity " + name + " is not trusted. Not forwarding intent.");
finish();
return;
}
diff --git a/tests/func/Android.bp b/tests/func/Android.bp
new file mode 100644
index 00000000..d4085394
--- /dev/null
+++ b/tests/func/Android.bp
@@ -0,0 +1,21 @@
+package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+ name: "TVFuncTests",
+ // Include all test java files.
+ srcs: ["src/**/*.java"],
+ static_libs: [
+ "androidx.test.runner",
+ "tv-test-common",
+ "ub-uiautomator",
+ ],
+ libs: ["android.test.base.stubs"],
+ instrumentation_for: "LiveTv",
+ sdk_version: "system_current",
+ optimize: {
+ enabled: false,
+ },
+}
diff --git a/tests/func/Android.mk b/tests/func/Android.mk
deleted file mode 100644
index 60290c2d..00000000
--- a/tests/func/Android.mk
+++ /dev/null
@@ -1,26 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-
-# Include all test java files.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := TVFuncTests
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
- androidx.test.runner \
- tv-test-common \
- ub-uiautomator \
-
-LOCAL_JAVA_LIBRARIES := android.test.base.stubs
-
-LOCAL_INSTRUMENTATION_FOR := LiveTv
-
-LOCAL_SDK_VERSION := system_current
-
-LOCAL_PROGUARD_ENABLED := disabled
-include $(BUILD_PACKAGE)
diff --git a/tests/robotests/src/com/android/tv/SetupPassthroughActivityTest.java b/tests/robotests/src/com/android/tv/SetupPassthroughActivityTest.java
index efba4947..2b2bbe83 100644
--- a/tests/robotests/src/com/android/tv/SetupPassthroughActivityTest.java
+++ b/tests/robotests/src/com/android/tv/SetupPassthroughActivityTest.java
@@ -37,6 +37,7 @@ import com.android.tv.common.CommonConstants;
import com.android.tv.common.dagger.ApplicationModule;
import com.android.tv.common.flags.impl.DefaultLegacyFlags;
import com.android.tv.common.flags.impl.SettableFlagsModule;
+import com.android.tv.common.flags.proto.TypedFeatures.StringListParam;
import com.android.tv.common.util.CommonUtils;
import com.android.tv.data.ChannelDataManager;
import com.android.tv.data.epg.EpgFetcher;
@@ -53,7 +54,6 @@ import com.android.tv.util.TvInputManagerHelper;
import com.google.android.tv.partner.support.EpgContract;
import com.google.common.base.Optional;
-import com.android.tv.common.flags.proto.TypedFeatures.StringListParam;
import dagger.Component;
import dagger.Module;
@@ -71,7 +71,6 @@ import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.android.util.concurrent.RoboExecutorService;
import org.robolectric.annotation.Config;
@@ -169,8 +168,7 @@ public class SetupPassthroughActivityTest {
CommonUtils.createSetupIntent(new Intent(), testInput.getId()));
SetupPassthroughActivity activity = activityController.get();
ShadowActivity shadowActivity = shadowOf(activity);
- shadowActivity.setCallingActivity(
- new ComponentName(CommonConstants.BASE_PACKAGE, "com.example.MyClass"));
+ shadowActivity.setCallingActivity(createTrustedComponent());
activityController.create();
ShadowActivity.IntentForResult shadowIntent =
@@ -205,6 +203,27 @@ public class SetupPassthroughActivityTest {
}
@Test
+ public void create_nullCallingPackage() {
+ testSingletonApp.tvInputManagerHelper.start();
+ testSingletonApp.tvInputManagerHelper.getFakeTvInputManager().add(testInput, -1);
+
+ ActivityController<SetupPassthroughActivity> activityController =
+ Robolectric.buildActivity(
+ SetupPassthroughActivity.class,
+ CommonUtils.createSetupIntent(new Intent(), testInput.getId()));
+ SetupPassthroughActivity activity = activityController.get();
+ ShadowActivity shadowActivity = shadowOf(activity);
+ shadowActivity.setCallingActivity(null);
+ activityController.create();
+
+ ShadowActivity.IntentForResult shadowIntent =
+ shadowActivity.getNextStartedActivityForResult();
+ // Since the calling activity is null, the next activity should not be started.
+ assertThat(shadowIntent).isNull();
+ assertThat(activity.isFinishing()).isTrue();
+ }
+
+ @Test
public void onActivityResult_canceled() {
testSingletonApp.tvInputManagerHelper.getFakeTvInputManager().add(testInput, -1);
SetupPassthroughActivity activity = createSetupActivityFor(testInput.getId());
@@ -216,7 +235,7 @@ public class SetupPassthroughActivityTest {
@Test
public void onActivityResult_ok() {
- TestSetupUtils setupUtils = new TestSetupUtils(RuntimeEnvironment.application);
+ TestSetupUtils setupUtils = new TestSetupUtils(ApplicationProvider.getApplicationContext());
testSingletonApp.setupUtils = setupUtils;
testSingletonApp.tvInputManagerHelper.getFakeTvInputManager().add(testInput, -1);
SetupPassthroughActivity activity = createSetupActivityFor(testInput.getId());
@@ -234,7 +253,7 @@ public class SetupPassthroughActivityTest {
@Test
public void onActivityResult_3rdPartyEpg_ok() {
TvFeatures.CLOUD_EPG_FOR_3RD_PARTY.enableForTest();
- TestSetupUtils setupUtils = new TestSetupUtils(RuntimeEnvironment.application);
+ TestSetupUtils setupUtils = new TestSetupUtils(ApplicationProvider.getApplicationContext());
testSingletonApp.setupUtils = setupUtils;
testSingletonApp.tvInputManagerHelper.getFakeTvInputManager().add(testInput, -1);
testSingletonApp
@@ -257,9 +276,9 @@ public class SetupPassthroughActivityTest {
}
@Test
- public void onActivityResult_3rdPartyEpg_notWhiteListed() {
+ public void onActivityResult_3rdPartyEpg_notAllowed() {
TvFeatures.CLOUD_EPG_FOR_3RD_PARTY.enableForTest();
- TestSetupUtils setupUtils = new TestSetupUtils(RuntimeEnvironment.application);
+ TestSetupUtils setupUtils = new TestSetupUtils(ApplicationProvider.getApplicationContext());
testSingletonApp.setupUtils = setupUtils;
testSingletonApp.tvInputManagerHelper.getFakeTvInputManager().add(testInput, -1);
SetupPassthroughActivity activity = createSetupActivityFor(testInput.getId());
@@ -280,7 +299,7 @@ public class SetupPassthroughActivityTest {
@Test
public void onActivityResult_3rdPartyEpg_disabled() {
TvFeatures.CLOUD_EPG_FOR_3RD_PARTY.disableForTests();
- TestSetupUtils setupUtils = new TestSetupUtils(RuntimeEnvironment.application);
+ TestSetupUtils setupUtils = new TestSetupUtils(ApplicationProvider.getApplicationContext());
testSingletonApp.setupUtils = setupUtils;
testSingletonApp.tvInputManagerHelper.getFakeTvInputManager().add(testInput, -1);
testSingletonApp
@@ -305,7 +324,7 @@ public class SetupPassthroughActivityTest {
@Test
public void onActivityResult_ok_tvInputInfo_null() {
- TestSetupUtils setupUtils = new TestSetupUtils(RuntimeEnvironment.application);
+ TestSetupUtils setupUtils = new TestSetupUtils(ApplicationProvider.getApplicationContext());
testSingletonApp.setupUtils = setupUtils;
FakeTvInputManager tvInputManager =
testSingletonApp.tvInputManagerHelper.getFakeTvInputManager();
@@ -320,11 +339,15 @@ public class SetupPassthroughActivityTest {
}
private SetupPassthroughActivity createSetupActivityFor(String inputId) {
- return Robolectric.buildActivity(
+ ActivityController<SetupPassthroughActivity> activityController =
+ Robolectric.buildActivity(
SetupPassthroughActivity.class,
- CommonUtils.createSetupIntent(new Intent(), inputId))
- .create()
- .get();
+ CommonUtils.createSetupIntent(new Intent(), inputId));
+ SetupPassthroughActivity activity = activityController.get();
+ ShadowActivity shadowActivity = shadowOf(activity);
+ shadowActivity.setCallingActivity(createTrustedComponent());
+ activityController.create();
+ return activity;
}
private TvInputInfo createMockInput(String inputId) {
@@ -344,6 +367,10 @@ public class SetupPassthroughActivityTest {
return tvInputInfo;
}
+ private static ComponentName createTrustedComponent() {
+ return new ComponentName(CommonConstants.BASE_PACKAGE, "com.example.MyClass");
+ }
+
/**
* Test SetupUtils.
*
@@ -351,6 +378,7 @@ public class SetupPassthroughActivityTest {
* bypasses all of that.
*/
private static class TestSetupUtils extends SetupUtils {
+
public String finishedId;
public Runnable finishedRunnable;
@@ -413,6 +441,7 @@ public class SetupPassthroughActivityTest {
})
/** Module for {@link MyTestApp} */
static class TestModule {
+
private final MyTestApp myTestApp;
TestModule(MyTestApp test) {