• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, 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 package com.android.managedprovisioning.manageduser;
17 
18 import static java.util.Objects.requireNonNull;
19 
20 import android.content.Context;
21 import android.os.UserHandle;
22 
23 import com.android.internal.annotations.VisibleForTesting;
24 import com.android.managedprovisioning.common.ProvisionLogger;
25 import com.android.managedprovisioning.task.nonrequiredapps.SystemAppsSnapshot;
26 
27 /**
28  * After a managed user is created, take a system app snapshot.
29  */
30 // TODO(b/178711424): move this into the framework.
31 public class ManagedUserCreationController {
32 
33     final private SystemAppsSnapshot mSystemAppsSnapshot;
34     final private int mUserId;
35     final private boolean mLeaveAllSystemAppsEnabled;
36 
ManagedUserCreationController(int userId, boolean leaveAllSystemAppsEnabled, Context context)37     public ManagedUserCreationController(int userId, boolean leaveAllSystemAppsEnabled,
38             Context context) {
39         this(userId, leaveAllSystemAppsEnabled, new SystemAppsSnapshot(context));
40     }
41 
42     @VisibleForTesting
ManagedUserCreationController(int userId, boolean leaveAllSystemAppsEnabled, SystemAppsSnapshot systemAppsSnapshot)43     ManagedUserCreationController(int userId, boolean leaveAllSystemAppsEnabled,
44             SystemAppsSnapshot systemAppsSnapshot) {
45         mUserId = userId;
46         mLeaveAllSystemAppsEnabled = leaveAllSystemAppsEnabled;
47         mSystemAppsSnapshot = requireNonNull(systemAppsSnapshot);
48     }
49 
run()50     public void run() {
51         if (mUserId == UserHandle.USER_NULL) {
52             ProvisionLogger.loge("Missing userId.");
53             return;
54         }
55         if (!mLeaveAllSystemAppsEnabled) {
56             mSystemAppsSnapshot.takeNewSnapshot(mUserId);
57         }
58     }
59 }
60