I am wanting to create a custom AOSP image (based on Android 11) that includes modifications that modify behavior of core OS functions (think parental controls).
Since I'm an AOSP newbie, as a proof of concept, I created a custom system service (compiled along other aosp system services in framework/base/services/core/java/com/android/server/*). It is started in startBootstrapServices via the SystemServiceRegistry. Anyway, this service exposes one method which will try and lock the screen (a privileged operation). Code example below:
public class PocService extends IPocServiceManagerAidlInterface.Stub {
private final static String LOG_TAG = "PocService";
private final Context mContext;
PocService(Context context) {
mContext = context;
}
@Override
public void lock() throws RemoteException {
Slog.i(LOG_TAG,"PocService UID: " + android.os.Process.myUid());
DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(DevicePolicyManager.class);
dpm.lockNow();
}
}
My user application gets the system service and invokes the method like so:
...
PocServiceManager pocServiceManager = (PocServiceManager)getSystemService(Context.POC_SERVICE);
pocServiceManager.lock();
...
This results in an exception with the following relevant portions:
...
Caused by: java.lang.SecurityException: No active admin owned by uid 10136 for policy #3
...
...
Caused by: android.os.RemoteException: Remote stack trace:
...
at com.android.server.devicepolicy.DevicePolicyManagerService.getActiveAdminOrCheckPermissionForCallerLocked(DevicePolicyManagerService.java:3326)
at com.android.server.devicepolicy.DevicePolicyManagerService.lockNow(DevicePolicyManagerService.java:6053)
...
The UID of the POC system service is 1000 (according to the log print), and the user app is 10136.
Is there a way that I can invoke privileged operations in my custom aosp system service, which in turn I can expose an API to my user application to be able to use?