From 57b9defca0e5730b46bd9d10508a99191a7f400d Mon Sep 17 00:00:00 2001 From: Milk <1871357815@qq.com> Date: Thu, 3 Jun 2021 17:50:55 +0800 Subject: [PATCH] fix android l --- .../system/os/BStorageManagerService.java | 3 +++ .../fake/service/IStorageManagerProxy.java | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Bcore/src/main/java/top/niunaijun/blackbox/core/system/os/BStorageManagerService.java b/Bcore/src/main/java/top/niunaijun/blackbox/core/system/os/BStorageManagerService.java index ace93a6..1b0f2b1 100644 --- a/Bcore/src/main/java/top/niunaijun/blackbox/core/system/os/BStorageManagerService.java +++ b/Bcore/src/main/java/top/niunaijun/blackbox/core/system/os/BStorageManagerService.java @@ -29,6 +29,9 @@ public class BStorageManagerService extends IBStorageManagerService.Stub impleme @Override public StorageVolume[] getVolumeList(int uid, String packageName, int flags, int userId) throws RemoteException { + if (reflection.android.os.storage.StorageManager.getVolumeList == null) { + return null; + } try { StorageVolume[] storageVolumes = reflection.android.os.storage.StorageManager.getVolumeList.call(BUserHandle.getUserId(Process.myUid()), 0); for (StorageVolume storageVolume : storageVolumes) { diff --git a/Bcore/src/main/java/top/niunaijun/blackbox/fake/service/IStorageManagerProxy.java b/Bcore/src/main/java/top/niunaijun/blackbox/fake/service/IStorageManagerProxy.java index 4d775d1..7e9823a 100644 --- a/Bcore/src/main/java/top/niunaijun/blackbox/fake/service/IStorageManagerProxy.java +++ b/Bcore/src/main/java/top/niunaijun/blackbox/fake/service/IStorageManagerProxy.java @@ -2,6 +2,7 @@ package top.niunaijun.blackbox.fake.service; import android.os.IInterface; import android.os.Process; +import android.os.storage.StorageVolume; import java.lang.reflect.Method; @@ -55,12 +56,24 @@ public class IStorageManagerProxy extends BinderInvocationStub { @Override protected Object hook(Object who, Method method, Object[] args) throws Throwable { if (args == null) { - return BlackBoxCore.getBStorageManager().getVolumeList(Process.myUid(), null, 0, BActivityThread.getUserId()); + StorageVolume[] volumeList = BlackBoxCore.getBStorageManager().getVolumeList(Process.myUid(), null, 0, BActivityThread.getUserId()); + if (volumeList == null) { + return method.invoke(who, args); + } + return volumeList; } - int uid = (int) args[0]; - String packageName = (String) args[1]; - int flags = (int) args[2]; - return BlackBoxCore.getBStorageManager().getVolumeList(uid, packageName, flags, BActivityThread.getUserId()); + try { + int uid = (int) args[0]; + String packageName = (String) args[1]; + int flags = (int) args[2]; + StorageVolume[] volumeList = BlackBoxCore.getBStorageManager().getVolumeList(uid, packageName, flags, BActivityThread.getUserId()); + if (volumeList == null) { + return method.invoke(who, args); + } + } catch (Throwable t) { + return method.invoke(who, args); + } + return method.invoke(who, args); } } }