• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.settings.qc;
18 
19 import static com.android.car.qc.QCItem.QC_ACTION_TOGGLE_STATE;
20 import static com.android.car.qc.QCItem.QC_TYPE_ACTION_SWITCH;
21 
22 import android.content.Context;
23 import android.content.Intent;
24 import android.net.Uri;
25 import android.sysprop.DisplayProperties;
26 
27 import com.android.car.qc.QCActionItem;
28 import com.android.car.qc.QCItem;
29 import com.android.car.qc.QCList;
30 import com.android.car.qc.QCRow;
31 import com.android.car.settings.R;
32 import com.android.car.settings.common.BuildInfoUtil;
33 import com.android.settingslib.development.DevelopmentSettingsEnabler;
34 import com.android.settingslib.development.SystemPropPoker;
35 
36 /**
37  * Quick control for showing a toggle for the layout bounds.
38  */
39 public class DebugLayoutBoundsRow extends SettingsQCItem {
DebugLayoutBoundsRow(Context context)40     public DebugLayoutBoundsRow(Context context) {
41         super(context);
42     }
43 
44     @Override
getQCItem()45     protected QCItem getQCItem() {
46         if (!BuildInfoUtil.isDevTesting(getContext())
47                 || !DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
48             return null;
49         }
50         QCActionItem actionItem = new QCActionItem.Builder(QC_TYPE_ACTION_SWITCH)
51                 .setChecked(DisplayProperties.debug_layout().orElse(false))
52                 .setAction(getBroadcastIntent())
53                 .build();
54 
55         QCList.Builder listBuilder = new QCList.Builder()
56                 .addRow(new QCRow.Builder()
57                         .setTitle(getContext().getString(R.string.show_layout_bounds_title))
58                         .addEndItem(actionItem)
59                         .build()
60                 );
61         return listBuilder.build();
62     }
63 
64     @Override
onNotifyChange(Intent intent)65     void onNotifyChange(Intent intent) {
66         boolean newState = intent.getBooleanExtra(QC_ACTION_TOGGLE_STATE, /* defaultValue */ false);
67         DisplayProperties.debug_layout(newState);
68         SystemPropPoker.getInstance().poke();
69     }
70 
71 
72 
73     @Override
getUri()74     protected Uri getUri() {
75         return SettingsQCRegistry.DEBUG_LAYOUT_BOUNDS_URI;
76     }
77 
78     @Override
getBackgroundWorkerClass()79     Class getBackgroundWorkerClass() {
80         return DefaultQCBackgroundWorker.class;
81     }
82 }
83