I am trying to access info using the HardwarePropertiesManager (https://developer.android.com/reference/android/os/HardwarePropertiesManager.html). I am using Android 7.0 (API Level 24) with the following code:
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
HardwarePropertiesManagerto 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.