• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 package com.android.car.developeroptions.display;
15 
16 import android.content.Context;
17 import android.hardware.display.ColorDisplayManager;
18 import android.os.UserHandle;
19 import android.provider.Settings.Secure;
20 import androidx.annotation.VisibleForTesting;
21 
22 import com.android.car.developeroptions.core.TogglePreferenceController;
23 
24 public class DisplayWhiteBalancePreferenceController extends TogglePreferenceController {
25 
26     private ColorDisplayManager mColorDisplayManager;
27 
DisplayWhiteBalancePreferenceController(Context context, String key)28     public DisplayWhiteBalancePreferenceController(Context context, String key) {
29         super(context, key);
30     }
31 
32     @Override
getAvailabilityStatus()33     public int getAvailabilityStatus() {
34         // Display white balance is only valid in linear light space. COLOR_MODE_SATURATED implies
35         // unmanaged color mode, and hence unknown color processing conditions.
36         return ColorDisplayManager.isDisplayWhiteBalanceAvailable(mContext) &&
37                 getColorDisplayManager().getColorMode() !=
38                         ColorDisplayManager.COLOR_MODE_SATURATED ?
39                 AVAILABLE : DISABLED_FOR_USER;
40     }
41 
42     @Override
isChecked()43     public boolean isChecked() {
44         return getColorDisplayManager().isDisplayWhiteBalanceEnabled();
45     }
46 
47     @Override
setChecked(boolean isChecked)48     public boolean setChecked(boolean isChecked) {
49         return getColorDisplayManager().setDisplayWhiteBalanceEnabled(isChecked);
50     }
51 
52     @VisibleForTesting
getColorDisplayManager()53     ColorDisplayManager getColorDisplayManager() {
54         if (mColorDisplayManager == null) {
55             mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class);
56         }
57         return mColorDisplayManager;
58     }
59 }
60