Skip to content

Commit 579befe

Browse files
author
Jae Seo
committed
TIF: Do not log non-searchable channel watch history
Bug: 16798476 Change-Id: Ic131009ad65a661331e4f8f0820c5c183a9f4986
1 parent ae267d2 commit 579befe

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

media/java/android/media/tv/TvContract.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.content.ComponentName;
2121
import android.content.ContentResolver;
2222
import android.content.ContentUris;
23+
import android.media.tv.TvContract.Programs;
2324
import android.net.Uri;
2425
import android.provider.BaseColumns;
2526
import android.util.ArraySet;
@@ -684,10 +685,11 @@ public static final String getVideoResolution(String videoFormat) {
684685
* The flag indicating whether this TV channel is searchable or not.
685686
* <p>
686687
* In some regions, it is not allowed to surface search results for a given channel without
687-
* broadcaster's consent. This is used to impose such restriction. A value of 1 indicates
688-
* the channel is searchable and can be included in search results, a value of 0 indicates
689-
* the channel and its TV programs are hidden from search. If not specified, this value is
690-
* set to 1 (searchable) by default.
688+
* broadcaster's consent. This is used to impose such restriction. Channels marked with
689+
* "not searchable" cannot be used by other services except for the system service that
690+
* shows the TV content. A value of 1 indicates the channel is searchable and can be
691+
* included in search results, a value of 0 indicates the channel and its TV programs are
692+
* hidden from search. If not specified, this value is set to 1 (searchable) by default.
691693
* </p><p>
692694
* Type: INTEGER (boolean)
693695
* </p>

services/core/java/com/android/server/tv/TvInputManagerService.java

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import android.content.pm.PackageManager;
3636
import android.content.pm.ResolveInfo;
3737
import android.content.pm.ServiceInfo;
38-
import android.content.res.Resources;
3938
import android.database.Cursor;
4039
import android.graphics.Rect;
4140
import 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

Comments
 (0)