Loading core/java/android/provider/Settings.java +7 −0 Original line number Diff line number Diff line Loading @@ -2413,6 +2413,13 @@ public final class Settings { */ public static final String LOCKSCREEN_TARGETS = "lockscreen_targets"; /** * Whether music controls should be shown on the lockscreen if a supporting * music player is active. * @hide */ public static final String LOCKSCREEN_MUSIC_CONTROLS = "lockscreen_music_controls"; /** * @deprecated Use {@link android.provider.Settings.Global#LOW_BATTERY_SOUND} * instead Loading policy/src/com/android/internal/policy/impl/keyguard/KeyguardTransportControlView.java +65 −9 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.PendingIntent; import android.app.PendingIntent.CanceledException; import android.content.Context; import android.content.Intent; import android.database.ContentObserver; import android.graphics.Bitmap; import android.media.AudioManager; import android.media.IRemoteControlDisplay; Loading @@ -32,6 +33,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; import android.text.Spannable; import android.text.TextUtils; import android.text.style.ForegroundColorSpan; Loading Loading @@ -75,6 +78,8 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick private AudioManager mAudioManager; private IRemoteControlDisplayWeak mIRCD; private boolean mMusicClientPresent = true; private boolean mShouldBeShown = true; private boolean mAttachNotified = false; /** * The metadata which should be populated into the view once we've been attached Loading Loading @@ -126,6 +131,20 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick }; private KeyguardHostView.TransportCallback mTransportCallback; private ContentObserver mSettingsObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { updateSettings(); } }; KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { @Override public void onUserSwitched(int userId) { updateSettings(); } }; /** * This class is required to have weak linkage to the current TransportControlView * because the remote process can hold a strong reference to this binder object and Loading Loading @@ -198,20 +217,48 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick protected void onListenerDetached() { mMusicClientPresent = false; if (DEBUG) Log.v(TAG, "onListenerDetached()"); if (mTransportCallback != null) { mTransportCallback.onListenerDetached(); } else { Log.w(TAG, "onListenerDetached: no callback"); } callCallbackIfNeeded(); } private void onListenerAttached() { mMusicClientPresent = true; if (DEBUG) Log.v(TAG, "onListenerAttached()"); if (mTransportCallback != null) { callCallbackIfNeeded(); } private void updateSettings() { boolean oldShown = mShouldBeShown; mShouldBeShown = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.LOCKSCREEN_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) != 0; if (DEBUG) Log.v(TAG, "updateSettings(): mShouldBeShown=" + mShouldBeShown); if (oldShown != mShouldBeShown) { callCallbackIfNeeded(); if (mShouldBeShown && mMusicClientPresent && mCurrentPlayState != RemoteControlClient.PLAYSTATE_NONE) { // send out the play state change event that we suppressed earlier mTransportCallback.onPlayStateChanged(); } } } private void callCallbackIfNeeded() { if (mTransportCallback == null) { Log.w(TAG, "callCallbackIfNeeded: no callback"); return; } boolean shouldBeAttached = mMusicClientPresent && mShouldBeShown; if (DEBUG) { Log.v(TAG, "callCallbackIfNeeded(): shouldBeAttached=" + shouldBeAttached + ", mAttachNotified=" + mAttachNotified); } if (shouldBeAttached && !mAttachNotified) { mTransportCallback.onListenerAttached(); } else { Log.w(TAG, "onListenerAttached(): no callback"); mAttachNotified = true; } else if (!shouldBeAttached && mAttachNotified) { mTransportCallback.onListenerDetached(); mAttachNotified = false; } } Loading Loading @@ -245,6 +292,11 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick if (!mAttached) { if (DEBUG) Log.v(TAG, "Registering TCV " + this); mAudioManager.registerRemoteControlDisplay(mIRCD); KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateCallback); mContext.getContentResolver().registerContentObserver( Settings.System.getUriFor(Settings.System.LOCKSCREEN_MUSIC_CONTROLS), false, mSettingsObserver); updateSettings(); } mAttached = true; } Loading @@ -256,6 +308,8 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick if (mAttached) { if (DEBUG) Log.v(TAG, "Unregistering TCV " + this); mAudioManager.unregisterRemoteControlDisplay(mIRCD); KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateCallback); mContext.getContentResolver().unregisterContentObserver(mSettingsObserver); } mAttached = false; } Loading Loading @@ -381,8 +435,10 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick mBtnPlay.setImageResource(imageResId); mBtnPlay.setContentDescription(getResources().getString(imageDescId)); mCurrentPlayState = state; if (mShouldBeShown) { mTransportCallback.onPlayStateChanged(); } } static class SavedState extends BaseSavedState { boolean clientPresent; Loading Loading
core/java/android/provider/Settings.java +7 −0 Original line number Diff line number Diff line Loading @@ -2413,6 +2413,13 @@ public final class Settings { */ public static final String LOCKSCREEN_TARGETS = "lockscreen_targets"; /** * Whether music controls should be shown on the lockscreen if a supporting * music player is active. * @hide */ public static final String LOCKSCREEN_MUSIC_CONTROLS = "lockscreen_music_controls"; /** * @deprecated Use {@link android.provider.Settings.Global#LOW_BATTERY_SOUND} * instead Loading
policy/src/com/android/internal/policy/impl/keyguard/KeyguardTransportControlView.java +65 −9 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.PendingIntent; import android.app.PendingIntent.CanceledException; import android.content.Context; import android.content.Intent; import android.database.ContentObserver; import android.graphics.Bitmap; import android.media.AudioManager; import android.media.IRemoteControlDisplay; Loading @@ -32,6 +33,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; import android.text.Spannable; import android.text.TextUtils; import android.text.style.ForegroundColorSpan; Loading Loading @@ -75,6 +78,8 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick private AudioManager mAudioManager; private IRemoteControlDisplayWeak mIRCD; private boolean mMusicClientPresent = true; private boolean mShouldBeShown = true; private boolean mAttachNotified = false; /** * The metadata which should be populated into the view once we've been attached Loading Loading @@ -126,6 +131,20 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick }; private KeyguardHostView.TransportCallback mTransportCallback; private ContentObserver mSettingsObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { updateSettings(); } }; KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { @Override public void onUserSwitched(int userId) { updateSettings(); } }; /** * This class is required to have weak linkage to the current TransportControlView * because the remote process can hold a strong reference to this binder object and Loading Loading @@ -198,20 +217,48 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick protected void onListenerDetached() { mMusicClientPresent = false; if (DEBUG) Log.v(TAG, "onListenerDetached()"); if (mTransportCallback != null) { mTransportCallback.onListenerDetached(); } else { Log.w(TAG, "onListenerDetached: no callback"); } callCallbackIfNeeded(); } private void onListenerAttached() { mMusicClientPresent = true; if (DEBUG) Log.v(TAG, "onListenerAttached()"); if (mTransportCallback != null) { callCallbackIfNeeded(); } private void updateSettings() { boolean oldShown = mShouldBeShown; mShouldBeShown = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.LOCKSCREEN_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) != 0; if (DEBUG) Log.v(TAG, "updateSettings(): mShouldBeShown=" + mShouldBeShown); if (oldShown != mShouldBeShown) { callCallbackIfNeeded(); if (mShouldBeShown && mMusicClientPresent && mCurrentPlayState != RemoteControlClient.PLAYSTATE_NONE) { // send out the play state change event that we suppressed earlier mTransportCallback.onPlayStateChanged(); } } } private void callCallbackIfNeeded() { if (mTransportCallback == null) { Log.w(TAG, "callCallbackIfNeeded: no callback"); return; } boolean shouldBeAttached = mMusicClientPresent && mShouldBeShown; if (DEBUG) { Log.v(TAG, "callCallbackIfNeeded(): shouldBeAttached=" + shouldBeAttached + ", mAttachNotified=" + mAttachNotified); } if (shouldBeAttached && !mAttachNotified) { mTransportCallback.onListenerAttached(); } else { Log.w(TAG, "onListenerAttached(): no callback"); mAttachNotified = true; } else if (!shouldBeAttached && mAttachNotified) { mTransportCallback.onListenerDetached(); mAttachNotified = false; } } Loading Loading @@ -245,6 +292,11 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick if (!mAttached) { if (DEBUG) Log.v(TAG, "Registering TCV " + this); mAudioManager.registerRemoteControlDisplay(mIRCD); KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateCallback); mContext.getContentResolver().registerContentObserver( Settings.System.getUriFor(Settings.System.LOCKSCREEN_MUSIC_CONTROLS), false, mSettingsObserver); updateSettings(); } mAttached = true; } Loading @@ -256,6 +308,8 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick if (mAttached) { if (DEBUG) Log.v(TAG, "Unregistering TCV " + this); mAudioManager.unregisterRemoteControlDisplay(mIRCD); KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateCallback); mContext.getContentResolver().unregisterContentObserver(mSettingsObserver); } mAttached = false; } Loading Loading @@ -381,8 +435,10 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick mBtnPlay.setImageResource(imageResId); mBtnPlay.setContentDescription(getResources().getString(imageDescId)); mCurrentPlayState = state; if (mShouldBeShown) { mTransportCallback.onPlayStateChanged(); } } static class SavedState extends BaseSavedState { boolean clientPresent; Loading