@@ -195,19 +195,19 @@ public List<PreviewChannel> getAllChannels() {
195
195
return Collections .emptyList ();
196
196
}
197
197
198
- Cursor cursor = mContext .getContentResolver ()
198
+ List <PreviewChannel > channels = new ArrayList <>();
199
+ try (Cursor cursor = mContext .getContentResolver ()
199
200
.query (
200
201
TvContractCompat .Channels .CONTENT_URI ,
201
202
PreviewChannel .Columns .PROJECTION ,
202
203
null ,
203
204
null ,
204
- null );
205
-
206
- List <PreviewChannel > channels = new ArrayList <>();
207
- if (cursor != null && cursor .moveToFirst ()) {
208
- do {
209
- channels .add (PreviewChannel .fromCursor (cursor ));
210
- } while (cursor .moveToNext ());
205
+ null )) {
206
+ if (cursor != null && cursor .moveToFirst ()) {
207
+ do {
208
+ channels .add (PreviewChannel .fromCursor (cursor ));
209
+ } while (cursor .moveToNext ());
210
+ }
211
211
}
212
212
return channels ;
213
213
}
@@ -228,10 +228,15 @@ public PreviewChannel getPreviewChannel(long channelId) {
228
228
229
229
PreviewChannel channel = null ;
230
230
Uri channelUri = TvContractCompat .buildChannelUri (channelId );
231
- Cursor cursor = mContext .getContentResolver ()
232
- .query (channelUri , PreviewChannel .Columns .PROJECTION , null , null , null );
233
- if (cursor != null && cursor .moveToFirst ()) {
234
- channel = PreviewChannel .fromCursor (cursor );
231
+ try (Cursor cursor = mContext .getContentResolver ()
232
+ .query (channelUri ,
233
+ PreviewChannel .Columns .PROJECTION ,
234
+ null ,
235
+ null ,
236
+ null )) {
237
+ if (cursor != null && cursor .moveToFirst ()) {
238
+ channel = PreviewChannel .fromCursor (cursor );
239
+ }
235
240
}
236
241
return channel ;
237
242
}
@@ -416,9 +421,12 @@ public PreviewProgram getPreviewProgram(long programId) {
416
421
417
422
PreviewProgram program = null ;
418
423
Uri programUri = TvContractCompat .buildPreviewProgramUri (programId );
419
- Cursor cursor = mContext .getContentResolver ().query (programUri , null , null , null , null );
420
- if (cursor != null && cursor .moveToFirst ()) {
421
- program = PreviewProgram .fromCursor (cursor );
424
+ try (Cursor cursor = mContext .getContentResolver ()
425
+ .query (programUri , null , null , null , null );
426
+ ) {
427
+ if (cursor != null && cursor .moveToFirst ()) {
428
+ program = PreviewProgram .fromCursor (cursor );
429
+ }
422
430
}
423
431
return program ;
424
432
}
@@ -492,9 +500,12 @@ public WatchNextProgram getWatchNextProgram(long programId) {
492
500
493
501
WatchNextProgram program = null ;
494
502
Uri programUri = TvContractCompat .buildWatchNextProgramUri (programId );
495
- Cursor cursor = mContext .getContentResolver ().query (programUri , null , null , null , null );
496
- if (cursor != null && cursor .moveToFirst ()) {
497
- program = WatchNextProgram .fromCursor (cursor );
503
+ try (Cursor cursor = mContext .getContentResolver ()
504
+ .query (programUri , null , null , null , null )
505
+ ) {
506
+ if (cursor != null && cursor .moveToFirst ()) {
507
+ program = WatchNextProgram .fromCursor (cursor );
508
+ }
498
509
}
499
510
return program ;
500
511
}
0 commit comments