1 /*
2  * Copyright (C) 2022 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.server;
18 
19 import android.content.Context;
20 import android.content.pm.PackageManager;
21 
22 import com.android.internal.util.Preconditions;
23 
24 import java.util.concurrent.atomic.AtomicBoolean;
25 
26 /**
27  * TODO(b/225012970): add javadoc from {@code com.android.server.devicepolicy.FactoryResetter}
28  */
29 public final class FactoryResetter {
30 
31     private static final AtomicBoolean sFactoryResetting = new AtomicBoolean(false);
32 
33     /**
34      * Checks whether a factory reset is in progress.
35      */
isFactoryResetting()36     public static boolean isFactoryResetting() {
37         return sFactoryResetting.get();
38     }
39 
40     /**
41      * @deprecated called by {@code com.android.server.devicepolicy.FactoryResetter}, won't be
42      * needed once that class logic is moved into this.
43      */
44     @Deprecated
setFactoryResetting(Context context)45     public static void setFactoryResetting(Context context) {
46         Preconditions.checkCallAuthorization(context.checkCallingOrSelfPermission(
47                 android.Manifest.permission.MASTER_CLEAR) == PackageManager.PERMISSION_GRANTED);
48         sFactoryResetting.set(true);
49     }
50 
FactoryResetter()51     private FactoryResetter() {
52         throw new UnsupportedOperationException("Provides only static methods");
53     }
54 }
55