Merge "Add wifi call special case, fix phone, predictor, filter system" into sc-dev am: 2008f5c9b4

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I6671727422ee6fb10e02cff6d5213b7592cc4ee8
This commit is contained in:
Nate Myren
2021-01-29 17:33:21 +00:00
committed by Automerger Merge Worker

View File

@@ -28,7 +28,10 @@ import static android.app.AppOpsManager.OPSTR_RECORD_AUDIO;
import static android.app.AppOpsManager.OP_FLAGS_ALL_TRUSTED; import static android.app.AppOpsManager.OP_FLAGS_ALL_TRUSTED;
import static android.app.AppOpsManager.opToPermission; import static android.app.AppOpsManager.opToPermission;
import static android.content.pm.PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED; import static android.content.pm.PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED;
import static android.media.AudioSystem.MODE_IN_COMMUNICATION;
import static android.telephony.TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
import android.Manifest;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.app.AppOpsManager; import android.app.AppOpsManager;
import android.content.ComponentName; import android.content.ComponentName;
@@ -41,12 +44,14 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.icu.text.ListFormatter; import android.icu.text.ListFormatter;
import android.location.LocationManager; import android.location.LocationManager;
import android.media.AudioManager;
import android.os.Process; import android.os.Process;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.DeviceConfig; import android.provider.DeviceConfig;
import android.provider.Settings; import android.provider.Settings;
import android.speech.RecognitionService; import android.speech.RecognitionService;
import android.speech.RecognizerIntent; import android.speech.RecognizerIntent;
import android.telephony.TelephonyManager;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.ArraySet; import android.util.ArraySet;
import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodInfo;
@@ -75,6 +80,9 @@ public class PermissionUsageHelper {
private static final String PROPERTY_LOCATION_INDICATORS_ENABLED = private static final String PROPERTY_LOCATION_INDICATORS_ENABLED =
"location_indicators_enabled"; "location_indicators_enabled";
/** Whether to show the Permissions Hub. */
private static final String PROPERTY_PERMISSIONS_HUB_2_ENABLED = "permissions_hub_2_enabled";
/** How long after an access to show it as "recent" */ /** How long after an access to show it as "recent" */
private static final String RECENT_ACCESS_TIME_MS = "recent_acccess_time_ms"; private static final String RECENT_ACCESS_TIME_MS = "recent_acccess_time_ms";
@@ -84,17 +92,25 @@ public class PermissionUsageHelper {
/** The name of the expected voice IME subtype */ /** The name of the expected voice IME subtype */
private static final String VOICE_IME_SUBTYPE = "voice"; private static final String VOICE_IME_SUBTYPE = "voice";
private static final String SYSTEM_PKG = "android";
private static final long DEFAULT_RUNNING_TIME_MS = 5000L; private static final long DEFAULT_RUNNING_TIME_MS = 5000L;
private static final long DEFAULT_RECENT_TIME_MS = 30000L; private static final long DEFAULT_RECENT_TIME_MS = 30000L;
private static boolean shouldShowPermissionsHub() {
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
PROPERTY_PERMISSIONS_HUB_2_ENABLED, false);
}
private static boolean shouldShowIndicators() { private static boolean shouldShowIndicators() {
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
PROPERTY_CAMERA_MIC_ICONS_ENABLED, true); PROPERTY_CAMERA_MIC_ICONS_ENABLED, true) || shouldShowPermissionsHub();
} }
private static boolean shouldShowLocationIndicator() { private static boolean shouldShowLocationIndicator() {
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
PROPERTY_LOCATION_INDICATORS_ENABLED, false); PROPERTY_LOCATION_INDICATORS_ENABLED, false)
|| shouldShowPermissionsHub();
} }
private static long getRecentThreshold(Long now) { private static long getRecentThreshold(Long now) {
@@ -113,7 +129,7 @@ public class PermissionUsageHelper {
); );
private static final List<String> MIC_OPS = List.of( private static final List<String> MIC_OPS = List.of(
OPSTR_PHONE_CALL_CAMERA, OPSTR_PHONE_CALL_MICROPHONE,
OPSTR_RECORD_AUDIO OPSTR_RECORD_AUDIO
); );
@@ -163,6 +179,13 @@ public class PermissionUsageHelper {
return mUserContexts.get(user); return mUserContexts.get(user);
} }
// TODO ntmyren: Replace this with better check if this moves beyond teamfood
private boolean isAppPredictor(String packageName, UserHandle user) {
return shouldShowPermissionsHub() && getUserContext(user).getPackageManager()
.checkPermission(Manifest.permission.MANAGE_APP_PREDICTIONS, packageName)
== PackageManager.PERMISSION_GRANTED;
}
/** /**
* @see PermissionManager.getIndicatorAppOpUsageData * @see PermissionManager.getIndicatorAppOpUsageData
*/ */
@@ -186,7 +209,28 @@ public class PermissionUsageHelper {
Map<PackageAttribution, CharSequence> packagesWithAttributionLabels = Map<PackageAttribution, CharSequence> packagesWithAttributionLabels =
getTrustedAttributions(rawUsages.get(MICROPHONE), proxyChains); getTrustedAttributions(rawUsages.get(MICROPHONE), proxyChains);
List<String> usedPermGroups = new ArrayList<>(rawUsages.keySet()); ArrayList<String> usedPermGroups = new ArrayList<>(rawUsages.keySet());
// If we have a phone call, and a carrier privileged app using microphone, hide the
// phone call.
AudioManager audioManager = mContext.getSystemService(AudioManager.class);
boolean hasPhoneCall = usedPermGroups.contains(OPSTR_PHONE_CALL_CAMERA)
|| usedPermGroups.contains(OPSTR_PHONE_CALL_MICROPHONE);
if (hasPhoneCall && usedPermGroups.contains(MICROPHONE) && audioManager.getMode()
== MODE_IN_COMMUNICATION) {
TelephonyManager telephonyManager =
mContext.getSystemService(TelephonyManager.class);
List<OpUsage> permUsages = rawUsages.get(MICROPHONE);
for (int usageNum = 0; usageNum < permUsages.size(); usageNum++) {
if (telephonyManager.checkCarrierPrivilegesForPackage(
permUsages.get(usageNum).packageName)
== CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
usedPermGroups.remove(OPSTR_PHONE_CALL_CAMERA);
usedPermGroups.remove(OPSTR_PHONE_CALL_MICROPHONE);
}
}
}
for (int permGroupNum = 0; permGroupNum < usedPermGroups.size(); permGroupNum++) { for (int permGroupNum = 0; permGroupNum < usedPermGroups.size(); permGroupNum++) {
boolean isPhone = false; boolean isPhone = false;
String permGroup = usedPermGroups.get(permGroupNum); String permGroup = usedPermGroups.get(permGroupNum);
@@ -269,8 +313,11 @@ public class PermissionUsageHelper {
if (lastAccessTime < recentThreshold && !attrOpEntry.isRunning()) { if (lastAccessTime < recentThreshold && !attrOpEntry.isRunning()) {
continue; continue;
} }
if (!isUserSensitive(packageName, user, op)
&& !isLocationProvider(packageName, user)) { if (packageName.equals(SYSTEM_PKG)
|| (!isUserSensitive(packageName, user, op)
&& !isLocationProvider(packageName, user)
&& !isAppPredictor(packageName, user))) {
continue; continue;
} }