Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1023e07f authored by Nate Myren's avatar Nate Myren
Browse files

Show all system apps to hub teamfood, remove location indicator

Location indicator has its own flag, so it is being removed from the hub
teamfood. Also, showing all system usages (except the system app) for
the hub teamfood.

Bug: 172868375
Test: atest PrivacyDialogControllerTest, PrivacyItemControllerFlagsTest
Change-Id: Iad5b141f600a0bf830d5b2ef5169ed90533914cb
parent 50f0175f
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -111,8 +111,7 @@ public class PermissionUsageHelper {

    private static boolean shouldShowLocationIndicator() {
        return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
                PROPERTY_LOCATION_INDICATORS_ENABLED, false)
                || shouldShowPermissionsHub();
                PROPERTY_LOCATION_INDICATORS_ENABLED, false);
    }

    private static long getRecentThreshold(Long now) {
@@ -326,10 +325,10 @@ public class PermissionUsageHelper {
                    }

                    if (packageName.equals(SYSTEM_PKG)
                            || (!isUserSensitive(packageName, user, op)
                            || (!shouldShowPermissionsHub()
                            && !isUserSensitive(packageName, user, op)
                            && !isLocationProvider(packageName, user)
                            && !isAppPredictor(packageName, user))
                            && !isSpeechRecognizerUsage(op, packageName)) {
                            && !isSpeechRecognizerUsage(op, packageName))) {
                        continue;
                    }

+6 −10
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.hardware.SensorPrivacyManager.Sensors.CAMERA;
import static android.hardware.SensorPrivacyManager.Sensors.MICROPHONE;
import static android.media.AudioManager.ACTION_MICROPHONE_MUTE_CHANGED;

import android.Manifest;
import android.app.AppOpsManager;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -43,6 +42,7 @@ import androidx.annotation.WorkerThread;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.systemui.Dumpable;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton;
@@ -370,13 +370,9 @@ public class AppOpsControllerImpl extends BroadcastReceiver implements AppOpsCon
    }

    // TODO ntmyren: remove after teamfood is finished
    private boolean shouldShowAppPredictor(String pkgName) {
        if (!DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, "permissions_hub_2_enabled",
                false)) {
            return false;
        }
        return mPackageManager.checkPermission(Manifest.permission.MANAGE_APP_PREDICTIONS, pkgName)
                == PackageManager.PERMISSION_GRANTED;
    private boolean showSystemApps() {
        return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
                SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED, false);
    }

    /**
@@ -399,8 +395,8 @@ public class AppOpsControllerImpl extends BroadcastReceiver implements AppOpsCon
            return true;
        }
        // TODO ntmyren: Replace this with more robust check if this moves beyond teamfood
        if ((appOpCode == AppOpsManager.OP_CAMERA && isLocationProvider(packageName))
                || shouldShowAppPredictor(packageName)
        if (((showSystemApps() && !packageName.equals("android"))
                || appOpCode == AppOpsManager.OP_CAMERA && isLocationProvider(packageName))
                || isSpeechRecognizerUsage(appOpCode, packageName)) {
            return true;
        }
+1 −3
Original line number Diff line number Diff line
@@ -214,9 +214,7 @@ class PrivacyDialogController(

    private fun filterType(type: PrivacyType?): PrivacyType? {
        return type?.let {
            if (privacyItemController.allIndicatorsAvailable) {
                it
            } else if ((it == PrivacyType.TYPE_CAMERA || it == PrivacyType.TYPE_MICROPHONE) &&
            if ((it == PrivacyType.TYPE_CAMERA || it == PrivacyType.TYPE_MICROPHONE) &&
                    privacyItemController.micCameraAvailable) {
                it
            } else if (it == PrivacyType.TYPE_LOCATION && privacyItemController.locationAvailable) {
+8 −21
Original line number Diff line number Diff line
@@ -68,8 +68,6 @@ class PrivacyItemController @Inject constructor(
            addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)
        }
        const val TAG = "PrivacyItemController"
        private const val ALL_INDICATORS =
                SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED
        private const val MIC_CAMERA = SystemUiDeviceConfigFlags.PROPERTY_MIC_CAMERA_ENABLED
        private const val LOCATION = SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_ENABLED
        private const val DEFAULT_ALL_INDICATORS = false
@@ -83,11 +81,6 @@ class PrivacyItemController @Inject constructor(
        @Synchronized get() = field.toList() // Returns a shallow copy of the list
        @Synchronized set

    private fun isAllIndicatorsEnabled(): Boolean {
        return deviceConfigProxy.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
                ALL_INDICATORS, DEFAULT_ALL_INDICATORS)
    }

    private fun isMicCameraEnabled(): Boolean {
        return deviceConfigProxy.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
                MIC_CAMERA, DEFAULT_MIC_CAMERA)
@@ -120,34 +113,29 @@ class PrivacyItemController @Inject constructor(
        uiExecutor.execute(notifyChanges)
    }

    var allIndicatorsAvailable = isAllIndicatorsEnabled()
        private set
    var micCameraAvailable = isMicCameraEnabled()
        private set
    var locationAvailable = isLocationEnabled()

    var allIndicatorsAvailable = micCameraAvailable && locationAvailable

    private val devicePropertiesChangedListener =
            object : DeviceConfig.OnPropertiesChangedListener {
        override fun onPropertiesChanged(properties: DeviceConfig.Properties) {
            if (DeviceConfig.NAMESPACE_PRIVACY.equals(properties.getNamespace()) &&
                    (properties.keyset.contains(ALL_INDICATORS) ||
                            properties.keyset.contains(MIC_CAMERA) ||
                    (properties.keyset.contains(MIC_CAMERA) ||
                            properties.keyset.contains(LOCATION))) {

                // Running on the ui executor so can iterate on callbacks
                if (properties.keyset.contains(ALL_INDICATORS)) {
                    allIndicatorsAvailable = properties.getBoolean(ALL_INDICATORS,
                            DEFAULT_ALL_INDICATORS)
                    callbacks.forEach { it.get()?.onFlagAllChanged(allIndicatorsAvailable) }
                }

                if (properties.keyset.contains(MIC_CAMERA)) {
                    micCameraAvailable = properties.getBoolean(MIC_CAMERA, DEFAULT_MIC_CAMERA)
                    allIndicatorsAvailable = micCameraAvailable && locationAvailable
                    callbacks.forEach { it.get()?.onFlagMicCameraChanged(micCameraAvailable) }
                }

                if (properties.keyset.contains(LOCATION)) {
                    locationAvailable = properties.getBoolean(LOCATION, DEFAULT_LOCATION)
                    allIndicatorsAvailable = micCameraAvailable && locationAvailable
                    callbacks.forEach { it.get()?.onFlagLocationChanged(locationAvailable) }
                }
                internalUiExecutor.updateListeningState()
@@ -163,8 +151,7 @@ class PrivacyItemController @Inject constructor(
            active: Boolean
        ) {
            // Check if we care about this code right now
            if (!allIndicatorsAvailable &&
                    (code in OPS_LOCATION && !locationAvailable)) {
            if (code in OPS_LOCATION && !locationAvailable) {
                return
            }
            val userId = UserHandle.getUserId(uid)
@@ -231,7 +218,7 @@ class PrivacyItemController @Inject constructor(
     */
    private fun setListeningState() {
        val listen = !callbacks.isEmpty() and
                (allIndicatorsAvailable || micCameraAvailable || locationAvailable)
                (micCameraAvailable || locationAvailable)
        if (listening == listen) return
        listening = listen
        if (listening) {
@@ -338,7 +325,7 @@ class PrivacyItemController @Inject constructor(
            AppOpsManager.OP_RECORD_AUDIO -> PrivacyType.TYPE_MICROPHONE
            else -> return null
        }
        if (type == PrivacyType.TYPE_LOCATION && (!allIndicatorsAvailable && !locationAvailable)) {
        if (type == PrivacyType.TYPE_LOCATION && !locationAvailable) {
            return null
        }
        val app = PrivacyApplication(appOpItem.packageName, appOpItem.uid)
+2 −11
Original line number Diff line number Diff line
@@ -88,7 +88,6 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
    private boolean mViewAndWindowAdded;
    private ObjectAnimator mAnimator;

    private boolean mAllIndicatorsFlagEnabled;
    private boolean mMicCameraIndicatorFlagEnabled;
    private boolean mLocationIndicatorEnabled;
    private List<PrivacyItem> mPrivacyItems;
@@ -111,12 +110,10 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
        mIconMarginStart = Math.round(res.getDimension(R.dimen.privacy_chip_icon_margin));
        mIconSize = res.getDimensionPixelSize(R.dimen.privacy_chip_icon_size);

        mAllIndicatorsFlagEnabled = privacyItemController.getAllIndicatorsAvailable();
        mMicCameraIndicatorFlagEnabled = privacyItemController.getMicCameraAvailable();
        mLocationIndicatorEnabled = privacyItemController.getLocationAvailable();

        if (DEBUG) {
            Log.d(TAG, "allIndicators: " + mAllIndicatorsFlagEnabled);
            Log.d(TAG, "micCameraIndicators: " + mMicCameraIndicatorFlagEnabled);
            Log.d(TAG, "locationIndicators: " + mLocationIndicatorEnabled);
        }
@@ -134,12 +131,6 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
        updateUI();
    }

    @Override
    public void onFlagAllChanged(boolean flag) {
        if (DEBUG) Log.d(TAG, "all indicators enabled: " + flag);
        mAllIndicatorsFlagEnabled = flag;
    }

    @Override
    public void onFlagMicCameraChanged(boolean flag) {
        if (DEBUG) Log.d(TAG, "mic/camera indicators enabled: " + flag);
@@ -155,8 +146,8 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
    private void updateUI() {
        if (DEBUG) Log.d(TAG, mPrivacyItems.size() + " privacy items");

        if ((mMicCameraIndicatorFlagEnabled || mAllIndicatorsFlagEnabled
                || mLocationIndicatorEnabled) && !mPrivacyItems.isEmpty()) {
        if ((mMicCameraIndicatorFlagEnabled || mLocationIndicatorEnabled)
                && !mPrivacyItems.isEmpty()) {
            if (mState == STATE_NOT_SHOWN || mState == STATE_DISAPPEARING) {
                showIndicator();
            } else {
Loading