android 11 自定义Android device owner 接口

在设置里面自定义广播 去处理下面的事情

 ComponentName mComponent=new ComponentName(packageName,receiverName);

DevicePolicyManager mDPM.setDeviceOwner(mComponent,"d_owner_"+mUserId);

      int  mUserId = android.os.Process.myPid();
      int uid = android.os.Process.myUid();
      Settings.Global.putInt(context.getContentResolver(), "cw_dpw_userid", mUserId);

然后在frameworks\base\services\devicepolicy\java\com\android\server\devicepolicy\DevicePolicyManagerService.java

下面的方法修改下

 private boolean isAdb() {
        final int callingUid = mInjector.binderGetCallingUid();
        boolean isdpwuid = false;
         try {
            final int callingPid = mInjector.binderGetCallingPid();
            int cw_dpw= Settings.Global.getInt(mContext.getContentResolver(), "cw_dpw_userid",0);
            isdpwuid = (callingPid == cw_dpw ) ;
            Log.w(LOG_TAG, "sssssssssss 3 callingPid = " +callingPid  + "........cw_dpw_userid = " +cw_dpw  +  "------isdpwuid= "+isdpwuid);
          } catch (Exception e) {
            return false;
        }
        return callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID || isdpwuid;
    }

你可能感兴趣的:(android)