Dismiss system dialog is working in some devices and not others I am developing a security app which will prevent mobile phones from powering off (phones with in-built battery). I found stackoverflow very usefull in starting the project but there's a problem in below code.
 This code is working on Android Emulator and my brother's phone Motorola X Play but It is neither working in my phone Xiaomi MI 5 nor in my friend's phone Xiaomi MI4i
Problem is:
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
is not working in my phone, so, power off menu is not dismissed
and what is more hectic is this code used to work around 2-3 weeks ago in every phone.
Pls someone help me through this so that i can continue developing my project so that i can contribute to one step towards safety of our mobile devices
thanks in advance :)
MainActivity.java
public class MainActivity extends AppCompatActivity {

public final static int REQUEST_CODE = 10101;

Handler H;
Runnable Run;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (checkDrawOverlayPermission()) {
startService(new Intent(this, MyService.class));
    }
}

public boolean checkDrawOverlayPermission() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
    }
    if (!Settings.canDrawOverlays(this)) {
/** if not construct intent to request permission */
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
/** request permission via start activity for result */
startActivityForResult(intent, REQUEST_CODE);
return false;
    } else {
return true;
    }
}

@Override
@TargetApi(Build.VERSION_CODES.M)
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE) {
if (Settings.canDrawOverlays(this)) {
startService(new Intent(this, MyService.class));
}
    }
}

}

MyService.java
public class MyService extends Service {
@Override
public void onCreate() {
    super.onCreate();
    Toast.makeText(getApplicationContext(),"Service Running",Toast.LENGTH_LONG).show();
    LinearLayout mLinear = new LinearLayout(getApplicationContext()) {

//home or recent button
public void onCloseSystemDialogs(String reason)
{
if ("globalactions".equals(reason)) {
Log.i("","Long press on power button");

KeyguardManager kgm = (KeyguardManager) getSystemService(getApplicationContext().KEYGUARD_SERVICE);
if(kgm.isKeyguardLocked()) {
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}
}
}
    };
    mLinear.setFocusable(true);
    View mView = LayoutInflater.from(this).inflate(R.layout.service_layout, mLinear);
    WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(
0,
0,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN  | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
    mParams.gravity =  Gravity.CENTER | Gravity.TOP;
    mWindowManager.addView(mView, mParams);
}
@Override
public IBinder onBind(Intent intent) {
    return null;
}
}