Merge "Bug 5045498 Keep track of RemoteControlClient play state change time" into ics-factoryrom
This commit is contained in:
committed by
Android (Google) Code Review
commit
9c43016b52
@@ -35,6 +35,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemClock;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
@@ -59,6 +60,7 @@ public class TransportControlView extends FrameLayout implements OnClickListener
|
||||
private static final int MSG_SET_ARTWORK = 103;
|
||||
private static final int MSG_SET_GENERATION_ID = 104;
|
||||
private static final int MAXDIM = 512;
|
||||
private static final int DISPLAY_TIMEOUT_MS = 5000; // 5s
|
||||
protected static final boolean DEBUG = true;
|
||||
protected static final String TAG = "TransportControlView";
|
||||
|
||||
@@ -142,7 +144,7 @@ public class TransportControlView extends FrameLayout implements OnClickListener
|
||||
mLocalHandler = new WeakReference<Handler>(handler);
|
||||
}
|
||||
|
||||
public void setPlaybackState(int generationId, int state) {
|
||||
public void setPlaybackState(int generationId, int state, long stateChangeTimeMs) {
|
||||
Handler handler = mLocalHandler.get();
|
||||
if (handler != null) {
|
||||
handler.obtainMessage(MSG_UPDATE_STATE, generationId, state).sendToTarget();
|
||||
@@ -401,4 +403,33 @@ public class TransportControlView extends FrameLayout implements OnClickListener
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean wasPlayingRecently(int state, long stateChangeTimeMs) {
|
||||
switch (state) {
|
||||
case RemoteControlClient.PLAYSTATE_PLAYING:
|
||||
case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
|
||||
case RemoteControlClient.PLAYSTATE_REWINDING:
|
||||
case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
|
||||
case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
|
||||
case RemoteControlClient.PLAYSTATE_BUFFERING:
|
||||
// actively playing or about to play
|
||||
return true;
|
||||
case RemoteControlClient.PLAYSTATE_NONE:
|
||||
return false;
|
||||
case RemoteControlClient.PLAYSTATE_STOPPED:
|
||||
case RemoteControlClient.PLAYSTATE_PAUSED:
|
||||
case RemoteControlClient.PLAYSTATE_ERROR:
|
||||
// we have stopped playing, check how long ago
|
||||
if (DEBUG) {
|
||||
if ((SystemClock.elapsedRealtime() - stateChangeTimeMs) < DISPLAY_TIMEOUT_MS) {
|
||||
Log.v(TAG, "wasPlayingRecently: time < TIMEOUT was playing recently");
|
||||
} else {
|
||||
Log.v(TAG, "wasPlayingRecently: time > TIMEOUT");
|
||||
}
|
||||
}
|
||||
return ((SystemClock.elapsedRealtime() - stateChangeTimeMs) < DISPLAY_TIMEOUT_MS);
|
||||
default:
|
||||
Log.e(TAG, "Unknown playback state " + state + " in wasPlayingRecently()");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ oneway interface IRemoteControlDisplay
|
||||
void setCurrentClientId(int clientGeneration, in PendingIntent clientMediaIntent,
|
||||
boolean clearing);
|
||||
|
||||
void setPlaybackState(int generationId, int state);
|
||||
void setPlaybackState(int generationId, int state, long stateChangeTimeMs);
|
||||
|
||||
void setTransportControlFlags(int generationId, int transportControlFlags);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.IllegalArgumentException;
|
||||
@@ -494,11 +495,15 @@ public class RemoteControlClient
|
||||
*/
|
||||
public void setPlaybackState(int state) {
|
||||
synchronized(mCacheLock) {
|
||||
// store locally
|
||||
mPlaybackState = state;
|
||||
if (mPlaybackState != state) {
|
||||
// store locally
|
||||
mPlaybackState = state;
|
||||
// keep track of when the state change occurred
|
||||
mPlaybackStateChangeTimeMs = SystemClock.elapsedRealtime();
|
||||
|
||||
// send to remote control display if conditions are met
|
||||
sendPlaybackState_syncCacheLock();
|
||||
// send to remote control display if conditions are met
|
||||
sendPlaybackState_syncCacheLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,6 +538,11 @@ public class RemoteControlClient
|
||||
* Access synchronized on mCacheLock
|
||||
*/
|
||||
private int mPlaybackState = PLAYSTATE_NONE;
|
||||
/**
|
||||
* Time of last play state change
|
||||
* Access synchronized on mCacheLock
|
||||
*/
|
||||
private long mPlaybackStateChangeTimeMs = 0;
|
||||
/**
|
||||
* Cache for the artwork bitmap.
|
||||
* Access synchronized on mCacheLock
|
||||
@@ -716,7 +726,8 @@ public class RemoteControlClient
|
||||
private void sendPlaybackState_syncCacheLock() {
|
||||
if ((mCurrentClientGenId == mInternalClientGenId) && (mRcDisplay != null)) {
|
||||
try {
|
||||
mRcDisplay.setPlaybackState(mInternalClientGenId, mPlaybackState);
|
||||
mRcDisplay.setPlaybackState(mInternalClientGenId, mPlaybackState,
|
||||
mPlaybackStateChangeTimeMs);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error in setPlaybackState(), dead display "+e);
|
||||
detachFromDisplay_syncCacheLock();
|
||||
|
||||
Reference in New Issue
Block a user