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:
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.
After some research I found out what the problem is. Using the HardwarePropertiesManager
API is only allowed in Enterprise configured Android devices (see here https://developer.android.com/work/overview.html and here https://sdgsystems.com/blog/introduction-android-work). So this API is mainly used for devices in Kiosk mode (or Bring Your Own Device - BYOD) in order to allow you to easily monitor this device remotely. The "device owner" or "profile owner" refer to a BYOD or COSU - Corporate Owned Single Use application or user profile.
Thus unfortunately this API cannot be used by normal devices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With