解决Android M上锁屏情况下,禁止PC通过MTP访问手机存储单元
2016-02-26 17:58
399 查看
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进行处理。
需要在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 图片处理,实现蒙层效果
- Android逆向之旅---解析编译之后的classes.dex文件格式
- Android NDK 创建 Socket 失败(socket = -1)问题记录
- 【转】Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法
- Android Process 详解
- Android插件化开发 第五篇 [360 Droid Plugin]
- android 获取屏幕尺寸
- android常用的几个获取包或activity以及判断前后台等
- Android系统自带样式(android:theme)详解
- android加快gradle构建速度
- Android 资源文件string.xml 中数组的使用(可支持多语言)
- Android Studio使用AIDL 实现进程间通信实例
- Android手动打包:jar某目录下存在两个同名(不区分大小写)class文件,解压后如何再打包回dex
- Android内存泄露杂记2016-02-26
- Ubuntu连接Android真机调试
- java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.widget.CheckBox.is
- Android物理按键
- Window 系统下安装cordova (用于Android开发)
- android之WIFI小车编程详述
- Android中Context详解 ---- 你所不知道的Context