1 /*
2  * Copyright (C) 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 android.app.admin;
17 
18 import android.app.Service;
19 import android.content.ComponentName;
20 import android.content.Intent;
21 import android.os.IBinder;
22 
23 // TODO(b/263363091): Restrict to DPC and holders of a new role permission and update javadocs
24 /**
25  * Base class for a service that device owner/profile owners can optionally have.
26  *
27  * <p>The system searches for it with an intent filter with the
28  * {@link DevicePolicyManager#ACTION_DEVICE_ADMIN_SERVICE} action, and tries to keep a bound
29  * connection as long as the hosting user is running, so that the device/profile owner is always
30  * considered to be in the foreground.  This is useful to receive implicit broadcasts that
31  * can no longer be received by manifest receivers by apps targeting Android version
32  * {@link android.os.Build.VERSION_CODES#O}.  Device/profile owners can use a runtime-registered
33  * broadcast receiver instead, and have a {@link DeviceAdminService} so that the process is always
34  * running.
35  *
36  * <p>Device/profile owners can use
37  * {@link android.content.pm.PackageManager#setComponentEnabledSetting(ComponentName, int, int)}
38  * to disable/enable its own service.  For example, when a device/profile owner no longer needs
39  * to be in the foreground, it can (and should) disable its service.
40  *
41  * <p>The service must be protected with the permission
42  * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.  Otherwise the system would ignore it.
43  *
44  * <p>When the owner process crashes, the service will be re-bound automatically after a
45  * back-off.
46  *
47  * <p>Note the process may still be killed if the system is under heavy memory pressure, in which
48  * case the process will be re-started later.
49  *
50  * <p>Starting from Android {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
51  * non-DPC admins can also optionally implement this service using the details
52  * mentioned above to ensure they receive policy update broadcasts
53  * (see {@link PolicyUpdateReceiver}).
54  */
55 public class DeviceAdminService extends Service {
56     private final IDeviceAdminServiceImpl mImpl;
57 
DeviceAdminService()58     public DeviceAdminService() {
59         mImpl = new IDeviceAdminServiceImpl();
60     }
61 
62     @Override
onBind(Intent intent)63     public final IBinder onBind(Intent intent) {
64         return mImpl.asBinder();
65     }
66 
67     private class IDeviceAdminServiceImpl extends IDeviceAdminService.Stub {
68     }
69 
70     // So far, we have no methods in this class.
71 }
72