当前位置:   article > 正文

如何远程控制Android手机,为所欲为?

手机里的mdm必须激活吗

一、激活设备管理器

      使用MDM功能要先激活设备管理器

640?wx_fmt=png

代码如下:

  1. /**
  2.      * 激活设备管理权限 成功执行激活时,DeviceAdminReceiver中的 onEnabled 会响应
  3.      */
  4.     private void activeManage() {
  5.         // 启动设备管理(隐式Intent) - 在AndroidManifest.xml中设定相应过滤器
  6.         Intent intents = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
  7.         // 权限列表
  8.         intents.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
  9.         // 描述(additional explanation)
  10.         intents.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
  11.                 "------ 其他描述 ------");
  12.         startActivityForResult(intents, 0);
  13.     }

二、可以远程对设备做哪些操作

要先获得DevicePolicyManager实例才可以进行控制操作

  1. DevicePolicyManager mDPM = (DevicePolicyManager) mContext
  2. .getSystemService(Context.DEVICE_POLICY_SERVICE);

1、控制锁屏

mDPM.lockNow();

2、控制摄像机的使用

  1. @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  2. public int setCameraDisabled(boolean disableCamera) {
  3. if (isDeviceAdminActive()) {
  4. if (API_LEVEL < 14) {
  5. return ERROR_UNSUPPORTED;
  6. }
  7. mDPM.setCameraDisabled(mDeviceAdminSample, disableCamera);
  8. return 0;
  9. } else {
  10. //
  11. activateDeviceAdmin();
  12. return ERROR_UNACTIVATED;
  13. }
  14. }
  15. public boolean getCameraDisabled() {
  16. if (isDeviceAdminActive()) {
  17. if (API_LEVEL < 14) {
  18. return false;
  19. }
  20. return mDPM.getCameraDisabled(mDeviceAdminSample);
  21. } else {
  22. //
  23. activateDeviceAdmin();
  24. return false;
  25. }
  26. }

