Enforce declared permissions on getCellularBatteryStats(), getWifiBatteryStats() and getGpsBatteryStats()
This reverts commit 1fa8dbdaef.
Reason for revert: Rolling forward the original change along with test fixes
Bug: 188420344
Bug: 188420350
Bug: 191307066
Test: build, flash, presubmit
Change-Id: I3109d1258187edee8b6d9e7770c619e4911dd34a
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.server.am;
|
||||
|
||||
import static android.content.pm.PackageManager.PERMISSION_DENIED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED;
|
||||
import static android.os.BatteryStats.POWER_DATA_UNAVAILABLE;
|
||||
|
||||
@@ -2499,6 +2500,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
||||
* @hide
|
||||
*/
|
||||
public CellularBatteryStats getCellularBatteryStats() {
|
||||
if (mContext.checkCallingOrSelfPermission(
|
||||
android.Manifest.permission.UPDATE_DEVICE_STATS) == PERMISSION_DENIED) {
|
||||
mContext.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.BATTERY_STATS, null);
|
||||
}
|
||||
|
||||
// Wait for the completion of pending works if there is any
|
||||
awaitCompletion();
|
||||
synchronized (mStats) {
|
||||
@@ -2511,6 +2518,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
||||
* @hide
|
||||
*/
|
||||
public WifiBatteryStats getWifiBatteryStats() {
|
||||
if (mContext.checkCallingOrSelfPermission(
|
||||
android.Manifest.permission.UPDATE_DEVICE_STATS) == PERMISSION_DENIED) {
|
||||
mContext.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.BATTERY_STATS, null);
|
||||
}
|
||||
|
||||
// Wait for the completion of pending works if there is any
|
||||
awaitCompletion();
|
||||
synchronized (mStats) {
|
||||
@@ -2523,6 +2536,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
||||
* @hide
|
||||
*/
|
||||
public GpsBatteryStats getGpsBatteryStats() {
|
||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BATTERY_STATS, null);
|
||||
|
||||
// Wait for the completion of pending works if there is any
|
||||
awaitCompletion();
|
||||
synchronized (mStats) {
|
||||
|
||||
Reference in New Issue
Block a user