aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/recommendation
diff options
context:
space:
mode:
authorLive Channels Team <no-reply@google.com>2018-01-11 20:42:01 -0800
committerNick Chalko <nchalko@google.com>2018-01-16 11:04:29 -0800
commit4a5144ac8c51c4d89d1359e13e37fcd7f928ed9a (patch)
tree9137148fbca9b8cb1b35c4553efc921e5027ffda /src/com/android/tv/recommendation
parente0fd52bbc36ec38397cdac345e42dd23ab093899 (diff)
downloadTV-4a5144ac8c51c4d89d1359e13e37fcd7f928ed9a.tar.gz
Project import generated by Copybara.
PiperOrigin-RevId: 181700159 Change-Id: I7bae213f26b690c0d76189c08abd85d7f7b304a3
Diffstat (limited to 'src/com/android/tv/recommendation')
-rw-r--r--src/com/android/tv/recommendation/ChannelPreviewUpdater.java15
-rw-r--r--src/com/android/tv/recommendation/ChannelRecord.java14
-rw-r--r--src/com/android/tv/recommendation/NotificationService.java18
-rw-r--r--src/com/android/tv/recommendation/RecommendationDataManager.java7
-rw-r--r--src/com/android/tv/recommendation/RecordedProgramPreviewUpdater.java13
5 files changed, 35 insertions, 32 deletions
diff --git a/src/com/android/tv/recommendation/ChannelPreviewUpdater.java b/src/com/android/tv/recommendation/ChannelPreviewUpdater.java
index d332e18a..5da802c4 100644
--- a/src/com/android/tv/recommendation/ChannelPreviewUpdater.java
+++ b/src/com/android/tv/recommendation/ChannelPreviewUpdater.java
@@ -28,8 +28,8 @@ import android.support.annotation.RequiresApi;
import android.support.media.tv.TvContractCompat;
import android.text.TextUtils;
import android.util.Log;
-import com.android.tv.ApplicationSingletons;
-import com.android.tv.TvApplication;
+import com.android.tv.Starter;
+import com.android.tv.TvSingletons;
import com.android.tv.data.Channel;
import com.android.tv.data.PreviewDataManager;
import com.android.tv.data.PreviewProgramContent;
@@ -46,8 +46,7 @@ import java.util.concurrent.TimeUnit;
@RequiresApi(Build.VERSION_CODES.O)
public class ChannelPreviewUpdater {
private static final String TAG = "ChannelPreviewUpdater";
- // STOPSHIP: set it to false.
- private static final boolean DEBUG = true;
+ private static final boolean DEBUG = false;
private static final int UPATE_PREVIEW_PROGRAMS_JOB_ID = 1000001;
private static final long ROUTINE_INTERVAL_MS = TimeUnit.MINUTES.toMillis(10);
@@ -100,10 +99,10 @@ public class ChannelPreviewUpdater {
mRecommender.registerEvaluator(new RandomEvaluator(), 0.1, 0.1);
mRecommender.registerEvaluator(new FavoriteChannelEvaluator(), 0.5, 0.5);
mRecommender.registerEvaluator(new RoutineWatchEvaluator(), 1.0, 1.0);
- ApplicationSingletons appSingleton = TvApplication.getSingletons(context);
- mPreviewDataManager = appSingleton.getPreviewDataManager();
+ TvSingletons tvSingleton = TvSingletons.getSingletons(context);
+ mPreviewDataManager = tvSingleton.getPreviewDataManager();
mParentalControlSettings =
- appSingleton.getTvInputManagerHelper().getParentalControlSettings();
+ tvSingleton.getTvInputManagerHelper().getParentalControlSettings();
}
/** Starts the routine service for updating the preview programs. */
@@ -294,7 +293,7 @@ public class ChannelPreviewUpdater {
@Override
public void onCreate() {
- TvApplication.setCurrentRunningProcess(this, true);
+ Starter.start(this);
if (DEBUG) Log.d(TAG, "ChannelPreviewUpdateService.onCreate");
mChannelPreviewUpdater = ChannelPreviewUpdater.getInstance(this);
}
diff --git a/src/com/android/tv/recommendation/ChannelRecord.java b/src/com/android/tv/recommendation/ChannelRecord.java
index 812b9d3f..34679452 100644
--- a/src/com/android/tv/recommendation/ChannelRecord.java
+++ b/src/com/android/tv/recommendation/ChannelRecord.java
@@ -17,8 +17,9 @@
package com.android.tv.recommendation;
import android.content.Context;
+import android.support.annotation.GuardedBy;
import android.support.annotation.VisibleForTesting;
-import com.android.tv.TvApplication;
+import com.android.tv.TvSingletons;
import com.android.tv.data.Channel;
import com.android.tv.data.Program;
import com.android.tv.data.ProgramDataManager;
@@ -29,7 +30,10 @@ public class ChannelRecord {
// TODO: decide the value for max history size.
@VisibleForTesting static final int MAX_HISTORY_SIZE = 100;
private final Context mContext;
+
+ @GuardedBy("this")
private final Deque<WatchedProgram> mWatchHistory;
+
private Program mCurrentProgram;
private Channel mChannel;
private long mTotalWatchDurationMs;
@@ -59,7 +63,7 @@ public class ChannelRecord {
mInputRemoved = removed;
}
- public long getLastWatchEndTimeMs() {
+ public synchronized long getLastWatchEndTimeMs() {
WatchedProgram p = mWatchHistory.peekLast();
return (p == null) ? 0 : p.getWatchEndTimeMs();
}
@@ -68,7 +72,7 @@ public class ChannelRecord {
long time = System.currentTimeMillis();
if (mCurrentProgram == null || mCurrentProgram.getEndTimeUtcMillis() < time) {
ProgramDataManager manager =
- TvApplication.getSingletons(mContext).getProgramDataManager();
+ TvSingletons.getSingletons(mContext).getProgramDataManager();
mCurrentProgram = manager.getCurrentProgram(mChannel.getId());
}
return mCurrentProgram;
@@ -78,11 +82,11 @@ public class ChannelRecord {
return mTotalWatchDurationMs;
}
- public final WatchedProgram[] getWatchHistory() {
+ public final synchronized WatchedProgram[] getWatchHistory() {
return mWatchHistory.toArray(new WatchedProgram[mWatchHistory.size()]);
}
- public void logWatchHistory(WatchedProgram p) {
+ public synchronized void logWatchHistory(WatchedProgram p) {
mWatchHistory.offer(p);
mTotalWatchDurationMs += p.getWatchedDurationMs();
if (mWatchHistory.size() > MAX_HISTORY_SIZE) {
diff --git a/src/com/android/tv/recommendation/NotificationService.java b/src/com/android/tv/recommendation/NotificationService.java
index c4b321e1..201bb103 100644
--- a/src/com/android/tv/recommendation/NotificationService.java
+++ b/src/com/android/tv/recommendation/NotificationService.java
@@ -40,10 +40,10 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.SparseLongArray;
import android.view.View;
-import com.android.tv.ApplicationSingletons;
import com.android.tv.MainActivityWrapper.OnCurrentChannelChangeListener;
import com.android.tv.R;
-import com.android.tv.TvApplication;
+import com.android.tv.Starter;
+import com.android.tv.TvSingletons;
import com.android.tv.common.WeakHandler;
import com.android.tv.data.Channel;
import com.android.tv.data.Program;
@@ -122,7 +122,7 @@ public class NotificationService extends Service
@Override
public void onCreate() {
if (DEBUG) Log.d(TAG, "onCreate");
- TvApplication.setCurrentRunningProcess(this, true);
+ Starter.start(this);
super.onCreate();
mCurrentNotificationCount = 0;
mNotificationChannels = new long[NOTIFICATION_COUNT];
@@ -146,17 +146,17 @@ public class NotificationService extends Service
getResources().getDimensionPixelOffset(R.dimen.notif_ch_logo_padding_bottom);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- ApplicationSingletons appSingletons = TvApplication.getSingletons(this);
- mTvInputManagerHelper = appSingletons.getTvInputManagerHelper();
+ TvSingletons tvSingletons = TvSingletons.getSingletons(this);
+ mTvInputManagerHelper = tvSingletons.getTvInputManagerHelper();
mHandlerThread = new HandlerThread("tv notification");
mHandlerThread.start();
mHandler = new NotificationHandler(mHandlerThread.getLooper(), this);
mHandler.sendEmptyMessage(MSG_INITIALIZE_RECOMMENDER);
// Just called for early initialization.
- appSingletons.getChannelDataManager();
- appSingletons.getProgramDataManager();
- appSingletons.getMainActivityWrapper().addOnCurrentChannelChangeListener(this);
+ tvSingletons.getChannelDataManager();
+ tvSingletons.getProgramDataManager();
+ tvSingletons.getMainActivityWrapper().addOnCurrentChannelChangeListener(this);
}
@UiThread
@@ -209,7 +209,7 @@ public class NotificationService extends Service
@Override
public void onDestroy() {
- TvApplication.getSingletons(this)
+ TvSingletons.getSingletons(this)
.getMainActivityWrapper()
.removeOnCurrentChannelChangeListener(this);
if (mRecommender != null) {
diff --git a/src/com/android/tv/recommendation/RecommendationDataManager.java b/src/com/android/tv/recommendation/RecommendationDataManager.java
index 794ca7e2..8e8455fa 100644
--- a/src/com/android/tv/recommendation/RecommendationDataManager.java
+++ b/src/com/android/tv/recommendation/RecommendationDataManager.java
@@ -33,13 +33,13 @@ import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
-import com.android.tv.TvApplication;
+import com.android.tv.TvSingletons;
import com.android.tv.common.WeakHandler;
+import com.android.tv.common.util.PermissionUtils;
import com.android.tv.data.Channel;
import com.android.tv.data.ChannelDataManager;
import com.android.tv.data.Program;
import com.android.tv.data.WatchedHistoryManager;
-import com.android.tv.util.PermissionUtils;
import com.android.tv.util.TvUriMatcher;
import java.util.ArrayList;
import java.util.Collection;
@@ -50,6 +50,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+@SuppressWarnings("TryWithResources") // TODO(b/62143348): remove when error prone check fixed
public class RecommendationDataManager implements WatchedHistoryManager.Listener {
private static final int MSG_START = 1000;
private static final int MSG_STOP = 1001;
@@ -185,7 +186,7 @@ public class RecommendationDataManager implements WatchedHistoryManager.Listener
mHandler = new RecommendationHandler(mHandlerThread.getLooper(), this);
mMainHandler = new RecommendationMainHandler(Looper.getMainLooper(), this);
mContentObserver = new RecommendationContentObserver(mHandler);
- mChannelDataManager = TvApplication.getSingletons(mContext).getChannelDataManager();
+ mChannelDataManager = TvSingletons.getSingletons(mContext).getChannelDataManager();
runOnMainThread(
new Runnable() {
@Override
diff --git a/src/com/android/tv/recommendation/RecordedProgramPreviewUpdater.java b/src/com/android/tv/recommendation/RecordedProgramPreviewUpdater.java
index 2b17c510..edc23c53 100644
--- a/src/com/android/tv/recommendation/RecordedProgramPreviewUpdater.java
+++ b/src/com/android/tv/recommendation/RecordedProgramPreviewUpdater.java
@@ -21,8 +21,7 @@ import android.os.Build;
import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import android.util.Log;
-import com.android.tv.ApplicationSingletons;
-import com.android.tv.TvApplication;
+import com.android.tv.TvSingletons;
import com.android.tv.data.PreviewDataManager;
import com.android.tv.data.PreviewProgramContent;
import com.android.tv.dvr.DvrDataManager;
@@ -34,10 +33,10 @@ import java.util.Set;
/** Class to update the preview data for {@link RecordedProgram} */
@RequiresApi(Build.VERSION_CODES.O)
+@SuppressWarnings("AndroidApiChecker") // TODO(b/32513850) remove when error prone is updated
public class RecordedProgramPreviewUpdater {
private static final String TAG = "RecordedProgramPreviewUpdater";
- // STOPSHIP: set it to false.
- private static final boolean DEBUG = true;
+ private static final boolean DEBUG = false;
private static final int RECOMMENDATION_COUNT = 6;
@@ -58,9 +57,9 @@ public class RecordedProgramPreviewUpdater {
private RecordedProgramPreviewUpdater(Context context) {
mContext = context.getApplicationContext();
- ApplicationSingletons applicationSingletons = TvApplication.getSingletons(mContext);
- mPreviewDataManager = applicationSingletons.getPreviewDataManager();
- mDvrDataManager = applicationSingletons.getDvrDataManager();
+ TvSingletons tvSingletons = TvSingletons.getSingletons(mContext);
+ mPreviewDataManager = tvSingletons.getPreviewDataManager();
+ mDvrDataManager = tvSingletons.getDvrDataManager();
mDvrDataManager.addRecordedProgramListener(
new DvrDataManager.RecordedProgramListener() {
@Override