• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.devicelockcontroller.debug;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Build;
23 import android.os.UserManager;
24 import android.text.TextUtils;
25 
26 import com.android.devicelockcontroller.policy.DevicePolicyController;
27 import com.android.devicelockcontroller.policy.DeviceStateController;
28 import com.android.devicelockcontroller.policy.PolicyObjectsInterface;
29 import com.android.devicelockcontroller.provision.worker.DeviceCheckInHelper;
30 import com.android.devicelockcontroller.util.LogUtil;
31 
32 /**
33  * Broadcast receiver which can start the setup flow.
34  */
35 public final class SetupFlowStarter extends BroadcastReceiver {
36 
37     private static final String TAG = "SetupFlowStarter";
38     private static final String EXTRA_IS_MANDATORY = "is-mandatory";
39 
40     @Override
onReceive(Context context, Intent intent)41     public void onReceive(Context context, Intent intent) {
42         if (!Build.isDebuggable()) {
43             LogUtil.w(TAG, "Adb command is not supported in non-debuggable build!");
44             return;
45         }
46 
47         if (!TextUtils.equals(intent.getComponent().getClassName(),
48                 SetupFlowStarter.class.getName())) {
49             LogUtil.w(TAG, "Implicit intent should not be used!");
50             return;
51         }
52 
53         final boolean isUserProfile =
54                 context.getSystemService(UserManager.class).isProfile();
55         if (isUserProfile) {
56             LogUtil.w(TAG, "Broadcast should not target user profiles");
57             return;
58         }
59 
60         PolicyObjectsInterface policyObjects =
61                 (PolicyObjectsInterface) context.getApplicationContext();
62         DevicePolicyController devicePolicyController = policyObjects.getPolicyController();
63         DeviceStateController deviceStateController = policyObjects.getStateController();
64 
65         DeviceCheckInHelper.setProvisionSucceeded(deviceStateController, devicePolicyController,
66                 context, intent.getBooleanExtra(EXTRA_IS_MANDATORY, /* defaultValue= */ true));
67     }
68 }
69