Merge "Enforce declared permissions on getCellularBatteryStats(), getWifiBatteryStats() and getGpsBatteryStats()" into sc-dev

This commit is contained in:
Dmitri Plotnikov
2021-06-18 16:52:25 +00:00
committed by Android (Google) Code Review

View File

@@ -16,6 +16,7 @@
package com.android.server.am; 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.net.NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED;
import static android.os.BatteryStats.POWER_DATA_UNAVAILABLE; import static android.os.BatteryStats.POWER_DATA_UNAVAILABLE;
@@ -2524,6 +2525,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
* @hide * @hide
*/ */
public CellularBatteryStats getCellularBatteryStats() { 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 // Wait for the completion of pending works if there is any
awaitCompletion(); awaitCompletion();
synchronized (mStats) { synchronized (mStats) {
@@ -2536,6 +2543,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
* @hide * @hide
*/ */
public WifiBatteryStats getWifiBatteryStats() { 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 // Wait for the completion of pending works if there is any
awaitCompletion(); awaitCompletion();
synchronized (mStats) { synchronized (mStats) {
@@ -2548,6 +2561,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
* @hide * @hide
*/ */
public GpsBatteryStats getGpsBatteryStats() { public GpsBatteryStats getGpsBatteryStats() {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BATTERY_STATS, null);
// Wait for the completion of pending works if there is any // Wait for the completion of pending works if there is any
awaitCompletion(); awaitCompletion();
synchronized (mStats) { synchronized (mStats) {