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

Commit 67744e46 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add permission check before setMain()" into oc-mr1-dev

parents f5174b2a 60d3925f
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.Rect;
@@ -680,7 +681,8 @@ public class TvView extends ViewGroup {
        // Other app may have shown its own main TvView.
        // Set main again to regain main session.
        synchronized (sMainTvViewLock) {
            if (hasFocus && this == sMainTvView.get() && mSession != null) {
            if (hasFocus && this == sMainTvView.get() && mSession != null
                    && checkChangeHdmiCecActiveSourcePermission()) {
                mSession.setMain();
            }
        }
@@ -848,6 +850,12 @@ public class TvView extends ViewGroup {
        return frame;
    }

    private boolean checkChangeHdmiCecActiveSourcePermission() {
        return getContext().checkSelfPermission(
                android.Manifest.permission.CHANGE_HDMI_CEC_ACTIVE_SOURCE)
                        == PackageManager.PERMISSION_GRANTED;
    }

    /**
     * Callback used to receive time shift position changes.
     */
@@ -1080,7 +1088,8 @@ public class TvView extends ViewGroup {
                mPendingAppPrivateCommands.clear();

                synchronized (sMainTvViewLock) {
                    if (hasWindowFocus() && TvView.this == sMainTvView.get()) {
                    if (hasWindowFocus() && TvView.this == sMainTvView.get()
                            && checkChangeHdmiCecActiveSourcePermission()) {
                        mSession.setMain();
                    }
                }