• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.media.cts;
17 
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
23 
24 import android.app.Activity;
25 import android.app.Instrumentation;
26 import android.content.Context;
27 import android.content.pm.PackageManager;
28 import android.content.res.AssetFileDescriptor;
29 import android.media.MediaPlayer;
30 import android.media.cts.TestUtils.Monitor;
31 import android.net.Uri;
32 import android.os.ConditionVariable;
33 import android.os.ParcelFileDescriptor;
34 import android.os.PersistableBundle;
35 
36 import androidx.annotation.CallSuper;
37 import androidx.test.core.app.ActivityScenario;
38 import androidx.test.platform.app.InstrumentationRegistry;
39 
40 import com.android.compatibility.common.util.MediaUtils;
41 
42 import java.io.File;
43 import java.io.FileNotFoundException;
44 import java.io.IOException;
45 import java.net.HttpCookie;
46 import java.util.List;
47 import java.util.logging.Logger;
48 import java.util.Map;
49 import java.util.Set;
50 
51 /**
52  * Base class for tests which use MediaPlayer to play audio or video.
53  */
54 public class MediaTestBase {
55     private static final Logger LOG = Logger.getLogger(MediaTestBase.class.getName());
56 
57     protected static final int SLEEP_TIME = 1000;
58     protected static final int LONG_SLEEP_TIME = 6000;
59     protected static final int STREAM_RETRIES = 20;
60     protected static boolean sUseScaleToFitMode = false;
61 
62     protected Context mContext;
63 
64     protected ActivityScenario<MediaStubActivity> mActivityScenario;
65     protected MediaStubActivity mActivity;
66 
67     @CallSuper
setUp()68     protected void setUp() throws Throwable {
69         mActivityScenario = ActivityScenario.launch(MediaStubActivity.class);
70         ConditionVariable activityReferenceObtained = new ConditionVariable();
71         mActivityScenario.onActivity(activity -> {
72             mActivity = activity;
73             activityReferenceObtained.open();
74         });
75         activityReferenceObtained.block(/* timeoutMs= */ 10000);
76         assertNotNull("Failed to acquire activity reference.", mActivity);
77 
78         mContext = getInstrumentation().getTargetContext();
79         getInstrumentation().waitForIdleSync();
80     }
81 
82     @CallSuper
tearDown()83     protected void tearDown() {
84         mActivityScenario.close();
85         mActivity = null;
86     }
87 
getInstrumentation()88     protected Instrumentation getInstrumentation() {
89         return InstrumentationRegistry.getInstrumentation();
90     }
91 
getActivity()92     protected MediaStubActivity getActivity() {
93         return mActivity;
94     }
95 
isTv()96     public boolean isTv() {
97         PackageManager pm = getInstrumentation().getTargetContext().getPackageManager();
98         return pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)
99                 && pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
100     }
101 
checkTv()102     public boolean checkTv() {
103         return MediaUtils.check(isTv(), "not a TV");
104     }
105 
106 }
107