Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove @SuppressLint("RestrictedApi") #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -143,8 +143,6 @@ object WatchNextHelper {
/**
* Retrieve all programs in Watch Next row.
*/
@SuppressLint("RestrictedApi")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the referenced library is restricted, so this lint suppression is needed here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removal can be merged now that bug #138150076 has been resolved.

// Suppress RestrictedApi due to https://issuetracker.google.com/138150076
internal fun getWatchNextPrograms(context: Context): List<WatchNextProgram> {
val programs: MutableList<WatchNextProgram> = mutableListOf()
val cursor = context.contentResolver.query(
Expand All @@ -169,8 +167,6 @@ object WatchNextHelper {
* Add unfinished program to Watch Next.
* Update the playback position if program already exists in Watch Next channel.
*/
@SuppressLint("RestrictedApi")
// Suppress RestrictedApi due to https://issuetracker.google.com/138150076
@Synchronized
internal fun insertOrUpdateVideoToWatchNext(
video: Video,
Expand Down Expand Up @@ -247,8 +243,6 @@ object WatchNextHelper {
* Returns the number of rows deleted or null if delete fails
*/
@Synchronized
@SuppressLint("RestrictedApi")
// Suppress RestrictedApi due to https://issuetracker.google.com/138150076
fun removeVideoFromWatchNext(context: Context, video: Video): Uri? {
Timber.v("Trying to Removing content from Watch Next: ${video.name}")

Expand Down Expand Up @@ -280,8 +274,6 @@ object WatchNextHelper {
}

@Synchronized
@SuppressLint("RestrictedApi")
// Suppress RestrictedApi due to https://issuetracker.google.com/138150076
fun removeVideosFromWatchNext(context: Context, videos: List<Video>) {
// Find the program with the matching ID for our metadata.
val foundPrograms = getWatchNextProgramByVideoIds(videos.map { it.id }, context)
Expand Down Expand Up @@ -311,8 +303,6 @@ object WatchNextHelper {
}

@Synchronized
@SuppressLint("RestrictedApi")
// Suppress RestrictedApi due to https://issuetracker.google.com/138150076
private fun getWatchNextProgramByVideoIds(ids: List<String>, context: Context):
List<WatchNextProgram> {
return getWatchNextPrograms(context).filter {
Expand All @@ -324,8 +314,6 @@ object WatchNextHelper {
* Find the Watch Next program for given id.
* Returns the first instance available.
*/
@SuppressLint("RestrictedApi")
// Suppress RestrictedApi due to https://issuetracker.google.com/138150076
internal fun findFirstWatchNextProgram(context: Context, predicate: (Cursor) -> Boolean):
WatchNextProgram? {

Expand All @@ -351,7 +339,6 @@ object WatchNextHelper {
/**
* Returns a list of videos which is visible on Watch Next row.
*/
@SuppressLint("RestrictedApi")
internal fun filterWatchNextVideos(videos: List<Video>, context: Context): List<Video> {
val watchedPrograms = getWatchNextProgramByVideoIds(videos.map { it.id }, context)
val watchedVideosIds = watchedPrograms.map { it.internalProviderId }
Expand Down
Expand Up @@ -39,8 +39,6 @@ class WatchNextWorker(private val context: Context, params: WorkerParameters) :
* Events triggered from player state change events &
* playback lifecycle events (onPause) are consumed here.
*/
@SuppressLint("RestrictedApi")
// Suppress RestrictedApi due to https://b.corp.google.com/issues/138150076
override fun doWork(): Result {

// Step 1 : get the video information from the "inputData".
Expand Down
Expand Up @@ -398,20 +398,24 @@ class WatchNextTest {
// Insert a new row.
rowId++

val programBuilder = WatchNextProgram.Builder()
.setId(rowId)
.setTitle(values?.getAsString(TvContractCompat.WatchNextPrograms.COLUMN_TITLE))
.setInternalProviderId(
values?.getAsString(
TvContractCompat.WatchNextPrograms
.COLUMN_INTERNAL_PROVIDER_ID
)
)
.setLastPlaybackPositionMillis(
values!!.getAsInteger(
TvContractCompat.WatchNextPrograms.COLUMN_LAST_PLAYBACK_POSITION_MILLIS
)
)
val programBuilder =
values?.getAsString(TvContractCompat.WatchNextPrograms.COLUMN_TITLE)?.let {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this refactoring? Reading the value first and providing it as a lambda is more difficult to understand, in my opinion.

WatchNextProgram.Builder()
.setId(rowId)
.setTitle(it)
.setInternalProviderId(
values.getAsString(
TvContractCompat.WatchNextPrograms
.COLUMN_INTERNAL_PROVIDER_ID
)
)
.setLastPlaybackPositionMillis(
values!!.getAsInteger(
TvContractCompat.WatchNextPrograms.COLUMN_LAST_PLAYBACK_POSITION_MILLIS
)
)
}


values.getAsInteger(
TvContractCompat.WatchNextPrograms.COLUMN_SEASON_DISPLAY_NUMBER
Expand Down Expand Up @@ -483,26 +487,31 @@ class WatchNextTest {
): Int {
val id = uri.lastPathSegment?.toLong() ?: return 0

val program = WatchNextProgram.Builder()
.setId(id)
.setTitle(values?.getAsString(TvContractCompat.WatchNextPrograms.COLUMN_TITLE))
.setInternalProviderId(
values?.getAsString(
TvContractCompat
.WatchNextPrograms.COLUMN_INTERNAL_PROVIDER_ID
val program = values?.getAsString(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here as above.

TvContractCompat
.WatchNextPrograms.COLUMN_INTERNAL_PROVIDER_ID
)?.let {
WatchNextProgram.Builder()
.setId(id)
.setTitle(values.getAsString(TvContractCompat.WatchNextPrograms.COLUMN_TITLE))
.setInternalProviderId(
it
)
)
.setLastPlaybackPositionMillis(
values!!.getAsInteger(
TvContractCompat.WatchNextPrograms.COLUMN_LAST_PLAYBACK_POSITION_MILLIS
.setLastPlaybackPositionMillis(
values.getAsInteger(
TvContractCompat.WatchNextPrograms.COLUMN_LAST_PLAYBACK_POSITION_MILLIS
)

)
)
.build()
.build()
}

// Since kotlin collections don't directly provide a replace function, for testing
// purpose, remove existing and add new entry to avoid complexity.
this.valuesInMemory.removeIf { it.id == id }
this.valuesInMemory.add(program)
if (program != null) {
this.valuesInMemory.add(program)
}
return 1
}

Expand Down