123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- package com.action.actionmdm;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Build;
- import android.os.Bundle;
- import android.support.v4.content.FileProvider;
- import android.text.TextUtils;
- import android.util.Log;
- import java.io.File;
- import java.util.Arrays;
- import java.util.Iterator;
- import java.util.List;
- public class MDMApi {
- private static final String TAG = "act-mdm";
- private Context mContext;
- private ContentResolver resolver = null;
- private static final Uri ACTION_MDM_URI = Uri.parse("content://com.action.mdm_provider");
- private static final String GET_MEID_IMEI = "get_meid_imei";
- private static final String GET_DISABLE_INSTALL_PKGS = "get_disable_install_pkgs";
- private static final String SET_DISABLE_INSTALL_PKGS = "set_disable_install_pkgs";
- private static final String IS_DISABLE_INSTALL_ALL_APP = "is_disable_install_all_app";
- private static final String SET_DISABLE_INSTALL_ALL_APP = "set_disable_install_all_app";
- private static final String IS_DISABLED_STATUSBAR = "is_disabled_statusbar";
- private static final String SET_DISABLED_STATUSBAR = "set_disabled_statusbar";
- private static final String GET_NOT_DISPLAY_DESKTOP_ICONS = "get_not_display_desktop_icons";
- private static final String SET_NOT_DISPLAY_DESKTOP_ICONS = "set_not_display_desktop_icons";
- private static final String UNINSTALLER_APP = "uninstaller_app";
- private static final String UNINSTALLER_PKG = "uninstaller_pkg";
- private static final String UNINSTALLER_ALLUSERS = "uninstaller_allusers";
- private static final String UNINSTALLER_SILENCE = "uninstaller_pkg_silence";
- private static final String SET_TIME = "set_time";
- private static final String REBOOT_DEVICE_KEY = "reboot_device";
- private static final String SHUTDOWN_DEVICE_KEY = "shutdown_device";
- private static final String SET_TRICOLOR_LAMP = "set_tricolor_lamp";
- private static final String DEFAULT_OPEN = "default_open";
- public MDMApi(Context context) {
- this.mContext = context;
- this.resolver = this.mContext.getContentResolver();
- }
- public List<String> getMeidAndImei() {
- List<String> res = null;
- String meidImei = null;
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras = this.resolver.call(ACTION_MDM_URI, "get_meid_imei", (String) null, extras);
- if (extras != null) {
- meidImei = extras.getString("get_meid_imei", (String) null);
- }
- if (!TextUtils.isEmpty(meidImei)) {
- String[] ids = meidImei.split(",");
- res = Arrays.asList(ids);
- }
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- return res;
- }
- public List<String> getDisableInstallPkgs() {
- List<String> res = null;
- String pkgs = null;
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras = this.resolver.call(ACTION_MDM_URI, "get_disable_install_pkgs", (String) null, extras);
- if (extras != null) {
- pkgs = extras.getString("get_disable_install_pkgs", (String) null);
- }
- if (!TextUtils.isEmpty(pkgs)) {
- String[] pkgArray = pkgs.split(",");
- res = Arrays.asList(pkgArray);
- }
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- return res;
- }
- public void setDisableInstallPkgs(List<String> pkgList) {
- if (pkgList != null && pkgList.size() > 0) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- String pkgs = "";
- String pkg;
- for (Iterator i$ = pkgList.iterator(); i$.hasNext(); pkgs = pkgs + pkg + ",") {
- pkg = (String) i$.next();
- }
- int len = pkgs.length();
- pkgs = pkgs.substring(0, len - 1);
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putString("set_disable_install_pkgs", pkgs);
- this.resolver.call(ACTION_MDM_URI, "set_disable_install_pkgs", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- }
- public boolean isDisableInstallAllApk() {
- boolean isDisable = false;
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras = this.resolver.call(ACTION_MDM_URI, "is_disable_install_all_app", (String) null, extras);
- if (extras != null) {
- isDisable = extras.getBoolean("is_disable_install_all_app", false);
- }
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- return isDisable;
- }
- public void setDisableInstallAllApk(boolean isDisable) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putBoolean("set_disable_install_all_app", isDisable);
- this.resolver.call(ACTION_MDM_URI, "set_disable_install_all_app", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- public boolean isDisableStatusBar() {
- boolean isDisable = false;
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras = this.resolver.call(ACTION_MDM_URI, "is_disabled_statusbar", (String) null, extras);
- if (extras != null) {
- isDisable = extras.getBoolean("is_disabled_statusbar", false);
- }
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- return isDisable;
- }
- public void setDisableStatusBar(boolean isDisable) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putBoolean("set_disabled_statusbar", isDisable);
- this.resolver.call(ACTION_MDM_URI, "set_disabled_statusbar", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- public List<String> getNotDisplayDesktopIcons() {
- List<String> res = null;
- String pkgs = null;
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras = this.resolver.call(ACTION_MDM_URI, "get_not_display_desktop_icons", (String) null, extras);
- if (extras != null) {
- pkgs = extras.getString("get_not_display_desktop_icons", (String) null);
- }
- if (!TextUtils.isEmpty(pkgs)) {
- String[] pkgArray = pkgs.split(",");
- res = Arrays.asList(pkgArray);
- }
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- return res;
- }
- public void setNotDisplayDesktopIcons(List<String> pkgList) {
- if (pkgList != null && pkgList.size() > 0) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- String pkgs = "";
- String pkg;
- for (Iterator i$ = pkgList.iterator(); i$.hasNext(); pkgs = pkgs + pkg + ",") {
- pkg = (String) i$.next();
- }
- int len = pkgs.length();
- pkgs = pkgs.substring(0, len - 1);
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putString("set_not_display_desktop_icons", pkgs);
- this.resolver.call(ACTION_MDM_URI, "set_not_display_desktop_icons", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- }
- public void uninstallApp(String pkg, boolean allUsers, boolean isSilence) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putString("uninstaller_pkg", pkg);
- extras.putBoolean("uninstaller_allusers", allUsers);
- extras.putBoolean("uninstaller_pkg_silence", isSilence);
- this.resolver.call(ACTION_MDM_URI, "uninstaller_app", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- public void setTime(long timeMillis) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putLong("set_time", timeMillis);
- this.resolver.call(ACTION_MDM_URI, "set_time", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- public void reboot() {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- this.resolver.call(ACTION_MDM_URI, "reboot_device", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- public void shutdown() {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- this.resolver.call(ACTION_MDM_URI, "shutdown_device", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- public void setTricolor(int value) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putInt("set_tricolor_lamp", value);
- this.resolver.call(ACTION_MDM_URI, "set_tricolor_lamp", (String) null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- public void install(String path, boolean runAfterInstall) {
- File apkFile = new File(path);
- if (!apkFile.exists()) {
- return;
- }
- Intent intent = new Intent();
- intent.setAction(Intent.ACTION_VIEW);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- if (Build.VERSION.SDK_INT >= 24) {
- Log.w(TAG, "版本大于 N ,开始使用 fileProvider 进行安装…");
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
- // 安装结束是否打开应用
- intent.putExtra(DEFAULT_OPEN, runAfterInstall);
- Uri contentUri = FileProvider.getUriForFile(mContext,
- "com.wubin.otg.otgmaster.fileprovider", apkFile);
- intent.setDataAndType(contentUri,
- "application/vnd.android.package-archive-silence");
- } else {
- Log.w(TAG, "正常进行安装…");
- intent.setDataAndType(Uri.fromFile(apkFile),
- "application/vnd.android.package-archive-silence");
- }
- mContext.startActivity(intent);
- }
- public boolean hasAdbEnable() {
- boolean isEnabled = false;
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras = this.resolver.call(ACTION_MDM_URI, "get_adb_state", null, extras);
- if (extras != null) {
- isEnabled = extras.getBoolean("get_adb_state", false);
- }
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- return isEnabled;
- }
- public void setAdbEnable(boolean enable) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putBoolean("set_adb_state", enable);
- this.resolver.call(ACTION_MDM_URI, "set_adb_state", null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- public boolean hasVirtualKeyEnable(String key) {
- boolean isEnabled = false;
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putString("get_key_state", key);
- extras = this.resolver.call(ACTION_MDM_URI, "get_key_state", null, extras);
- if (extras != null) {
- isEnabled = extras.getBoolean("get_key_state", false);
- }
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- return !isEnabled;
- }
- public void setVirtualKeyEnable(String key, boolean enable) {
- if (this.resolver == null) {
- this.resolver = this.mContext.getContentResolver();
- }
- if (this.resolver.acquireContentProviderClient(ACTION_MDM_URI) != null) {
- Log.d("act-mdm", "find provider " + ACTION_MDM_URI);
- Bundle extras = new Bundle();
- extras.putString("set_key_state_key", key);
- extras.putBoolean("set_key_state_value", !enable);
- this.resolver.call(ACTION_MDM_URI, "set_key_state", null, extras);
- } else {
- Log.d("act-mdm", "Could Not Find Provider " + ACTION_MDM_URI);
- }
- }
- }
|