diff options
author | Nick Chalko <nchalko@google.com> | 2015-08-03 15:39:56 -0700 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2015-08-03 15:53:37 -0700 |
commit | 816a4be1a0f34f6a48877c8afd3dbbca19eac435 (patch) | |
tree | 4f18dda269764494942f5313acc93db4a35d47db /tests/common/src/com/android/tv/testing/testinput | |
parent | 6edd2b09e5d16a29c703a5fcbd2e88c5cf5e55b7 (diff) | |
download | TV-816a4be1a0f34f6a48877c8afd3dbbca19eac435.tar.gz |
Migrate Live Channels App Src to AOSP branch
Bug: 21625152
Change-Id: I07e2830b27440556dc757e6340b4f77d1c0cbc66
Diffstat (limited to 'tests/common/src/com/android/tv/testing/testinput')
7 files changed, 357 insertions, 0 deletions
diff --git a/tests/common/src/com/android/tv/testing/testinput/ChannelState.java b/tests/common/src/com/android/tv/testing/testinput/ChannelState.java new file mode 100644 index 00000000..3d234dac --- /dev/null +++ b/tests/common/src/com/android/tv/testing/testinput/ChannelState.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2015 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 com.android.tv.testing.testinput; + +import android.media.tv.TvTrackInfo; + +import com.android.tv.testing.Constants; + +import java.util.Collections; +import java.util.List; + +/** + * Versioned state information for a channel. + */ +public class ChannelState { + + /** + * The video track a channel has by default. + */ + public static TvTrackInfo DEFAULT_VIDEO_TRACK = Constants.FHD1080P50_VIDEO_TRACK; + /** + * The video track a channel has by default. + */ + public static TvTrackInfo DEFAULT_AUDIO_TRACK = Constants.EN_STEREO_AUDIO_TRACK; + /** + * The channel is "tuned" and video availale. + * + * @see #getTuneStatus() + */ + public static int TUNE_STATUS_VIDEO_AVAILABLE = -2; + + private static int CHANNEL_VERSION_DEFAULT = 1; + /** + * Default ChannelState with version @{value #CHANNEL_VERSION_DEFAULT} and default {@link + * ChannelStateData}. + */ + public static final ChannelState DEFAULT = new ChannelState(CHANNEL_VERSION_DEFAULT, + new ChannelStateData()); + private final int mVersion; + private final ChannelStateData mData; + + + private ChannelState(int version, ChannelStateData channelStateData) { + mVersion = version; + mData = channelStateData; + } + + /** + * Returns the id of the selected audio track, or null if none is selected. + */ + public String getSelectedAudioTrackId() { + return mData.mSelectedAudioTrackId; + } + + /** + * Returns the id of the selected audio track, or null if none is selected. + */ + public String getSelectedVideoTrackId() { + return mData.mSelectedVideoTrackId; + } + + /** + * The current version. Larger version numbers are newer. + * + * <p>The version is increased by {@link #next(ChannelStateData)}. + */ + public int getVersion() { + return mVersion; + } + + /** + * Tune status is either {@link #TUNE_STATUS_VIDEO_AVAILABLE} or a {@link + * android.media.tv.TvInputService.Session#notifyVideoUnavailable(int) video unavailable + * reason} + */ + public int getTuneStatus() { + return mData.mTuneStatus; + } + + /** + * An unmodifiable list of TvTrackInfo for a channel, suitable for {@link + * android.media.tv.TvInputService.Session#notifyTracksChanged(List)} + */ + public List<TvTrackInfo> getTrackInfoList() { + return Collections.unmodifiableList(mData.mTvTrackInfos); + } + + @Override + public String toString() { + return "v" + mVersion + ":" + mData; + } + + /** + * Creates a new ChannelState, with an incremented version and {@code data} provided. + * + * @param data the data for the new ChannelState + */ + public ChannelState next(ChannelStateData data) { + return new ChannelState(mVersion + 1, data); + } +} diff --git a/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.aidl b/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.aidl new file mode 100644 index 00000000..cdf43adb --- /dev/null +++ b/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.aidl @@ -0,0 +1,3 @@ +package com.android.tv.testing.testinput; + +parcelable ChannelStateData; diff --git a/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.java b/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.java new file mode 100644 index 00000000..9bac9d12 --- /dev/null +++ b/tests/common/src/com/android/tv/testing/testinput/ChannelStateData.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2015 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 com.android.tv.testing.testinput; + +import android.media.tv.TvTrackInfo; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; +import java.util.List; + +/** + * Mutable unversioned channel state. + */ +public final class ChannelStateData implements Parcelable { + public static final Creator<ChannelStateData> CREATOR = new Creator<ChannelStateData>() { + @Override + public ChannelStateData createFromParcel(Parcel in) { + return new ChannelStateData(in); + } + + @Override + public ChannelStateData[] newArray(int size) { + return new ChannelStateData[size]; + } + }; + + public final List<TvTrackInfo> mTvTrackInfos = new ArrayList<>(); + public int mTuneStatus = ChannelState.TUNE_STATUS_VIDEO_AVAILABLE; + public String mSelectedAudioTrackId = ChannelState.DEFAULT_AUDIO_TRACK.getId(); + public String mSelectedVideoTrackId = ChannelState.DEFAULT_VIDEO_TRACK.getId(); + + public ChannelStateData() { + mTvTrackInfos.add(ChannelState.DEFAULT_VIDEO_TRACK); + mTvTrackInfos.add(ChannelState.DEFAULT_AUDIO_TRACK); + } + + private ChannelStateData(Parcel in) { + mTuneStatus = in.readInt(); + in.readTypedList(mTvTrackInfos, TvTrackInfo.CREATOR); + mSelectedAudioTrackId = in.readString(); + mSelectedVideoTrackId = in.readString(); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(mTuneStatus); + dest.writeTypedList(mTvTrackInfos); + dest.writeString(mSelectedAudioTrackId); + dest.writeString(mSelectedVideoTrackId); + } + + @Override + public String toString() { + return "{" + + "tune=" + mTuneStatus + + ", tracks=" + mTvTrackInfos + + "}"; + } +} diff --git a/tests/common/src/com/android/tv/testing/testinput/ITestInputControl.aidl b/tests/common/src/com/android/tv/testing/testinput/ITestInputControl.aidl new file mode 100644 index 00000000..a82f378b --- /dev/null +++ b/tests/common/src/com/android/tv/testing/testinput/ITestInputControl.aidl @@ -0,0 +1,9 @@ +package com.android.tv.testing.testinput; + + +import com.android.tv.testing.testinput.ChannelStateData; + +/** Remote interface for controlling the test TV Input Service */ +interface ITestInputControl { + void updateChannelState(int origId, in ChannelStateData data); +} diff --git a/tests/common/src/com/android/tv/testing/testinput/TestInputControlConnection.java b/tests/common/src/com/android/tv/testing/testinput/TestInputControlConnection.java new file mode 100644 index 00000000..9b3f8835 --- /dev/null +++ b/tests/common/src/com/android/tv/testing/testinput/TestInputControlConnection.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2015 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 com.android.tv.testing.testinput; + +import android.content.ComponentName; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.os.RemoteException; +import android.os.SystemClock; +import android.util.Log; + +import com.android.tv.testing.ChannelInfo; + +/** + * Connection for controlling the Test TV Input Service. + * + * <p>Wrapped methods for calling {@link ITestInputControl} that waits for a binding and rethrows + * {@link RemoteException} as {@link RuntimeException } are also included. + */ +public class TestInputControlConnection implements ServiceConnection { + private static final String TAG = "TestInputControlConn"; + private static final int BOUND_CHECK_INTERVAL_MS = 10; + + private ITestInputControl mControl; + + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + mControl = ITestInputControl.Stub.asInterface(service); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + Log.w(TAG, "TestInputControl service disconnected unexpectedly."); + mControl = null; + } + + /** + * Is the service currently connected. + */ + public boolean isBound() { + return mControl != null; + } + + /** + * Update the state of the channel. + * + * @param channel the channel to update. + * @param data the new state for the channel. + */ + public void updateChannelState(ChannelInfo channel, ChannelStateData data) { + waitUntilBound(); + try { + mControl.updateChannelState(channel.originalNetworkId, data); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } + + /** + * Sleep until {@link #isBound()} is true; + */ + public void waitUntilBound() { + while (!isBound()) { + SystemClock.sleep(BOUND_CHECK_INTERVAL_MS); + } + } +} diff --git a/tests/common/src/com/android/tv/testing/testinput/TestInputControlUtils.java b/tests/common/src/com/android/tv/testing/testinput/TestInputControlUtils.java new file mode 100644 index 00000000..54aacf20 --- /dev/null +++ b/tests/common/src/com/android/tv/testing/testinput/TestInputControlUtils.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 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 com.android.tv.testing.testinput; + +import android.content.ComponentName; +import android.content.Intent; + +/** + * Static utils for {@link ITestInputControl}. + */ +public final class TestInputControlUtils { + + public static Intent createIntent() { + return new Intent().setComponent(new ComponentName("com.android.tv.testinput", + "com.android.tv.testinput.TestInputControlService")); + } + + private TestInputControlUtils() { + } +} diff --git a/tests/common/src/com/android/tv/testing/testinput/TvTestInputConstants.java b/tests/common/src/com/android/tv/testing/testinput/TvTestInputConstants.java new file mode 100644 index 00000000..e7ff4f5d --- /dev/null +++ b/tests/common/src/com/android/tv/testing/testinput/TvTestInputConstants.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2015 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 com.android.tv.testing.testinput; + +import com.android.tv.testing.ChannelInfo; + +/** + * Constants for interacting with TvTestInput. + */ +public final class TvTestInputConstants { + + /** + * Channel 1. + * + * <p> By convention Channel 1 should not be changed. Test often start by tuning to this + * channel. + */ + public static final ChannelInfo CH_1 = ChannelInfo.create(null, 1); + /** + * Channel 2. + * + * <p> By convention the state of Channel 2 is changed by tests. Testcases should explicitly + * set the state of this channel before using it in tests. + */ + public static final ChannelInfo CH_2 = ChannelInfo.create(null, 2); +} |