diff options
Diffstat (limited to 'tests/input/src/com/android/tv/testinput')
5 files changed, 158 insertions, 138 deletions
diff --git a/tests/input/src/com/android/tv/testinput/TestInputControl.java b/tests/input/src/com/android/tv/testinput/TestInputControl.java index cd85c86e..5e5ec32a 100644 --- a/tests/input/src/com/android/tv/testinput/TestInputControl.java +++ b/tests/input/src/com/android/tv/testinput/TestInputControl.java @@ -21,28 +21,26 @@ import android.net.Uri; import android.os.RemoteException; import android.util.Log; import android.util.LongSparseArray; - -import com.android.tv.testing.ChannelInfo; -import com.android.tv.testing.ChannelUtils; +import com.android.tv.testing.data.ChannelInfo; +import com.android.tv.testing.data.ChannelUtils; import com.android.tv.testing.testinput.ChannelState; import com.android.tv.testing.testinput.ChannelStateData; import com.android.tv.testing.testinput.ITestInputControl; - import java.util.Map; /** * Maintains state for the {@link TestTvInputService}. * - * <p>Maintains the current state for every channel. A default is sent if the state is not + * <p>Maintains the current state for every channel. A default is sent if the state is not * explicitly set. The state is versioned so TestTvInputService can tell if onNotifyXXX events need * to be sent. * - * <p> Test update the state using @{link ITestInputControl} via {@link TestInputControlService}. + * <p>Test update the state using @{link ITestInputControl} via {@link TestInputControlService}. */ class TestInputControl extends ITestInputControl.Stub { - private final static String TAG = "TestInputControl"; - private final static TestInputControl INSTANCE = new TestInputControl(); + private static final String TAG = "TestInputControl"; + private static final TestInputControl INSTANCE = new TestInputControl(); private final LongSparseArray<ChannelInfo> mId2ChannelInfoMap = new LongSparseArray<>(); private final LongSparseArray<ChannelState> mOrigId2StateMap = new LongSparseArray<>(); @@ -50,8 +48,7 @@ class TestInputControl extends ITestInputControl.Stub { private java.lang.String mInputId; private boolean initialized; - private TestInputControl() { - } + private TestInputControl() {} public static TestInputControl getInstance() { return INSTANCE; @@ -73,8 +70,13 @@ class TestInputControl extends ITestInputControl.Stub { for (Long channelId : channelIdToInfoMap.keySet()) { mId2ChannelInfoMap.put(channelId, channelIdToInfoMap.get(channelId)); } - Log.i(TAG, "Initialized channel map for " + mInputId + " with " + mId2ChannelInfoMap.size() - + " channels"); + Log.i( + TAG, + "Initialized channel map for " + + mInputId + + " with " + + mId2ChannelInfoMap.size() + + " channels"); } public ChannelInfo getChannelInfo(Uri channelUri) { diff --git a/tests/input/src/com/android/tv/testinput/TestInputControlService.java b/tests/input/src/com/android/tv/testinput/TestInputControlService.java index 4a5668cc..4a1306ed 100644 --- a/tests/input/src/com/android/tv/testinput/TestInputControlService.java +++ b/tests/input/src/com/android/tv/testinput/TestInputControlService.java @@ -20,8 +20,8 @@ import android.content.Intent; import android.os.IBinder; /** - * Testcases communicate to the {@link TestInputControl} via - * {@link com.android.tv.testing.testinput.ITestInputControl}. + * Testcases communicate to the {@link TestInputControl} via {@link + * com.android.tv.testing.testinput.ITestInputControl}. */ public class TestInputControlService extends Service { diff --git a/tests/input/src/com/android/tv/testinput/TestTvInputService.java b/tests/input/src/com/android/tv/testinput/TestTvInputService.java index 621ceacb..840587c9 100644 --- a/tests/input/src/com/android/tv/testinput/TestTvInputService.java +++ b/tests/input/src/com/android/tv/testinput/TestTvInputService.java @@ -41,17 +41,13 @@ import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.view.Surface; - import com.android.tv.input.TunerHelper; -import com.android.tv.testing.ChannelInfo; +import com.android.tv.testing.data.ChannelInfo; import com.android.tv.testing.testinput.ChannelState; - import java.util.Date; import java.util.concurrent.TimeUnit; -/** - * Simple TV input service which provides test channels. - */ +/** Simple TV input service which provides test channels. */ public class TestTvInputService extends TvInputService { private static final String TAG = "TestTvInputService"; private static final int REFRESH_DELAY_MS = 1000 / 5; @@ -93,9 +89,7 @@ public class TestTvInputService extends TvInputService { return new SimpleRecordingSessionImpl(this, inputId); } - /** - * Simple session implementation that just display some text. - */ + /** Simple session implementation that just display some text. */ private class SimpleSessionImpl extends Session { private static final int MSG_SEEK = 1000; private static final int SEEK_DELAY_MS = 300; @@ -118,28 +112,36 @@ public class TestTvInputService extends TvInputService { // The current playback speed rate. private float mSpeed; - private final Handler mHandler = new Handler(Looper.myLooper()) { - @Override - public void handleMessage(Message msg) { - if (msg.what == MSG_SEEK) { - // Actually, this input doesn't play any videos, it just shows the image. - // So we should simulate the playback here by changing the current playback - // position periodically in order to test the time shift. - // If the playback is paused, the current playback position doesn't need to be - // changed. - if (mPausedTimeMs == 0) { - long currentTimeMs = System.currentTimeMillis(); - mCurrentPositionMs += (long) ((currentTimeMs - - mLastCurrentPositionUpdateTimeMs) * mSpeed); - mCurrentPositionMs = Math.max(mRecordStartTimeMs, - Math.min(mCurrentPositionMs, currentTimeMs)); - mLastCurrentPositionUpdateTimeMs = currentTimeMs; + private final Handler mHandler = + new Handler(Looper.myLooper()) { + @Override + public void handleMessage(Message msg) { + if (msg.what == MSG_SEEK) { + // Actually, this input doesn't play any videos, it just shows the + // image. + // So we should simulate the playback here by changing the current + // playback + // position periodically in order to test the time shift. + // If the playback is paused, the current playback position doesn't need + // to be + // changed. + if (mPausedTimeMs == 0) { + long currentTimeMs = System.currentTimeMillis(); + mCurrentPositionMs += + (long) + ((currentTimeMs - mLastCurrentPositionUpdateTimeMs) + * mSpeed); + mCurrentPositionMs = + Math.max( + mRecordStartTimeMs, + Math.min(mCurrentPositionMs, currentTimeMs)); + mLastCurrentPositionUpdateTimeMs = currentTimeMs; + } + sendEmptyMessageDelayed(MSG_SEEK, SEEK_DELAY_MS); + } + super.handleMessage(msg); } - sendEmptyMessageDelayed(MSG_SEEK, SEEK_DELAY_MS); - } - super.handleMessage(msg); - } - }; + }; SimpleSessionImpl(Context context) { super(context); @@ -213,7 +215,8 @@ public class TestTvInputService extends TvInputService { mChannelUri = channelUri; ChannelInfo info = mBackend.getChannelInfo(channelUri); synchronized (mDrawRunnable) { - if (info == null || mChannel == null + if (info == null + || mChannel == null || mChannel.originalNetworkId != info.originalNetworkId) { mCurrentState = null; } @@ -231,8 +234,9 @@ public class TestTvInputService extends TvInputService { Log.i(TAG, "Tuning to " + mChannel); } notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE); - mRecordStartTimeMs = mCurrentPositionMs = mLastCurrentPositionUpdateTimeMs - = System.currentTimeMillis(); + mRecordStartTimeMs = + mCurrentPositionMs = + mLastCurrentPositionUpdateTimeMs = System.currentTimeMillis(); mPausedTimeMs = 0; mHandler.sendEmptyMessageDelayed(MSG_SEEK, SEEK_DELAY_MS); mSpeed = 1; @@ -269,8 +273,8 @@ public class TestTvInputService extends TvInputService { @Override public void onTimeShiftPause() { - mCurrentPositionMs = mPausedTimeMs = mLastCurrentPositionUpdateTimeMs - = System.currentTimeMillis(); + mCurrentPositionMs = + mPausedTimeMs = mLastCurrentPositionUpdateTimeMs = System.currentTimeMillis(); } @Override @@ -283,8 +287,9 @@ public class TestTvInputService extends TvInputService { @Override public void onTimeShiftSeekTo(long timeMs) { mLastCurrentPositionUpdateTimeMs = System.currentTimeMillis(); - mCurrentPositionMs = Math.max(mRecordStartTimeMs, - Math.min(timeMs, mLastCurrentPositionUpdateTimeMs)); + mCurrentPositionMs = + Math.max( + mRecordStartTimeMs, Math.min(timeMs, mLastCurrentPositionUpdateTimeMs)); } @Override @@ -354,14 +359,14 @@ public class TestTvInputService extends TvInputService { } } - private void update(ChannelState oldState, ChannelState newState, - ChannelInfo currentChannel) { + private void update( + ChannelState oldState, ChannelState newState, ChannelInfo currentChannel) { Log.i(TAG, "Updating channel " + currentChannel.number + " state to " + newState); notifyTracksChanged(newState.getTrackInfoList()); if (oldState == null || oldState.getTuneStatus() != newState.getTuneStatus()) { if (newState.getTuneStatus() == ChannelState.TUNE_STATUS_VIDEO_AVAILABLE) { notifyVideoAvailable(); - //TODO handle parental controls. + // TODO handle parental controls. notifyContentAllowed(); setAudioTrack(newState.getSelectedAudioTrackId()); setVideoTrack(newState.getSelectedVideoTrackId()); @@ -379,20 +384,20 @@ public class TestTvInputService extends TvInputService { private class SimpleRecordingSessionImpl extends RecordingSession { private final String[] PROGRAM_PROJECTION = { - Programs.COLUMN_TITLE, - Programs.COLUMN_EPISODE_TITLE, - Programs.COLUMN_SHORT_DESCRIPTION, - Programs.COLUMN_POSTER_ART_URI, - Programs.COLUMN_THUMBNAIL_URI, - Programs.COLUMN_CANONICAL_GENRE, - Programs.COLUMN_CONTENT_RATING, - Programs.COLUMN_START_TIME_UTC_MILLIS, - Programs.COLUMN_END_TIME_UTC_MILLIS, - Programs.COLUMN_VIDEO_WIDTH, - Programs.COLUMN_VIDEO_HEIGHT, - Programs.COLUMN_SEASON_DISPLAY_NUMBER, - Programs.COLUMN_SEASON_TITLE, - Programs.COLUMN_EPISODE_DISPLAY_NUMBER, + Programs.COLUMN_TITLE, + Programs.COLUMN_EPISODE_TITLE, + Programs.COLUMN_SHORT_DESCRIPTION, + Programs.COLUMN_POSTER_ART_URI, + Programs.COLUMN_THUMBNAIL_URI, + Programs.COLUMN_CANONICAL_GENRE, + Programs.COLUMN_CONTENT_RATING, + Programs.COLUMN_START_TIME_UTC_MILLIS, + Programs.COLUMN_END_TIME_UTC_MILLIS, + Programs.COLUMN_VIDEO_WIDTH, + Programs.COLUMN_VIDEO_HEIGHT, + Programs.COLUMN_SEASON_DISPLAY_NUMBER, + Programs.COLUMN_SEASON_TITLE, + Programs.COLUMN_EPISODE_DISPLAY_NUMBER, }; private final String mInputId; @@ -442,8 +447,14 @@ public class TestTvInputService extends TvInputService { long time = System.currentTimeMillis(); if (programHintUri != null) { // Retrieves program info from mProgramHintUri - try (Cursor c = getContentResolver().query(programHintUri, - PROGRAM_PROJECTION, null, null, null)) { + try (Cursor c = + getContentResolver() + .query( + programHintUri, + PROGRAM_PROJECTION, + null, + null, + null)) { if (c != null && c.getCount() > 0) { storeRecordedProgram(c, startTime, endTime); return null; @@ -453,11 +464,19 @@ public class TestTvInputService extends TvInputService { } } // Retrieves the current program - try (Cursor c = getContentResolver().query( - TvContract.buildProgramsUriForChannel(channelUri, startTime, - endTime - startTime < MAX_COMMAND_DELAY ? startTime : - endTime - MAX_COMMAND_DELAY), - PROGRAM_PROJECTION, null, null, null)) { + try (Cursor c = + getContentResolver() + .query( + TvContract.buildProgramsUriForChannel( + channelUri, + startTime, + endTime - startTime < MAX_COMMAND_DELAY + ? startTime + : endTime - MAX_COMMAND_DELAY), + PROGRAM_PROJECTION, + null, + null, + null)) { if (c != null && c.getCount() == 1) { storeRecordedProgram(c, startTime, endTime); return null; @@ -472,10 +491,9 @@ public class TestTvInputService extends TvInputService { private void storeRecordedProgram(Cursor c, long startTime, long endTime) { ContentValues values = new ContentValues(); values.put(RecordedPrograms.COLUMN_INPUT_ID, mInputId); - values.put(RecordedPrograms.COLUMN_CHANNEL_ID, - ContentUris.parseId(channelUri)); - values.put(RecordedPrograms.COLUMN_RECORDING_DURATION_MILLIS, - endTime - startTime); + values.put(RecordedPrograms.COLUMN_CHANNEL_ID, ContentUris.parseId(channelUri)); + values.put( + RecordedPrograms.COLUMN_RECORDING_DURATION_MILLIS, endTime - startTime); if (c != null) { int index = 0; c.moveToNext(); @@ -492,15 +510,15 @@ public class TestTvInputService extends TvInputService { values.put(Programs.COLUMN_VIDEO_HEIGHT, c.getLong(index++)); values.put(Programs.COLUMN_SEASON_DISPLAY_NUMBER, c.getString(index++)); values.put(Programs.COLUMN_SEASON_TITLE, c.getString(index++)); - values.put(Programs.COLUMN_EPISODE_DISPLAY_NUMBER, - c.getString(index++)); + values.put(Programs.COLUMN_EPISODE_DISPLAY_NUMBER, c.getString(index++)); } else { values.put(RecordedPrograms.COLUMN_TITLE, "No program info"); values.put(RecordedPrograms.COLUMN_START_TIME_UTC_MILLIS, startTime); values.put(RecordedPrograms.COLUMN_END_TIME_UTC_MILLIS, endTime); } - Uri uri = getContentResolver() - .insert(TvContract.RecordedPrograms.CONTENT_URI, values); + Uri uri = + getContentResolver() + .insert(TvContract.RecordedPrograms.CONTENT_URI, values); notifyRecordingStopped(uri); } }.execute(); diff --git a/tests/input/src/com/android/tv/testinput/TestTvInputSetupActivity.java b/tests/input/src/com/android/tv/testinput/TestTvInputSetupActivity.java index a793ac71..c9153d1c 100644 --- a/tests/input/src/com/android/tv/testinput/TestTvInputSetupActivity.java +++ b/tests/input/src/com/android/tv/testinput/TestTvInputSetupActivity.java @@ -22,24 +22,17 @@ import android.app.Dialog; import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; -import android.media.tv.TvContract; import android.media.tv.TvInputInfo; import android.os.Bundle; import android.util.Log; - -import com.android.tv.testing.ChannelInfo; -import com.android.tv.testing.ChannelUtils; -import com.android.tv.testing.Constants; -import com.android.tv.testing.ProgramInfo; -import com.android.tv.testing.ProgramUtils; - -import java.util.ArrayList; +import com.android.tv.common.util.Clock; +import com.android.tv.testing.constants.Constants; +import com.android.tv.testing.data.ChannelInfo; +import com.android.tv.testing.data.ChannelUtils; +import com.android.tv.testing.data.ProgramUtils; import java.util.List; -import java.util.Map; -/** - * The setup activity for {@link TestTvInputService}. - */ +/** The setup activity for {@link TestTvInputService}. */ public class TestTvInputSetupActivity extends Activity { private static final String TAG = "TestTvInputSetup"; private String mInputId; @@ -60,45 +53,41 @@ public class TestTvInputSetupActivity extends Activity { public static void registerChannels(Context context, String inputId, int channelCount) { Log.i(TAG, "Registering " + channelCount + " channels"); - List<ChannelInfo> channels = new ArrayList<>(); - for (int i = 1; i <= channelCount; i++) { - channels.add(ChannelInfo.create(context, i)); - } + List<ChannelInfo> channels = ChannelUtils.createChannelInfos(context, channelCount); ChannelUtils.updateChannels(context, inputId, channels); - - // Reload channels so we have the ids. - Map<Long, ChannelInfo> channelIdToInfoMap = - ChannelUtils.queryChannelInfoMapForTvInput(context, inputId); - for (Long channelId : channelIdToInfoMap.keySet()) { - ProgramInfo programInfo = ProgramInfo.create(); - ProgramUtils.populatePrograms(context, TvContract.buildChannelUri(channelId), - programInfo); - } + ProgramUtils.updateProgramForAllChannelsOf( + context, inputId, Clock.SYSTEM, ProgramUtils.PROGRAM_INSERT_DURATION_MS); } public static class MyAlertDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - return new AlertDialog.Builder(getActivity()).setTitle(R.string.simple_setup_title) + return new AlertDialog.Builder(getActivity()) + .setTitle(R.string.simple_setup_title) .setMessage(R.string.simple_setup_message) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - // TODO: add UI to ask how many channels - ((TestTvInputSetupActivity) getActivity()) - .registerChannels(Constants.UNIT_TEST_CHANNEL_COUNT); - // Sets the results so that the application can process the - // registered channels properly. - getActivity().setResult(Activity.RESULT_OK); - getActivity().finish(); - } - }).setNegativeButton(android.R.string.cancel, + .setPositiveButton( + android.R.string.ok, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + // TODO: add UI to ask how many channels + ((TestTvInputSetupActivity) getActivity()) + .registerChannels(Constants.UNIT_TEST_CHANNEL_COUNT); + // Sets the results so that the application can process the + // registered channels properly. + getActivity().setResult(Activity.RESULT_OK); + getActivity().finish(); + } + }) + .setNegativeButton( + android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { getActivity().finish(); } - }).create(); + }) + .create(); } } } diff --git a/tests/input/src/com/android/tv/testinput/instrument/TestSetupInstrumentation.java b/tests/input/src/com/android/tv/testinput/instrument/TestSetupInstrumentation.java index 48e485c5..a4bd45c0 100644 --- a/tests/input/src/com/android/tv/testinput/instrument/TestSetupInstrumentation.java +++ b/tests/input/src/com/android/tv/testinput/instrument/TestSetupInstrumentation.java @@ -21,22 +21,24 @@ import android.app.Instrumentation; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; - -import com.android.tv.testing.Constants; +import com.android.tv.testing.constants.Constants; import com.android.tv.testinput.TestTvInputService; import com.android.tv.testinput.TestTvInputSetupActivity; /** - * An instrumentation utility to set up the needed inputs, channels, programs and other settings - * for automated unit tests. + * An instrumentation utility to set up the needed inputs, channels, programs and other settings for + * automated unit tests. + * + * <p> * - * <p><pre>{@code + * <pre>{@code * adb shell am instrument \ * -e testSetupMode {func,jank,unit} \ * -w com.android.tv.testinput/.instrument.TestSetupInstrumentation * }</pre> * * <p>Optional arguments are: + * * <pre> * -e channelCount number * </pre> @@ -82,23 +84,26 @@ public class TestSetupInstrumentation extends Instrumentation { private void setup() throws TestSetupException { final String testSetupMode = mArguments.getString(TEST_SETUP_MODE_ARG); if (TextUtils.isEmpty(testSetupMode)) { - Log.i(TAG, "Performing no setup actions because " + TEST_SETUP_MODE_ARG - + " was not passed as an argument"); + Log.i( + TAG, + "Performing no setup actions because " + + TEST_SETUP_MODE_ARG + + " was not passed as an argument"); } else { Log.i(TAG, "Running setup for " + testSetupMode + " tests."); int channelCount; switch (testSetupMode) { case "func": - channelCount = getArgumentAsInt(CHANNEL_COUNT_ARG, - Constants.FUNC_TEST_CHANNEL_COUNT); + channelCount = + getArgumentAsInt(CHANNEL_COUNT_ARG, Constants.FUNC_TEST_CHANNEL_COUNT); break; case "jank": - channelCount = getArgumentAsInt(CHANNEL_COUNT_ARG, - Constants.JANK_TEST_CHANNEL_COUNT); + channelCount = + getArgumentAsInt(CHANNEL_COUNT_ARG, Constants.JANK_TEST_CHANNEL_COUNT); break; case "unit": - channelCount = getArgumentAsInt(CHANNEL_COUNT_ARG, - Constants.UNIT_TEST_CHANNEL_COUNT); + channelCount = + getArgumentAsInt(CHANNEL_COUNT_ARG, Constants.UNIT_TEST_CHANNEL_COUNT); break; default: throw new TestSetupException( @@ -114,8 +119,14 @@ public class TestSetupInstrumentation extends Instrumentation { try { return Integer.parseInt(stringValue); } catch (NumberFormatException e) { - Log.w(TAG, "Unable to parse arg " + arg + " with value " + stringValue - + " to a integer.", e); + Log.w( + TAG, + "Unable to parse arg " + + arg + + " with value " + + stringValue + + " to a integer.", + e); } } return defaultValue; |