Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9df1aa5f authored by DvTonder's avatar DvTonder
Browse files

Audioservice: Fix Theme engine support

A few more instances of mVolumePanel.postXXXX had to be enclosed in a
null pointer avoidance wrapper.

Change-Id: I60a0544b5a785417af1ea61e7322b06f2748876b
parent ea28c5a0
Loading
Loading
Loading
Loading
+123 −9
Original line number Diff line number Diff line
@@ -1106,7 +1106,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {

    // UI update and Broadcast Intent
    private void sendMasterVolumeUpdate(int flags, int oldVolume, int newVolume) {
        mVolumePanel.postMasterVolumeChanged(flags);
        masterVolumeChanged(flags);

        Intent intent = new Intent(AudioManager.MASTER_VOLUME_CHANGED_ACTION);
        intent.putExtra(AudioManager.EXTRA_PREV_MASTER_VOLUME_VALUE, oldVolume);
@@ -1116,7 +1116,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {

    // UI update and Broadcast Intent
    private void sendMasterMuteUpdate(boolean muted, int flags) {
        mVolumePanel.postMasterMuteChanged(flags);
        masterMuteChanged(flags);
        broadcastMasterMuteStatus(muted);
    }

@@ -2313,7 +2313,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                        if (mMusicActiveMs > UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX) {
                            setSafeMediaVolumeEnabled(true);
                            mMusicActiveMs = 0;
                            mVolumePanel.postDisplaySafeVolumeWarning();
                            displaySafeVolumeWarning();
                        }
                    }
                }
@@ -3974,6 +3974,63 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        }
    }

    private void masterVolumeChanged(final int flags) {
        if (mUiContext != null && mVolumePanel != null) {
            mVolumePanel.postMasterVolumeChanged(flags);
        } else {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mUiContext == null) {
                        mUiContext = ThemeUtils.createUiContext(mContext);
                    }

                    final Context context = mUiContext != null ? mUiContext : mContext;
                    mVolumePanel = new VolumePanel(context, AudioService.this);
                    mVolumePanel.postMasterVolumeChanged(flags);
                }
            });
        }
    }

    private void masterMuteChanged(final int flags) {
        if (mUiContext != null && mVolumePanel != null) {
            mVolumePanel.postMasterMuteChanged(flags);
        } else {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mUiContext == null) {
                        mUiContext = ThemeUtils.createUiContext(mContext);
                    }

                    final Context context = mUiContext != null ? mUiContext : mContext;
                    mVolumePanel = new VolumePanel(context, AudioService.this);
                    mVolumePanel.postMasterMuteChanged(flags);
                }
            });
        }
    }

    private void remoteSliderVisibility(final boolean hasRemotePlayback) {
        if (mUiContext != null && mVolumePanel != null) {
            mVolumePanel.postRemoteSliderVisibility(hasRemotePlayback);
        } else {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mUiContext == null) {
                        mUiContext = ThemeUtils.createUiContext(mContext);
                    }

                    final Context context = mUiContext != null ? mUiContext : mContext;
                    mVolumePanel = new VolumePanel(context, AudioService.this);
                    mVolumePanel.postRemoteSliderVisibility(hasRemotePlayback);
                }
            });
        }
    }

    private void showVolumeChangeUi(final int streamType, final int flags) {
        if (mUiContext != null && mVolumePanel != null) {
            mVolumePanel.postVolumeChanged(streamType, flags);
@@ -3993,6 +4050,63 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        }
    }

    private void remoteVolumeChanged(final int streamType, final int flags) {
        if (mUiContext != null && mVolumePanel != null) {
            mVolumePanel.postRemoteVolumeChanged(streamType, flags);
        } else {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mUiContext == null) {
                        mUiContext = ThemeUtils.createUiContext(mContext);
                    }

                    final Context context = mUiContext != null ? mUiContext : mContext;
                    mVolumePanel = new VolumePanel(context, AudioService.this);
                    mVolumePanel.postRemoteVolumeChanged(streamType, flags);
                }
            });
        }
    }

    private void displaySafeVolumeWarning() {
        if (mUiContext != null && mVolumePanel != null) {
            mVolumePanel.postDisplaySafeVolumeWarning();
        } else {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mUiContext == null) {
                        mUiContext = ThemeUtils.createUiContext(mContext);
                    }

                    final Context context = mUiContext != null ? mUiContext : mContext;
                    mVolumePanel = new VolumePanel(context, AudioService.this);
                    mVolumePanel.postDisplaySafeVolumeWarning();
                }
            });
        }
    }

    private void hasNewRemotePlaybackInfo() {
        if (mUiContext != null && mVolumePanel != null) {
            mVolumePanel.postHasNewRemotePlaybackInfo();
        } else {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (mUiContext == null) {
                        mUiContext = ThemeUtils.createUiContext(mContext);
                    }

                    final Context context = mUiContext != null ? mUiContext : mContext;
                    mVolumePanel = new VolumePanel(context, AudioService.this);
                    mVolumePanel.postHasNewRemotePlaybackInfo();
                }
            });
        }
    }

    //==========================================================================================
    // AudioFocus
    //==========================================================================================
@@ -5502,7 +5616,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                            synchronized (mMainRemote) {
                                if (rccId == mMainRemote.mRccId) {
                                    mMainRemote.mVolume = value;
                                    mVolumePanel.postHasNewRemotePlaybackInfo();
                                    hasNewRemotePlaybackInfo();
                                }
                            }
                            break;
@@ -5511,7 +5625,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                            synchronized (mMainRemote) {
                                if (rccId == mMainRemote.mRccId) {
                                    mMainRemote.mVolumeMax = value;
                                    mVolumePanel.postHasNewRemotePlaybackInfo();
                                    hasNewRemotePlaybackInfo();
                                }
                            }
                            break;
@@ -5520,7 +5634,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                            synchronized (mMainRemote) {
                                if (rccId == mMainRemote.mRccId) {
                                    mMainRemote.mVolumeHandling = value;
                                    mVolumePanel.postHasNewRemotePlaybackInfo();
                                    hasNewRemotePlaybackInfo();
                                }
                            }
                            break;
@@ -5638,7 +5752,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        }

        // fire up the UI
        mVolumePanel.postRemoteVolumeChanged(streamType, flags);
        remoteVolumeChanged(streamType, flags);
    }

    private void sendVolumeUpdateToRemote(int rccId, int direction) {
@@ -5742,7 +5856,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        synchronized (mMainRemote) {
            if (mHasRemotePlayback != hasRemotePlayback) {
                mHasRemotePlayback = hasRemotePlayback;
                mVolumePanel.postRemoteSliderVisibility(hasRemotePlayback);
                remoteSliderVisibility(hasRemotePlayback);
            }
        }
    }
@@ -5977,7 +6091,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                    (mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) &&
                    ((device & mSafeMediaVolumeDevices) != 0) &&
                    (index > mSafeMediaVolumeIndex)) {
                mVolumePanel.postDisplaySafeVolumeWarning();
                displaySafeVolumeWarning();
                return false;
            }
            return true;