From 87a0000d52d004fd8d2decab355c21debedadc58 Mon Sep 17 00:00:00 2001 From: Kshitij Gupta Date: Sun, 28 Feb 2021 03:08:38 +0530 Subject: [PATCH] DeviceConfig: Check for permission before bailing --- .../launcher3/uioverrides/DeviceFlag.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/DeviceFlag.java b/quickstep/src/com/android/launcher3/uioverrides/DeviceFlag.java index a291843f3c..991dbb1931 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/DeviceFlag.java +++ b/quickstep/src/com/android/launcher3/uioverrides/DeviceFlag.java @@ -16,8 +16,11 @@ package com.android.launcher3.uioverrides; +import android.Manifest; import android.annotation.TargetApi; +import android.app.ActivityThread; import android.content.Context; +import android.content.pm.PackageManager; import android.os.Build; import android.provider.DeviceConfig; @@ -61,24 +64,27 @@ public class DeviceFlag extends DebugFlag { } private void registerDeviceConfigChangedListener(Context context) { -// DeviceConfig.addOnPropertiesChangedListener( -// NAMESPACE_LAUNCHER, -// context.getMainExecutor(), -// properties -> { -// if (!NAMESPACE_LAUNCHER.equals(properties.getNamespace()) -// || !properties.getKeyset().contains(key)) { -// return; -// } -// defaultValue = getDeviceValue(key, mDefaultValueInCode); -// initialize(context); -// for (Runnable r: mListeners) { -// r.run(); -// } -// }); + int usagePerm = context.checkCallingOrSelfPermission("android.permission.READ_DEVICE_CONFIG"); + if (usagePerm != PackageManager.PERMISSION_GRANTED) return; + DeviceConfig.addOnPropertiesChangedListener( + NAMESPACE_LAUNCHER, + context.getMainExecutor(), + properties -> { + if (!NAMESPACE_LAUNCHER.equals(properties.getNamespace()) + || !properties.getKeyset().contains(key)) { + return; + } + defaultValue = getDeviceValue(key, mDefaultValueInCode); + initialize(context); + for (Runnable r: mListeners) { + r.run(); + } + }); } protected static boolean getDeviceValue(String key, boolean defaultValue) { - return defaultValue; -// return DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, key, defaultValue); + int usagePerm = ActivityThread.currentApplication().checkCallingOrSelfPermission("android.permission.READ_DEVICE_CONFIG"); + if (usagePerm != PackageManager.PERMISSION_GRANTED) return defaultValue; + return DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, key, defaultValue); } }