如果device不支持某种sensor,可以在android/frameworks/base/core/java/android/hardware/SystemSensorManager.java里将其disabled掉。以disable proximity sensor为例。
public SystemSensorManager(Context context, Looper mainLooper) {
synchronized(sLock) {
if (!sNativeClassInited) {
sNativeClassInited = true;
nativeClassInit();
}
}
mMainLooper = mainLooper;
mTargetSdkLevel = context.getApplicationInfo().targetSdkVersion;
mContext = context;
mNativeInstance = nativeCreate(context.getOpPackageName());
// initialize the sensor list
for (int index = 0;;++index) {
Sensor sensor = new Sensor();
if (!nativeGetSensorAtIndex(mNativeInstance, sensor, index)) break;
//disable p_sensor solution: Remove proximity sensor from sensor list.
if ((sensor != null) && sensor.getType() == Sensor.TYPE_PROXIMITY){
Log.i(TAG,"skip proximity sensor");
continue;
}
mFullSensorsList.add(sensor);
mHandleToSensor.put(sensor.getHandle(), sensor);
}
}
就是将p_sensor 从mFullSensorsList中移出。这一步基本上已经work了(SensorManager#getSensorList(8)得不到p_sensor的讯息),但是如果你的code还需要通过CTS测试,那么最好在android/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java的hasSystemFeature方法里做remove proximity sensor feature
public boolean hasSystemFeature(String name, int version) {
// allow instant applications
synchronized (mAvailableFeatures) {
final FeatureInfo feat = mAvailableFeatures.get(name);
if (feat == null) {
return false;
} else {
//remove proximity sensor feature
if(name.equals("android.hardware.sensor.proximity")){
Log.w(TAG, "skip standard proximity sensor");
return false;
}
return feat.version >= version;
}
}
}
这样一来PackageManager#hasSystemFeature(android.hardware.sensor.proximity) return false。
可用命令adb shell pm list features来检查device都support 那些功能。
或者尝试删除frameworks\native\data\etc下相关的配置文件文章来源:https://www.toymoban.com/news/detail-738001.html
文章来源地址https://www.toymoban.com/news/detail-738001.html
到了这里,关于android 8.1 disable unsupported sensor的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!