1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.tv.hdmi;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.IntentFilter;
23 import android.hardware.hdmi.HdmiControlManager;
24 import android.os.Bundle;
25 import android.view.View;
26 import android.view.WindowManager;
27 import android.widget.Button;
28 import android.widget.ImageView;
29 import android.widget.TextView;
30 
31 import com.android.systemui.tv.TvBottomSheetActivity;
32 import com.android.systemui.tv.res.R;
33 
34 /**
35  * Confirmation dialog shown when the device loses active source. Gives the user the option to keep
36  * the device active, in case the loss of active source was due to a misleading CEC message from a
37  * faulty device.
38  */
39 public class HdmiCecActiveSourceLostActivity extends TvBottomSheetActivity
40         implements View.OnClickListener {
41     private HdmiControlManager mHdmiControlManager;
42 
43     @Override
onCreate(Bundle b)44     public final void onCreate(Bundle b) {
45         super.onCreate(b);
46         mHdmiControlManager =
47                 (HdmiControlManager)
48                         getApplicationContext().getSystemService(Context.HDMI_CONTROL_SERVICE);
49         getWindow()
50                 .addPrivateFlags(
51                         WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
52 
53         OnActiveSourceRecoveredBroadcastReceiver onActiveSourceRecoveredBroadcastReceiver =
54                 new OnActiveSourceRecoveredBroadcastReceiver();
55         IntentFilter filter =
56                 new IntentFilter(HdmiControlManager.ACTION_ON_ACTIVE_SOURCE_RECOVERED_DISMISS_UI);
57         getApplicationContext()
58                 .registerReceiver(
59                         onActiveSourceRecoveredBroadcastReceiver,
60                         filter,
61                         Context.RECEIVER_EXPORTED);
62         initUI();
63     }
64 
65     @Override
onClick(View v)66     public void onClick(View v) {
67         if (v.getId() == R.id.bottom_sheet_negative_button) {
68             mHdmiControlManager.setPowerStateChangeOnActiveSourceLost(
69                     HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_NONE);
70         }
71         finish();
72     }
73 
initUI()74     private void initUI() {
75         TextView titleTextView = findViewById(R.id.bottom_sheet_title);
76         TextView contentTextView = findViewById(R.id.bottom_sheet_body);
77         ImageView icon = findViewById(R.id.bottom_sheet_icon);
78         ImageView secondIcon = findViewById(R.id.bottom_sheet_second_icon);
79         Button okButton = findViewById(R.id.bottom_sheet_positive_button);
80         Button cancelButton = findViewById(R.id.bottom_sheet_negative_button);
81 
82         titleTextView.setText(getString(R.string.hdmi_cec_on_active_source_lost_title));
83         contentTextView.setText(getString(R.string.hdmi_cec_on_active_source_lost_description));
84         icon.setImageResource(R.drawable.ic_input_switch);
85         secondIcon.setVisibility(View.GONE);
86 
87         okButton.setText(R.string.hdmi_cec_on_active_source_lost_ok);
88         okButton.setOnClickListener(this);
89         okButton.requestFocus();
90 
91         cancelButton.setText(R.string.hdmi_cec_on_active_source_lost_do_not_show);
92         cancelButton.setOnClickListener(this);
93     }
94 
95     private class OnActiveSourceRecoveredBroadcastReceiver extends BroadcastReceiver {
96         @Override
onReceive(Context context, Intent intent)97         public void onReceive(Context context, Intent intent) {
98             finish();
99         }
100     }
101 }
102