您好,登錄后才能下訂單哦!
1、問題解決主要文件:/m8976/packages/providers/MediaProvider/src/com/android/providers/media/MtpService.java
需要在MtpService.java中updateDisabledStateLocked 方法添加鎖屏情況限制:
final KeyguardManager keyguardManager = (KeyguardManager) getSystemService( Context.KEYGUARD_SERVICE); mMtpDisabled = (keyguardManager.isKeyguardLocked() && keyguardManager.isKeyguardSecure()) || !mUnlocked || !isCurrentUser;
只要鎖屏,mMtpDisabled就設置為true。
這樣就實現該功能。
2、當解鎖時,自動加載手機存儲單元:
添加解鎖監聽
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + if (Intent.ACTION_USER_PRESENT.equals(action)) { + // If the media scanner is running, it may currently be calling + // sendObjectAdded/Removed, which also synchronizes on mBinder + // (and in addition to that, all the native MtpServer methods + // lock the same Mutex). If it happens to be in an mtp device + // write(), it may block for some time, so process this broadcast + // in a thread. + new Thread(new Runnable() { + @Override + public void run() { + synchronized (mBinder) { + // Unhide the storage units when the user has unlocked the lockscreen + if (mMtpDisabled) { + addStorageDevicesLocked(); + mMtpDisabled = false; + } + } + }}, "addStorageDevices").start(); + } + } + };
Android M上發送解鎖狀態的廣播code沒有去除,可以查看/m8976/frameworks/base/packages/SystemUI/src/com/android /systemui/keyguard/KeyguardViewMediator.java
在KeyguardViewMediator.java文件中可以看出,在解鎖時,發送Intent.ACTION_USER_PRESENT廣播,然后在MtpService.java
進行接收,對mMtpDisabled進行處理。
以上這篇完美解決android M上鎖屏情況下,禁止pc通過MTP訪問手機存儲單元就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。