1 /* 2 * Copyright (C) 2023 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.internal.foldables; 18 19 import android.content.res.Resources; 20 import android.os.Build; 21 import android.sysprop.FoldLockBehaviorProperties; 22 import android.util.Slog; 23 24 import com.android.internal.R; 25 import com.android.internal.foldables.flags.Flags; 26 27 import java.util.function.Supplier; 28 29 /** 30 * Wrapper class to access {@link FoldLockBehaviorProperties} and also assists with testing 31 */ 32 public class FoldLockSettingAvailabilityProvider { 33 34 private static final String TAG = "FoldLockSettingAvailabilityProvider"; 35 private final boolean mFoldLockBehaviorResourceValue; 36 private final Supplier<Boolean> mFoldLockSettingEnabled = Flags::foldLockSettingEnabled; 37 FoldLockSettingAvailabilityProvider(Resources resources)38 public FoldLockSettingAvailabilityProvider(Resources resources) { 39 mFoldLockBehaviorResourceValue = resources.getBoolean( 40 R.bool.config_fold_lock_behavior); 41 } 42 isFoldLockBehaviorAvailable()43 public boolean isFoldLockBehaviorAvailable() { 44 return mFoldLockBehaviorResourceValue 45 && flagOrSystemProperty(); 46 } 47 flagOrSystemProperty()48 private boolean flagOrSystemProperty() { 49 if ((Build.IS_ENG || Build.IS_USERDEBUG) 50 && FoldLockBehaviorProperties.fold_lock_setting_enabled().orElse(false)) { 51 return true; 52 } 53 try { 54 return mFoldLockSettingEnabled.get(); 55 } catch (Throwable ex) { 56 Slog.i(TAG, 57 "Flags not ready yet. Return false for " 58 + Flags.FLAG_FOLD_LOCK_SETTING_ENABLED, 59 ex); 60 return false; 61 } 62 } 63 } 64