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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14985497

Change-Id: I91047a7a56cbb952f4df7da7fea0e168ccaf5b3c
This commit is contained in:
Dmitri Plotnikov
2021-06-18 17:04:34 +00:00
committed by Automerger Merge Worker

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) {