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.os.Build;
20 import android.sysprop.FoldLockBehaviorProperties;
21 import android.util.Slog;
22 
23 import com.android.internal.foldables.flags.Flags;
24 
25 import java.util.function.Supplier;
26 
27 /**
28  * Wrapper class to access {@link FoldLockBehaviorProperties}.
29  */
30 public class FoldGracePeriodProvider {
31 
32     private static final String TAG = "FoldGracePeriodProvider";
33     private final Supplier<Boolean> mFoldGracePeriodEnabled = Flags::foldGracePeriodEnabled;
34 
35     /**
36      * Whether the fold grace period feature is enabled.
37      */
isEnabled()38     public boolean isEnabled() {
39         if ((Build.IS_ENG || Build.IS_USERDEBUG)
40                 && FoldLockBehaviorProperties.fold_grace_period_enabled().orElse(false)) {
41             return true;
42         }
43         try {
44             return mFoldGracePeriodEnabled.get();
45         } catch (Throwable ex) {
46             Slog.i(TAG,
47                     "Flags not ready yet. Return false for "
48                             + Flags.FLAG_FOLD_GRACE_PERIOD_ENABLED,
49                     ex);
50             return false;
51         }
52     }
53 }
54