1、問題解決主要文件:/m8976/packages/providers/MediaProvider/src/com/android/providers/media/MtpService.java
專注于為中小企業(yè)提供成都網(wǎng)站設計、做網(wǎng)站服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)貢覺免費做網(wǎng)站提供優(yōu)質的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉變。
需要在MtpService.java中updateDisabledStateLocked 方法添加鎖屏情況限制:
final KeyguardManager keyguardManager = (KeyguardManager) getSystemService( Context.KEYGUARD_SERVICE); mMtpDisabled = (keyguardManager.isKeyguardLocked() && keyguardManager.isKeyguardSecure()) || !mUnlocked || !isCurrentUser;
只要鎖屏,mMtpDisabled就設置為true。
這樣就實現(xiàn)該功能。
2、當解鎖時,自動加載手機存儲單元:
添加解鎖監(jiān)聽
+ 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上發(fā)送解鎖狀態(tài)的廣播code沒有去除,可以查看/m8976/frameworks/base/packages/SystemUI/src/com/android /systemui/keyguard/KeyguardViewMediator.java
在KeyguardViewMediator.java文件中可以看出,在解鎖時,發(fā)送Intent.ACTION_USER_PRESENT廣播,然后在MtpService.java
進行接收,對mMtpDisabled進行處理。
以上這篇完美解決android M上鎖屏情況下,禁止pc通過MTP訪問手機存儲單元就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持創(chuàng)新互聯(lián)。