iamr0s / Dhizuku-API

API of Dhizuku.
MIT License
97 stars 12 forks source link

setTime #8

Closed diabl0w closed 2 months ago

diabl0w commented 7 months ago

Hi, running your demo-binder wrapper, I replaced one of the buttons to run the following code

boolean success = false;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
   success = devicePolicyManager.setTime(DhizukuVariables.COMPONENT_NAME, 1230681600000L);
}
Toast.makeText(this, String.valueOf(success), Toast.LENGTH_LONG);

but when executing I get the following error:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.app.admin.DevicePolicyManager.setTime(android.content.ComponentName, long)' on a null object reference
diabl0w commented 7 months ago

EDIT: actually the demo gives that error without any changes for all of the functions in the demo

iamr0s commented 2 months ago

请附上工程文件

diabl0w commented 2 months ago

I don't think the demo exists anymore and the root issue was resolved using UserService:

public class UserService extends IUserService.Stub{
    private Context context;
    private DevicePolicyManager devicePolicyManager;

    public UserService(Context context) {
        this.context = context;
        devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    }

    @Override
    public void set_time(long x) {
        devicePolicyManager.setTime(DhizukuVariables.COMPONENT_NAME, x);
    }
iamr0s commented 2 months ago

其它接口能否正常使用

diabl0w commented 2 months ago

其它接口能否正常使用

Sorry, I don't understand. If you are asking about method, I can only get it to work via UserService as it required DhizukuVariables.COMPONENT_NAME & getSystemService(Context.DEVICE_POLICY_SERVICE)