I'd implemented an app to get data usage, for getting data we need to give two permissions -
PACKAGE_USAGE_STATS
READ_PHONE_STATE
When I install app as play store app it works fine but when I push it as system app it crashes. Reason for this crash is - PACKAGE_USAGE_STATS permission. For system app its default value is enabled but still it got crash & produce following exception
java.lang.SecurityException: NetworkStats: Neither user nor current process has android.permission.READ_NETWORK_USAGE_HISTORY. at android.os.Parcel.readException(Parcel.java:1620) at android.os.Parcel.readException(Parcel.java:1573) at android.net.INetworkStatsSession$Stub$Proxy.getHistoryIntervalForUid(INetworkStatsSession.java:425) at android.app.usage.NetworkStats.startHistoryEnumeration(NetworkStats.java:341) at android.app.usage.NetworkStatsManager.queryDetailsForUid(NetworkStatsManager.java:201) at com.android.launcher3.appdatausage.DataUsageManager$2.run(DataUsageManager.java:204) at java.lang.Thread.run(Thread.java:818)
Once I toggle the permission it works fine. How to resolve this?