3535import android .content .pm .PackageManager ;
3636import android .content .pm .ResolveInfo ;
3737import android .content .pm .ServiceInfo ;
38- import android .content .res .Resources ;
3938import android .database .Cursor ;
4039import android .graphics .Rect ;
4140import android .hardware .hdmi .HdmiDeviceInfo ;
@@ -283,7 +282,6 @@ private void buildTvInputListLocked(int userId) {
283282 userState .inputMap .clear ();
284283 userState .inputMap = inputMap ;
285284
286- Resources r = Resources .getSystem ();
287285 userState .ratingSystemXmlUriSet .clear ();
288286 userState .ratingSystemXmlUriSet .add (TvContentRating .SYSTEM_CONTENT_RATING_SYSTEM_XML );
289287 for (TvInputState state : userState .inputMap .values ()) {
@@ -1262,6 +1260,7 @@ public void tune(IBinder sessionToken, final Uri channelUri, Bundle params, int
12621260 args .arg1 = sessionState .mLogUri ;
12631261 args .arg2 = ContentUris .parseId (channelUri );
12641262 args .arg3 = currentTime ;
1263+ args .arg4 = sessionState ;
12651264 mLogHandler .obtainMessage (LogHandler .MSG_OPEN_ENTRY , args ).sendToTarget ();
12661265 } catch (RemoteException e ) {
12671266 Slog .e (TAG , "error in tune" , e );
@@ -2076,7 +2075,8 @@ public void handleMessage(Message msg) {
20762075 Uri uri = (Uri ) args .arg1 ;
20772076 long channelId = (long ) args .arg2 ;
20782077 long time = (long ) args .arg3 ;
2079- onOpenEntry (uri , channelId , time );
2078+ SessionState sessionState = (SessionState ) args .arg4 ;
2079+ onOpenEntry (uri , channelId , time , sessionState );
20802080 args .recycle ();
20812081 return ;
20822082 }
@@ -2085,7 +2085,8 @@ public void handleMessage(Message msg) {
20852085 Uri uri = (Uri ) args .arg1 ;
20862086 long channelId = (long ) args .arg2 ;
20872087 long time = (long ) args .arg3 ;
2088- onUpdateEntry (uri , channelId , time );
2088+ SessionState sessionState = (SessionState ) args .arg4 ;
2089+ onUpdateEntry (uri , channelId , time , sessionState );
20892090 args .recycle ();
20902091 return ;
20912092 }
@@ -2104,7 +2105,17 @@ public void handleMessage(Message msg) {
21042105 }
21052106 }
21062107
2107- private void onOpenEntry (Uri uri , long channelId , long watchStarttime ) {
2108+ private void onOpenEntry (Uri logUri , long channelId , long watchStarttime ,
2109+ SessionState sessionState ) {
2110+ if (!isChannelSearchable (channelId )) {
2111+ // Do not log anything about non-searchable channels.
2112+ synchronized (mLock ) {
2113+ sessionState .mLogUri = null ;
2114+ }
2115+ mContentResolver .delete (logUri , null , null );
2116+ return ;
2117+ }
2118+
21082119 String [] projection = {
21092120 TvContract .Programs .COLUMN_TITLE ,
21102121 TvContract .Programs .COLUMN_START_TIME_UTC_MILLIS ,
@@ -2132,11 +2143,11 @@ private void onOpenEntry(Uri uri, long channelId, long watchStarttime) {
21322143 long endTime = cursor .getLong (2 );
21332144 values .put (TvContract .WatchedPrograms .COLUMN_END_TIME_UTC_MILLIS , endTime );
21342145 values .put (TvContract .WatchedPrograms .COLUMN_DESCRIPTION , cursor .getString (3 ));
2135- mContentResolver .update (uri , values , null , null );
2146+ mContentResolver .update (logUri , values , null , null );
21362147
21372148 // Schedule an update when the current program ends.
21382149 SomeArgs args = SomeArgs .obtain ();
2139- args .arg1 = uri ;
2150+ args .arg1 = logUri ;
21402151 args .arg2 = channelId ;
21412152 args .arg3 = endTime ;
21422153 Message msg = obtainMessage (LogHandler .MSG_UPDATE_ENTRY , args );
@@ -2149,7 +2160,7 @@ private void onOpenEntry(Uri uri, long channelId, long watchStarttime) {
21492160 }
21502161 }
21512162
2152- private void onUpdateEntry (Uri uri , long channelId , long time ) {
2163+ private void onUpdateEntry (Uri uri , long channelId , long time , SessionState sessionState ) {
21532164 String [] projection = {
21542165 TvContract .WatchedPrograms .COLUMN_WATCH_START_TIME_UTC_MILLIS ,
21552166 TvContract .WatchedPrograms .COLUMN_WATCH_END_TIME_UTC_MILLIS ,
@@ -2193,14 +2204,34 @@ private void onUpdateEntry(Uri uri, long channelId, long time) {
21932204 }
21942205 }
21952206 // Re-open the current log entry with the next program information.
2196- onOpenEntry (uri , channelId , time );
2207+ onOpenEntry (uri , channelId , time , sessionState );
21972208 }
21982209
21992210 private void onCloseEntry (Uri uri , long watchEndTime ) {
22002211 ContentValues values = new ContentValues ();
22012212 values .put (TvContract .WatchedPrograms .COLUMN_WATCH_END_TIME_UTC_MILLIS , watchEndTime );
22022213 mContentResolver .update (uri , values , null , null );
22032214 }
2215+
2216+ private boolean isChannelSearchable (long channelId ) {
2217+ String [] projection = { TvContract .Channels .COLUMN_SEARCHABLE };
2218+ String selection = TvContract .Channels ._ID + "=?" ;
2219+ String [] selectionArgs = { String .valueOf (channelId ) };
2220+ Cursor cursor = null ;
2221+ try {
2222+ cursor = mContentResolver .query (TvContract .Channels .CONTENT_URI , projection ,
2223+ selection , selectionArgs , null );
2224+ if (cursor != null && cursor .moveToNext ()) {
2225+ return cursor .getLong (0 ) == 1 ? true : false ;
2226+ }
2227+ } finally {
2228+ if (cursor != null ) {
2229+ cursor .close ();
2230+ }
2231+ }
2232+ // Unless explicitly specified non-searchable, by default the channel is searchable.
2233+ return true ;
2234+ }
22042235 }
22052236
22062237 final class HardwareListener implements TvInputHardwareManager .Listener {
0 commit comments