HardwarePropertiesManager无法正常工作

Ser*_*eim 5 android cpu-usage android-sensors

我正在尝试使用HardwarePropertiesManagerhttps://developer.android.com/reference/android/os/HardwarePropertiesManager.html)访问信息。我正在使用带有以下代码的Android 7.0(API级别24):

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView helloTV = findViewById(R.id.helloTV);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            HardwarePropertiesManager hardwarePropertiesManager = getApplicationContext().getSystemService(HardwarePropertiesManager.class);
            CpuUsageInfo[] cpuUsages = hardwarePropertiesManager.getCpuUsages();
            ///...

Now when my applications finds the hardwarePropertiesManager.getCpuUsages(); line it throws the following exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{gr.serafeim.sensorplayground/gr.serafeim.sensorplayground.MainActivity}: java.lang.SecurityException: The caller is not a device or profile owner or bound VrListenerService.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6123)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
     Caused by: java.lang.SecurityException: The caller is not a device or profile owner or bound VrListenerService.
        at android.os.Parcel.readException(Parcel.java:1683)
        at android.os.Parcel.readException(Parcel.java:1636)
        at android.os.IHardwarePropertiesManager$Stub$Proxy.getCpuUsages(IHardwarePropertiesManager.java:127)
        at android.os.HardwarePropertiesManager.getCpuUsages(HardwarePropertiesManager.java:155)
        at gr.serafeim.sensorplayground.MainActivity.onCreate(MainActivity.java:21)
        at android.app.Activity.performCreate(Activity.java:6672)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6123) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 

Can somebody explain to me:

  • What is "device or profile owner" - how can my application be one?
  • What is a "VrListenerService"
  • Is there any way I can actually use the HardwarePropertiesManager to get info about my CPU or it's a lost cause ?

The documentation of the getCpuUsages just says that it throws a SecurityException "if something other than the device owner or the current VR service tries to retrieve information provided by this service" -- this does not clarify anything.

Ser*_*eim 5

经过研究,我发现了问题所在。HardwarePropertiesManager仅在企业配置的Android设备中允许使用API(请参见https://developer.android.com/work/overview.htmlhttps://sdgsystems.com/blog/introduction-android-work)。因此,此API主要用于信息亭模式下的设备(或自带设备-BYOD),以便您可以轻松地远程监控此设备。“设备所有者”或“配置文件所有者”是指BYOD或COSU-公司拥有的一次性使用应用程序或用户配置文件。

因此,不幸的是,该API无法被普通设备使用。