1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wm; 18 19 import android.annotation.NonNull; 20 import android.os.SystemProperties; 21 import android.util.ArraySet; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 25 /** 26 * A Blacklist for packages that should force the display out of high refresh rate. 27 */ 28 class HighRefreshRateBlacklist { 29 30 private static final String SYSPROP_KEY = "ro.window_manager.high_refresh_rate_blacklist"; 31 private static final String SYSPROP_KEY_LENGTH_SUFFIX = "_length"; 32 private static final String SYSPROP_KEY_ENTRY_SUFFIX = "_entry"; 33 private static final int MAX_ENTRIES = 50; 34 35 private ArraySet<String> mBlacklistedPackages = new ArraySet<>(); 36 create()37 static HighRefreshRateBlacklist create() { 38 return new HighRefreshRateBlacklist(new SystemPropertyGetter() { 39 @Override 40 public int getInt(String key, int def) { 41 return SystemProperties.getInt(key, def); 42 } 43 44 @Override 45 public String get(String key) { 46 return SystemProperties.get(key); 47 } 48 }); 49 } 50 51 @VisibleForTesting 52 HighRefreshRateBlacklist(SystemPropertyGetter propertyGetter) { 53 54 // Read and populate the blacklist 55 final int length = Math.min( 56 propertyGetter.getInt(SYSPROP_KEY + SYSPROP_KEY_LENGTH_SUFFIX, 0), 57 MAX_ENTRIES); 58 for (int i = 1; i <= length; i++) { 59 final String packageName = propertyGetter.get( 60 SYSPROP_KEY + SYSPROP_KEY_ENTRY_SUFFIX + i); 61 if (!packageName.isEmpty()) { 62 mBlacklistedPackages.add(packageName); 63 } 64 } 65 } 66 67 boolean isBlacklisted(String packageName) { 68 return mBlacklistedPackages.contains(packageName); 69 } 70 71 interface SystemPropertyGetter { 72 int getInt(String key, int def); 73 @NonNull String get(String key); 74 } 75 } 76