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

Commit 6984f885 authored by Evan Severson's avatar Evan Severson Committed by Android (Google) Code Review
Browse files

Merge "Unsuppress the sensor privacy dialog immediately positive action" into sc-dev

parents 1db78385 17762821
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.hardware.SensorPrivacyManager.EXTRA_SENSOR
import android.hardware.SensorPrivacyManager.INDIVIDUAL_SENSOR_CAMERA
import android.hardware.SensorPrivacyManager.INDIVIDUAL_SENSOR_MICROPHONE
import android.os.Bundle
import android.os.Handler
import android.text.Html
import android.util.Log
import com.android.internal.app.AlertActivity
@@ -43,10 +44,13 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene

    companion object {
        private val LOG_TAG = SensorUseStartedActivity::class.java.simpleName

        private const val SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS = 2000L
    }

    private var sensor = -1
    private lateinit var sensorUsePackageName: String
    private var unsuppressImmediately = false

    private lateinit var sensorPrivacyManager: SensorPrivacyManager
    private lateinit var appOpsManager: AppOpsManager
@@ -118,6 +122,7 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
        super.onStart()

        sensorPrivacyManager.suppressIndividualSensorPrivacyReminders(sensorUsePackageName, true)
        unsuppressImmediately = false
    }

    override fun onClick(dialog: DialogInterface?, which: Int) {
@@ -131,15 +136,15 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
                        }

                        override fun onDismissSucceeded() {
                            sensorPrivacyManager
                                    .setIndividualSensorPrivacyForProfileGroup(sensor, false)
                            setResult(RESULT_OK)
                            disableSensorPrivacy()
                        }
                    })
                } else {
                    sensorPrivacyManager.setIndividualSensorPrivacyForProfileGroup(sensor, false)
                    setResult(RESULT_OK)
                    disableSensorPrivacy()
                }
            }
            BUTTON_NEGATIVE -> {
                unsuppressImmediately = false
            }
        }

@@ -149,10 +154,24 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
    override fun onStop() {
        super.onDestroy()

        sensorPrivacyManager.suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
        if (unsuppressImmediately) {
            sensorPrivacyManager
                    .suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
        } else {
            Handler(mainLooper).postDelayed({
                sensorPrivacyManager
                        .suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
            }, SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS)
        }
    }

    override fun onBackPressed() {
        // do not allow backing out
    }

    private fun disableSensorPrivacy() {
        sensorPrivacyManager.setIndividualSensorPrivacyForProfileGroup(sensor, false)
        unsuppressImmediately = true
        setResult(RESULT_OK)
    }
}
 No newline at end of file
+8 −6
Original line number Diff line number Diff line
@@ -105,8 +105,6 @@ public final class SensorPrivacyService extends SystemService {

    private static final String TAG = "SensorPrivacyService";

    private static final int SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS = 2000;

    /** Version number indicating compatibility parsing the persisted file */
    private static final int CURRENT_PERSISTENCE_VERSION = 1;
    /** Version number indicating the persisted data needs upgraded to match new internal data
@@ -756,10 +754,7 @@ public final class SensorPrivacyService extends SystemService {

                    suppressPackageReminderTokens.add(token);
                } else {
                    mHandler.postDelayed(PooledLambda.obtainRunnable(
                            SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,
                            this, key, token),
                            SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS);
                    mHandler.removeSuppressPackageReminderToken(key, token);
                }
            }
        }
@@ -1110,6 +1105,13 @@ public final class SensorPrivacyService extends SystemService {
            }
            listeners.finishBroadcast();
        }

        public void removeSuppressPackageReminderToken(Pair<String, UserHandle> key,
                IBinder token) {
            sendMessage(PooledLambda.obtainMessage(
                    SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,
                    mSensorPrivacyServiceImpl, key, token));
        }
    }

    private final class DeathRecipient implements IBinder.DeathRecipient {