3、控制密码

  1. public int resetPasswd(String newPasswd) {
  2. if (isDeviceAdminActive()) {
  3. boolean succeed = mDPM.resetPassword(newPasswd,
  4. DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
  5. if (succeed) {
  6. return 0;
  7. } else {
  8. return ERROR_PASSWD_QUALITY;
  9. }
  10. } else {
  11. // 激活时间与用户的操作有关,所以不等待,直接返回操作失败
  12. activateDeviceAdmin();
  13. return ERROR_UNACTIVATED;
  14. }
  15. }
  16. public int setPasswdQuality(int value) {
  17. if (isDeviceAdminActive()) {
  18. if (API_LEVEL < 11) {
  19. return ERROR_UNSUPPORTED;
  20. }
  21. mDPM.setPasswordQuality(mDeviceAdminSample, value);
  22. return 0;
  23. } else {
  24. activateDeviceAdmin();
  25. return ERROR_UNACTIVATED;
  26. }
  27. }
  28. public String getPasswordQuality() {
  29. if (isDeviceAdminActive()) {
  30. int quality = mDPM.getPasswordQuality(mDeviceAdminSample);
  31. switch (quality) {
  32. case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK:
  33. return "图案";
  34. case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
  35. return "数字";
  36. case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
  37. return "字母";
  38. case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
  39. return "数字和字母";
  40. default:
  41. return "其它";
  42. }
  43. } else {
  44. activateDeviceAdmin();
  45. return "未知";
  46. }
  47. }
  48. public int setPasswordMinimumLength(int value) {
  49. if (isDeviceAdminActive()) {
  50. mDPM.setPasswordMinimumLength(mDeviceAdminSample, value);
  51. return 0;
  52. } else {
  53. activateDeviceAdmin();
  54. return ERROR_UNACTIVATED;
  55. }
  56. }
  57. /*
  58. * -1无法获取
  59. */
  60. public int getPasswordMinimumLength() {
  61. if (isDeviceAdminActive()) {
  62. return mDPM.getPasswordMinimumLength(mDeviceAdminSample);
  63. } else {
  64. activateDeviceAdmin();
  65. return -1;
  66. }
  67. }
  68. // TODO: 2017-2-7 策略信息中并没有该项
  69. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  70. public int setPasswordMinimumLetters(int value) {
  71. if (isDeviceAdminActive()) {
  72. if (API_LEVEL < 11) {
  73. return ERROR_UNSUPPORTED;
  74. }
  75. mDPM.setPasswordMinimumLetters(mDeviceAdminSample, value);
  76. return 0;
  77. } else {
  78. activateDeviceAdmin();
  79. return ERROR_UNACTIVATED;
  80. }
  81. }
  82. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  83. public int setPasswordMinimumNumeric(int value) {
  84. if (isDeviceAdminActive()) {
  85. if (API_LEVEL < 11) {
  86. return ERROR_UNSUPPORTED;
  87. }
  88. mDPM.setPasswordMinimumNumeric(mDeviceAdminSample, value);
  89. return 0;
  90. } else {
  91. activateDeviceAdmin();
  92. return ERROR_UNACTIVATED;
  93. }
  94. }
  95. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  96. public int setPasswordMinimumLowerCase(int value) {
  97. if (isDeviceAdminActive()) {
  98. if (API_LEVEL < 11) {
  99. return ERROR_UNSUPPORTED;
  100. }
  101. mDPM.setPasswordMinimumLowerCase(mDeviceAdminSample, value);
  102. return 0;
  103. } else {
  104. activateDeviceAdmin();
  105. return ERROR_UNACTIVATED;
  106. }
  107. }
  108. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  109. public int setPasswordMinimumUpperCase(int value) {
  110. if (isDeviceAdminActive()) {
  111. if (API_LEVEL < 11) {
  112. return ERROR_UNSUPPORTED;
  113. }
  114. mDPM.setPasswordMinimumUpperCase(mDeviceAdminSample, value);
  115. return 0;
  116. } else {
  117. activateDeviceAdmin();
  118. return ERROR_UNACTIVATED;
  119. }
  120. }
  121. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  122. public int setPasswordMinimumSymbols(int value) {
  123. if (isDeviceAdminActive()) {
  124. if (API_LEVEL < 11) {
  125. return ERROR_UNSUPPORTED;
  126. }
  127. mDPM.setPasswordMinimumSymbols(mDeviceAdminSample, value);
  128. return 0;
  129. } else {
  130. activateDeviceAdmin();
  131. return ERROR_UNACTIVATED;
  132. }
  133. }
  134. /*
  135. * -1无法获取
  136. */
  137. public int getPasswordMinimumSymbols() {
  138. if (isDeviceAdminActive()) {
  139. return mDPM.getPasswordMinimumSymbols(mDeviceAdminSample);
  140. } else {
  141. activateDeviceAdmin();
  142. return -1;
  143. }
  144. }
  145. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  146. public int setPasswordMinimumNonLetter(int value) {
  147. if (isDeviceAdminActive()) {
  148. if (API_LEVEL < 11) {
  149. return ERROR_UNSUPPORTED;
  150. }
  151. mDPM.setPasswordMinimumNonLetter(mDeviceAdminSample, value);
  152. return 0;
  153. } else {
  154. activateDeviceAdmin();
  155. return ERROR_UNACTIVATED;
  156. }
  157. }
  158. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  159. public int setPasswordHistoryLength(int value) {
  160. if (isDeviceAdminActive()) {
  161. if (API_LEVEL < 11) {
  162. return ERROR_UNSUPPORTED;
  163. }
  164. mDPM.setPasswordHistoryLength(mDeviceAdminSample, value);
  165. return 0;
  166. } else {
  167. activateDeviceAdmin();
  168. return ERROR_UNACTIVATED;
  169. }
  170. }
  171. /*
  172. * -1无法获取
  173. */
  174. public int getPasswordHistoryLength() {
  175. if (isDeviceAdminActive()) {
  176. return mDPM.getPasswordHistoryLength(mDeviceAdminSample);
  177. } else {
  178. activateDeviceAdmin();
  179. return -1;
  180. }
  181. }
  182. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  183. public int setPasswordExpirationTimeout(int value) {
  184. if (isDeviceAdminActive()) {
  185. if (API_LEVEL < 11) {
  186. return ERROR_UNSUPPORTED;
  187. }
  188. mDPM.setPasswordExpirationTimeout(mDeviceAdminSample, value
  189. * MS_PER_DAY);
  190. return 0;
  191. } else {
  192. activateDeviceAdmin();
  193. return ERROR_UNACTIVATED;
  194. }
  195. }
  196. /*
  197. * -1无法获取
  198. */
  199. public long getPasswordExpirationTimeout() {
  200. if (isDeviceAdminActive()) {
  201. long ret = mDPM.getPasswordExpirationTimeout(mDeviceAdminSample);
  202. return ret / MS_PER_DAY;
  203. } else {
  204. activateDeviceAdmin();
  205. return -1;
  206. }
  207. }

4、控制蓝牙

  1. // 打开、关闭蓝牙
  2. public int setBluetoothState(boolean enable) {
  3. BluetoothAdapter bluetoothAdapter = BluetoothAdapter
  4. .getDefaultAdapter();
  5. if (bluetoothAdapter == null) {
  6. return ERROR_UNSUPPORTED;
  7. }
  8. if (enable) {
  9. bluetoothAdapter.enable();
  10. } else {
  11. bluetoothAdapter.disable();
  12. }
  13. return 0;
  14. }

5、WIFI控制相关

  1. public int getWifiState() {
  2. android.net.wifi.WifiManager wifiManager = (android.net.wifi.WifiManager) mContext
  3. .getSystemService(Context.WIFI_SERVICE);
  4. return wifiManager.getWifiState();
  5. }
  6. // 打开、关闭wifi
  7. public void setWifiState(boolean enable) {
  8. android.net.wifi.WifiManager wifiManager = (android.net.wifi.WifiManager) mContext
  9. .getSystemService(Context.WIFI_SERVICE);
  10. wifiManager.setWifiEnabled(enable);
  11. }
  12. // 打开、关闭wifi
  13. public void disconnectWifi() {
  14. android.net.wifi.WifiManager wifiManager = (android.net.wifi.WifiManager) mContext
  15. .getSystemService(Context.WIFI_SERVICE);
  16. wifiManager.getConnectionInfo().getNetworkId();
  17. WifiAdmin wifiAdmin = new WifiAdmin(mContext);
  18. wifiAdmin.disconnectWifi(wifiManager.getConnectionInfo().getNetworkId());
  19. //wifiManager.disconnect();
  20. }

6、设置静音

  1. // 设置静音
  2. public int setMute(boolean setMute) {
  3. if (setMute) {
  4. AudioManager audioManager = (AudioManager) mContext
  5. .getSystemService(Context.AUDIO_SERVICE);
  6. audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // mute
  7. // music
  8. // stream
  9. audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); // mute
  10. // ring
  11. // stream
  12. if (Build.VERSION.SDK_INT >= 8) {
  13. audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
  14. AudioManager.AUDIOFOCUS_GAIN);
  15. audioManager.requestAudioFocus(null, AudioManager.STREAM_RING,
  16. AudioManager.AUDIOFOCUS_GAIN);
  17. }
  18. } else {
  19. AudioManager audioManager = (AudioManager) mContext
  20. .getSystemService(Context.AUDIO_SERVICE);
  21. int maxMusic = audioManager
  22. .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
  23. audioManager
  24. .setStreamVolume(AudioManager.STREAM_MUSIC, maxMusic, 0); // mute
  25. // music
  26. // stream
  27. int maxRing = audioManager
  28. .getStreamMaxVolume(AudioManager.STREAM_RING);
  29. audioManager.setStreamVolume(AudioManager.STREAM_RING, maxRing, 0); // mute
  30. // ring
  31. // stream
  32. if (Build.VERSION.SDK_INT >= 8) {
  33. audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
  34. AudioManager.AUDIOFOCUS_GAIN);
  35. audioManager.requestAudioFocus(null, AudioManager.STREAM_RING,
  36. AudioManager.AUDIOFOCUS_GAIN);
  37. }
  38. }
  39. return 0;
  40. }

