1 /*
2  * Copyright (C) 2021 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.bedstead.dpmwrapper;
17 
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Process;
22 import android.util.Log;
23 
24 /**
25  * {@link BroadcastReceiver} used to run {@link android.app.admin.DevicePolicyManager} methods in
26  * the DPC running in the device owner user.
27  *
28  * <p>Used in cases where the test app doesn't "naturally" have a {@link DeviceAdminReceiver} (for
29  * example, when it uses a {@link android.app.admin.DelegatedAdminReceiver}).
30  *
31  * <p>It must be declared in the manifest:
32    <pre><code>
33    <receiver android:name="com.android.bedstead.dpmwrapper.IpcBroadcastReceiver"
34              android:exported="true">
35    </code></pre>
36  */
37 // TODO(b/176993670): remove when DpmWrapper IPC mechanism changes
38 public final class IpcBroadcastReceiver extends BroadcastReceiver {
39 
40     private static final String TAG = IpcBroadcastReceiver.class.getSimpleName();
41 
42     @Override
onReceive(Context context, Intent intent)43     public void onReceive(Context context, Intent intent) {
44         Log.i(TAG, "onReceive(" + Process.myUserHandle() + "): " + Utils.toString(intent));
45         DeviceOwnerHelper.runManagerMethod(this, context, intent);
46     }
47 }
48