7、恢复出厂设置

  1. @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  2. public int wipeData(boolean withExternalStorage) {
  3. if (isDeviceAdminActive()) {
  4. if (API_LEVEL >= 9) {
  5. // mDPM.wipeData(withExternalStorage ? DevicePolicyManager.WIPE_EXTERNAL_STORAGE
  6. // : 0);
  7. mDPM.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE);
  8. } else {
  9. // WIPE_EXTERNAL_STORAGE is not supported under API level 9
  10. mDPM.wipeData(0);
  11. }
  12. return 0;
  13. } else {
  14. activateDeviceAdmin();
  15. return ERROR_UNACTIVATED;
  16. }
  17. }

要想实现更多的管理服务得去不同厂家申请了,比如申请加入APP白名单的接口,wifi黑白名单的各种黑操作之类的。

有问题欢迎留言讨论

热文推荐:

1、大厂又有新的开源项目了,赶紧来领取...

2、面试官问我:一个 TCP 连接可以发多少个 HTTP 请求?我竟然回答不上来...

3、程序员疑似出bug被吊打!菲律宾的高薪工作机会了解一下?

4、“一键脱衣”的DeepNude下架后,我在GitHub上找到它涉及的技术

5、原生Android开发的路该怎么走

6、太厉害了,终于有人能把TCP/IP 协议讲的明明白白了

7、腾讯开源超实用的UI轮子库,我是轮子搬运工

8、腾讯新开源一吊炸天神器—零反射全动态Android插件框架正式开源

                        喜欢 就关注吧,欢迎投稿!

640?wx_fmt=jpeg

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/188049
推荐阅读
相关标签
  

闽ICP备14008679号