Merge UP1A.230905.019
Merged-In: Ifc048311746c027e3683cdcf65f1079d04cf7c56 Change-Id: I2a988e3da0958f31323f95588e1ac66482186ecf
This commit is contained in:
@@ -7151,6 +7151,18 @@
|
|||||||
<!-- Sound: Title for the option managing notification volume. [CHAR LIMIT=30] -->
|
<!-- Sound: Title for the option managing notification volume. [CHAR LIMIT=30] -->
|
||||||
<string name="notification_volume_option_title">Notification volume</string>
|
<string name="notification_volume_option_title">Notification volume</string>
|
||||||
|
|
||||||
|
<!-- Sound: Content description of ring volume title in silent mode. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=8994620163934249882] -->
|
||||||
|
<string name="ringer_content_description_silent_mode">Ringer silent</string>
|
||||||
|
|
||||||
|
<!-- Sound: Content description of ring volume title in vibrate mode. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=6261841170896561364] -->
|
||||||
|
<string name="ringer_content_description_vibrate_mode">Ringer vibrate</string>
|
||||||
|
|
||||||
|
<!-- Sound: Content description of notification volume title in vibrate mode. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="notification_volume_content_description_vibrate_mode">Notification volume muted, notifications will vibrate</string>
|
||||||
|
|
||||||
|
<!-- Sound: Content description of volume title in silent mode [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="volume_content_description_silent_mode"> <xliff:g id="volume type" example="notification volume">%1$s</xliff:g> muted</string>
|
||||||
|
|
||||||
<!-- Sound: Summary for when notification volume is disabled. [CHAR LIMIT=100] -->
|
<!-- Sound: Summary for when notification volume is disabled. [CHAR LIMIT=100] -->
|
||||||
<string name="notification_volume_disabled_summary">Unavailable because ring is muted</string>
|
<string name="notification_volume_disabled_summary">Unavailable because ring is muted</string>
|
||||||
|
|
||||||
|
@@ -81,6 +81,8 @@ public class ApprovalPreferenceController extends BasePreferenceController {
|
|||||||
final RestrictedSwitchPreference preference =
|
final RestrictedSwitchPreference preference =
|
||||||
(RestrictedSwitchPreference) pref;
|
(RestrictedSwitchPreference) pref;
|
||||||
final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
|
final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
|
||||||
|
final boolean isAllowedCn = mCn.flattenToShortString().length()
|
||||||
|
<= NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH;
|
||||||
final boolean isEnabled = isServiceEnabled(mCn);
|
final boolean isEnabled = isServiceEnabled(mCn);
|
||||||
preference.setChecked(isEnabled);
|
preference.setChecked(isEnabled);
|
||||||
preference.setOnPreferenceChangeListener((p, newValue) -> {
|
preference.setOnPreferenceChangeListener((p, newValue) -> {
|
||||||
@@ -105,7 +107,8 @@ public class ApprovalPreferenceController extends BasePreferenceController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
preference.updateState(mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isEnabled);
|
preference.updateState(
|
||||||
|
mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isAllowedCn, isEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable(final ComponentName cn) {
|
public void disable(final ComponentName cn) {
|
||||||
|
@@ -623,9 +623,9 @@ public class FingerprintSettings extends SubSettings {
|
|||||||
return; // Activity went away
|
return; // Activity went away
|
||||||
}
|
}
|
||||||
|
|
||||||
final Preference addPreference = findPreference(KEY_FINGERPRINT_ADD);
|
mAddFingerprintPreference = findPreference(KEY_FINGERPRINT_ADD);
|
||||||
|
|
||||||
if (addPreference == null) {
|
if (mAddFingerprintPreference == null) {
|
||||||
return; // b/275519315 Skip if updateAddPreference() invoke before addPreference()
|
return; // b/275519315 Skip if updateAddPreference() invoke before addPreference()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,6 +52,7 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont
|
|||||||
|
|
||||||
public MediaVolumePreferenceController(Context context) {
|
public MediaVolumePreferenceController(Context context) {
|
||||||
super(context, KEY_MEDIA_VOLUME);
|
super(context, KEY_MEDIA_VOLUME);
|
||||||
|
mVolumePreferenceListener = this::updateContentDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -109,6 +110,18 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateContentDescription() {
|
||||||
|
if (mPreference != null) {
|
||||||
|
if (mPreference.isMuted()) {
|
||||||
|
mPreference.updateContentDescription(
|
||||||
|
mContext.getString(R.string.volume_content_description_silent_mode,
|
||||||
|
mPreference.getTitle()));
|
||||||
|
} else {
|
||||||
|
mPreference.updateContentDescription(mPreference.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SliceAction getSliceEndItem(Context context) {
|
public SliceAction getSliceEndItem(Context context) {
|
||||||
if (!isSupportEndItem()) {
|
if (!isSupportEndItem()) {
|
||||||
|
@@ -67,7 +67,9 @@ public class NotificationAccessConfirmationActivity extends Activity
|
|||||||
mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
|
mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
|
||||||
CharSequence mAppLabel;
|
CharSequence mAppLabel;
|
||||||
|
|
||||||
if (mComponentName == null || mComponentName.getPackageName() == null) {
|
if (mComponentName == null || mComponentName.getPackageName() == null
|
||||||
|
|| mComponentName.flattenToString().length()
|
||||||
|
> NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -66,7 +66,6 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
|||||||
private static final String TAG = "NotifAccessSettings";
|
private static final String TAG = "NotifAccessSettings";
|
||||||
static final String ALLOWED_KEY = "allowed";
|
static final String ALLOWED_KEY = "allowed";
|
||||||
static final String NOT_ALLOWED_KEY = "not_allowed";
|
static final String NOT_ALLOWED_KEY = "not_allowed";
|
||||||
private static final int MAX_CN_LENGTH = 500;
|
|
||||||
|
|
||||||
private static final ManagedServiceSettings.Config CONFIG =
|
private static final ManagedServiceSettings.Config CONFIG =
|
||||||
new ManagedServiceSettings.Config.Builder()
|
new ManagedServiceSettings.Config.Builder()
|
||||||
@@ -150,7 +149,8 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
|||||||
for (ServiceInfo service : services) {
|
for (ServiceInfo service : services) {
|
||||||
final ComponentName cn = new ComponentName(service.packageName, service.name);
|
final ComponentName cn = new ComponentName(service.packageName, service.name);
|
||||||
boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
|
boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
|
||||||
if (!isAllowed && cn.flattenToString().length() > MAX_CN_LENGTH) {
|
if (!isAllowed && cn.flattenToString().length()
|
||||||
|
> NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ import android.os.Handler;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -75,6 +76,7 @@ public class NotificationVolumePreferenceController extends
|
|||||||
|
|
||||||
updateEffectsSuppressor();
|
updateEffectsSuppressor();
|
||||||
selectPreferenceIconState();
|
selectPreferenceIconState();
|
||||||
|
updateContentDescription();
|
||||||
updateEnabledState();
|
updateEnabledState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,23 +122,37 @@ public class NotificationVolumePreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void selectPreferenceIconState() {
|
protected int getEffectiveRingerMode() {
|
||||||
|
if (mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
|
return AudioManager.RINGER_MODE_SILENT;
|
||||||
|
} else if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
|
||||||
|
if (mHelper.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
|
||||||
|
// Ring is in normal, but notification is in silent.
|
||||||
|
return AudioManager.RINGER_MODE_SILENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mRingerMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateContentDescription() {
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
if (mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
int ringerMode = getEffectiveRingerMode();
|
||||||
mMuteIcon = mVibrateIconId;
|
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
mPreference.showIcon(mVibrateIconId);
|
mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
|
||||||
} else if (mRingerMode == AudioManager.RINGER_MODE_SILENT
|
mPreference.updateContentDescription(
|
||||||
|| mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
mContext.getString(
|
||||||
mMuteIcon = mSilentIconId;
|
R.string.notification_volume_content_description_vibrate_mode));
|
||||||
mPreference.showIcon(mSilentIconId);
|
} else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
|
||||||
} else { // ringmode normal: could be that we are still silent
|
mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
|
||||||
if (mHelper.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
|
mPreference.updateContentDescription(
|
||||||
// ring is in normal, but notification is in silent
|
mContext.getString(R.string.volume_content_description_silent_mode,
|
||||||
mMuteIcon = mSilentIconId;
|
mPreference.getTitle()));
|
||||||
mPreference.showIcon(mSilentIconId);
|
} else {
|
||||||
} else {
|
// Set a11y mode to none in order not to trigger talkback while changing
|
||||||
mPreference.showIcon(mNormalIconId);
|
// notification volume in normal mode.
|
||||||
}
|
mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_NONE);
|
||||||
|
mPreference.updateContentDescription(mPreference.getTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +185,7 @@ public class NotificationVolumePreferenceController extends
|
|||||||
break;
|
break;
|
||||||
case NOTIFICATION_VOLUME_CHANGED:
|
case NOTIFICATION_VOLUME_CHANGED:
|
||||||
selectPreferenceIconState();
|
selectPreferenceIconState();
|
||||||
|
updateContentDescription();
|
||||||
updateEnabledState();
|
updateEnabledState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ import android.os.Vibrator;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
|
|||||||
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
||||||
mVibrator = null;
|
mVibrator = null;
|
||||||
}
|
}
|
||||||
|
mVolumePreferenceListener = this::updateContentDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateEffectsSuppressor() {
|
protected void updateEffectsSuppressor() {
|
||||||
@@ -123,6 +125,7 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
|
|||||||
}
|
}
|
||||||
mRingerMode = ringerMode;
|
mRingerMode = ringerMode;
|
||||||
selectPreferenceIconState();
|
selectPreferenceIconState();
|
||||||
|
updateContentDescription();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,10 +134,11 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
|
|||||||
*/
|
*/
|
||||||
protected void selectPreferenceIconState() {
|
protected void selectPreferenceIconState() {
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
|
int ringerMode = getEffectiveRingerMode();
|
||||||
|
if (ringerMode == AudioManager.RINGER_MODE_NORMAL) {
|
||||||
mPreference.showIcon(mNormalIconId);
|
mPreference.showIcon(mNormalIconId);
|
||||||
} else {
|
} else {
|
||||||
if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE && mVibrator != null) {
|
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
mMuteIcon = mVibrateIconId;
|
mMuteIcon = mVibrateIconId;
|
||||||
} else {
|
} else {
|
||||||
mMuteIcon = mSilentIconId;
|
mMuteIcon = mSilentIconId;
|
||||||
@@ -144,6 +148,28 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getEffectiveRingerMode() {
|
||||||
|
if (mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
|
return AudioManager.RINGER_MODE_SILENT;
|
||||||
|
}
|
||||||
|
return mRingerMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateContentDescription() {
|
||||||
|
if (mPreference != null) {
|
||||||
|
int ringerMode = getEffectiveRingerMode();
|
||||||
|
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
|
mPreference.updateContentDescription(
|
||||||
|
mContext.getString(R.string.ringer_content_description_vibrate_mode));
|
||||||
|
} else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
|
||||||
|
mPreference.updateContentDescription(
|
||||||
|
mContext.getString(R.string.ringer_content_description_silent_mode));
|
||||||
|
} else {
|
||||||
|
mPreference.updateContentDescription(mPreference.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract boolean hintsMatch(int hints);
|
protected abstract boolean hintsMatch(int hints);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,7 @@ public class SeparateRingVolumePreferenceController extends
|
|||||||
mReceiver.register(true);
|
mReceiver.register(true);
|
||||||
updateEffectsSuppressor();
|
updateEffectsSuppressor();
|
||||||
selectPreferenceIconState();
|
selectPreferenceIconState();
|
||||||
|
updateContentDescription();
|
||||||
|
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
|
mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
|
||||||
|
@@ -47,10 +47,13 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
|
|
||||||
protected SeekBar mSeekBar;
|
protected SeekBar mSeekBar;
|
||||||
private int mStream;
|
private int mStream;
|
||||||
private SeekBarVolumizer mVolumizer;
|
@VisibleForTesting
|
||||||
|
SeekBarVolumizer mVolumizer;
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
|
private Listener mListener;
|
||||||
private ImageView mIconView;
|
private ImageView mIconView;
|
||||||
private TextView mSuppressionTextView;
|
private TextView mSuppressionTextView;
|
||||||
|
private TextView mTitle;
|
||||||
private String mSuppressionText;
|
private String mSuppressionText;
|
||||||
private boolean mMuted;
|
private boolean mMuted;
|
||||||
private boolean mZenMuted;
|
private boolean mZenMuted;
|
||||||
@@ -98,6 +101,10 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setListener(Listener listener) {
|
||||||
|
mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
public void onActivityResume() {
|
public void onActivityResume() {
|
||||||
if (mStopped) {
|
if (mStopped) {
|
||||||
init();
|
init();
|
||||||
@@ -118,6 +125,7 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
|
mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
|
||||||
mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
|
mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
|
||||||
mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text);
|
mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text);
|
||||||
|
mTitle = (TextView) view.findViewById(com.android.internal.R.id.title);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +150,9 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mMuted = muted;
|
mMuted = muted;
|
||||||
mZenMuted = zenMuted;
|
mZenMuted = zenMuted;
|
||||||
updateIconView();
|
updateIconView();
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onUpdateMuteState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onStartTrackingTouch(SeekBarVolumizer sbv) {
|
public void onStartTrackingTouch(SeekBarVolumizer sbv) {
|
||||||
@@ -165,6 +176,9 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mVolumizer.setSeekBar(mSeekBar);
|
mVolumizer.setSeekBar(mSeekBar);
|
||||||
updateIconView();
|
updateIconView();
|
||||||
updateSuppressionText();
|
updateSuppressionText();
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onUpdateMuteState();
|
||||||
|
}
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
mSeekBar.setEnabled(false);
|
mSeekBar.setEnabled(false);
|
||||||
mVolumizer.stop();
|
mVolumizer.stop();
|
||||||
@@ -175,7 +189,7 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
if (mIconView == null) return;
|
if (mIconView == null) return;
|
||||||
if (mIconResId != 0) {
|
if (mIconResId != 0) {
|
||||||
mIconView.setImageResource(mIconResId);
|
mIconView.setImageResource(mIconResId);
|
||||||
} else if (mMuteIconResId != 0 && mMuted && !mZenMuted) {
|
} else if (mMuteIconResId != 0 && isMuted()) {
|
||||||
mIconView.setImageResource(mMuteIconResId);
|
mIconView.setImageResource(mMuteIconResId);
|
||||||
} else {
|
} else {
|
||||||
mIconView.setImageDrawable(getIcon());
|
mIconView.setImageDrawable(getIcon());
|
||||||
@@ -208,6 +222,10 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
updateSuppressionText();
|
updateSuppressionText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isMuted() {
|
||||||
|
return mMuted && !mZenMuted;
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateSuppressionText() {
|
protected void updateSuppressionText() {
|
||||||
if (mSuppressionTextView != null && mSeekBar != null) {
|
if (mSuppressionTextView != null && mSeekBar != null) {
|
||||||
mSuppressionTextView.setText(mSuppressionText);
|
mSuppressionTextView.setText(mSuppressionText);
|
||||||
@@ -216,6 +234,19 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update content description of title to improve talkback announcements.
|
||||||
|
*/
|
||||||
|
protected void updateContentDescription(CharSequence contentDescription) {
|
||||||
|
if (mTitle == null) return;
|
||||||
|
mTitle.setContentDescription(contentDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setAccessibilityLiveRegion(int mode) {
|
||||||
|
if (mTitle == null) return;
|
||||||
|
mTitle.setAccessibilityLiveRegion(mode);
|
||||||
|
}
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void onSampleStarting(SeekBarVolumizer sbv);
|
void onSampleStarting(SeekBarVolumizer sbv);
|
||||||
void onStreamValueChanged(int stream, int progress);
|
void onStreamValueChanged(int stream, int progress);
|
||||||
@@ -225,4 +256,15 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
*/
|
*/
|
||||||
void onStartTrackingTouch(SeekBarVolumizer sbv);
|
void onStartTrackingTouch(SeekBarVolumizer sbv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener to view updates in volumeSeekbarPreference.
|
||||||
|
*/
|
||||||
|
public interface Listener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener to mute state updates.
|
||||||
|
*/
|
||||||
|
void onUpdateMuteState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@ public abstract class VolumeSeekBarPreferenceController extends
|
|||||||
protected VolumeSeekBarPreference mPreference;
|
protected VolumeSeekBarPreference mPreference;
|
||||||
protected VolumeSeekBarPreference.Callback mVolumePreferenceCallback;
|
protected VolumeSeekBarPreference.Callback mVolumePreferenceCallback;
|
||||||
protected AudioHelper mHelper;
|
protected AudioHelper mHelper;
|
||||||
|
protected VolumeSeekBarPreference.Listener mVolumePreferenceListener;
|
||||||
|
|
||||||
public VolumeSeekBarPreferenceController(Context context, String key) {
|
public VolumeSeekBarPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
@@ -62,6 +63,7 @@ public abstract class VolumeSeekBarPreferenceController extends
|
|||||||
protected void setupVolPreference(PreferenceScreen screen) {
|
protected void setupVolPreference(PreferenceScreen screen) {
|
||||||
mPreference = screen.findPreference(getPreferenceKey());
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
mPreference.setCallback(mVolumePreferenceCallback);
|
mPreference.setCallback(mVolumePreferenceCallback);
|
||||||
|
mPreference.setListener(mVolumePreferenceListener);
|
||||||
mPreference.setStream(getAudioStream());
|
mPreference.setStream(getAudioStream());
|
||||||
mPreference.setMuteIcon(getMuteIcon());
|
mPreference.setMuteIcon(getMuteIcon());
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.notification;
|
||||||
|
|
||||||
|
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class NotificationAccessConfirmationActivityTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void start_showsDialog() {
|
||||||
|
ComponentName cn = new ComponentName("com.example", "com.example.SomeService");
|
||||||
|
installPackage(cn.getPackageName(), "X");
|
||||||
|
|
||||||
|
NotificationAccessConfirmationActivity activity = startActivityWithIntent(cn);
|
||||||
|
|
||||||
|
assertThat(activity.isFinishing()).isFalse();
|
||||||
|
assertThat(getDialogText(activity)).isEqualTo(
|
||||||
|
activity.getString(R.string.notification_listener_security_warning_summary, "X"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void start_withMissingPackage_finishes() {
|
||||||
|
ComponentName cn = new ComponentName("com.example", "com.example.SomeService");
|
||||||
|
|
||||||
|
NotificationAccessConfirmationActivity activity = startActivityWithIntent(cn);
|
||||||
|
|
||||||
|
assertThat(getDialogText(activity)).isNull();
|
||||||
|
assertThat(activity.isFinishing()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void start_componentNameTooLong_finishes() {
|
||||||
|
ComponentName longCn = new ComponentName("com.example", Strings.repeat("Blah", 150));
|
||||||
|
installPackage(longCn.getPackageName(), "<Unused>");
|
||||||
|
|
||||||
|
NotificationAccessConfirmationActivity activity = startActivityWithIntent(longCn);
|
||||||
|
|
||||||
|
assertThat(getDialogText(activity)).isNull();
|
||||||
|
assertThat(activity.isFinishing()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NotificationAccessConfirmationActivity startActivityWithIntent(
|
||||||
|
ComponentName cn) {
|
||||||
|
return Robolectric.buildActivity(
|
||||||
|
NotificationAccessConfirmationActivity.class,
|
||||||
|
new Intent().putExtra(EXTRA_COMPONENT_NAME, cn))
|
||||||
|
.setup()
|
||||||
|
.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void installPackage(String packageName, String appName) {
|
||||||
|
PackageInfo pi = new PackageInfo();
|
||||||
|
pi.packageName = packageName;
|
||||||
|
pi.applicationInfo = new ApplicationInfo();
|
||||||
|
pi.applicationInfo.packageName = packageName;
|
||||||
|
pi.applicationInfo.name = appName;
|
||||||
|
shadowOf(RuntimeEnvironment.application.getPackageManager()).installPackage(pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static String getDialogText(Activity activity) {
|
||||||
|
TextView tv = activity.getWindow().findViewById(android.R.id.message);
|
||||||
|
CharSequence text = (tv != null ? tv.getText() : null);
|
||||||
|
return text != null ? text.toString() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -49,6 +49,8 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private VolumeSeekBarPreference.Callback mCallback;
|
private VolumeSeekBarPreference.Callback mCallback;
|
||||||
@Mock
|
@Mock
|
||||||
|
private VolumeSeekBarPreference.Listener mListener;
|
||||||
|
@Mock
|
||||||
private AudioHelper mHelper;
|
private AudioHelper mHelper;
|
||||||
|
|
||||||
private VolumeSeekBarPreferenceControllerTestable mController;
|
private VolumeSeekBarPreferenceControllerTestable mController;
|
||||||
@@ -59,7 +61,7 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
|
when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
|
||||||
when(mPreference.getKey()).thenReturn("key");
|
when(mPreference.getKey()).thenReturn("key");
|
||||||
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, true,
|
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, true,
|
||||||
mPreference.getKey());
|
mPreference.getKey(), mListener);
|
||||||
mController.setAudioHelper(mHelper);
|
mController.setAudioHelper(mHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,18 +72,20 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
verify(mPreference).setCallback(mCallback);
|
verify(mPreference).setCallback(mCallback);
|
||||||
verify(mPreference).setStream(VolumeSeekBarPreferenceControllerTestable.AUDIO_STREAM);
|
verify(mPreference).setStream(VolumeSeekBarPreferenceControllerTestable.AUDIO_STREAM);
|
||||||
verify(mPreference).setMuteIcon(VolumeSeekBarPreferenceControllerTestable.MUTE_ICON);
|
verify(mPreference).setMuteIcon(VolumeSeekBarPreferenceControllerTestable.MUTE_ICON);
|
||||||
|
verify(mPreference).setListener(mListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_notAvailable_shouldNotUpdatePreference() {
|
public void displayPreference_notAvailable_shouldNotUpdatePreference() {
|
||||||
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, false,
|
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, false,
|
||||||
mPreference.getKey());
|
mPreference.getKey(), mListener);
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
verify(mPreference, never()).setCallback(any(VolumeSeekBarPreference.Callback.class));
|
verify(mPreference, never()).setCallback(any(VolumeSeekBarPreference.Callback.class));
|
||||||
verify(mPreference, never()).setStream(anyInt());
|
verify(mPreference, never()).setStream(anyInt());
|
||||||
verify(mPreference, never()).setMuteIcon(anyInt());
|
verify(mPreference, never()).setMuteIcon(anyInt());
|
||||||
|
verify(mPreference, never()).setListener(mListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,10 +161,12 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
private boolean mAvailable;
|
private boolean mAvailable;
|
||||||
|
|
||||||
VolumeSeekBarPreferenceControllerTestable(Context context,
|
VolumeSeekBarPreferenceControllerTestable(Context context,
|
||||||
VolumeSeekBarPreference.Callback callback, boolean available, String key) {
|
VolumeSeekBarPreference.Callback callback, boolean available, String key,
|
||||||
|
VolumeSeekBarPreference.Listener listener) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
setCallback(callback);
|
setCallback(callback);
|
||||||
mAvailable = available;
|
mAvailable = available;
|
||||||
|
mVolumePreferenceListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,11 +18,14 @@ package com.android.settings.notification;
|
|||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.doCallRealMethod;
|
import static org.mockito.Mockito.doCallRealMethod;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.preference.SeekBarVolumizer;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -34,18 +37,28 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class VolumeSeekBarPreferenceTest {
|
public class VolumeSeekBarPreferenceTest {
|
||||||
|
|
||||||
|
private static final CharSequence CONTENT_DESCRIPTION = "TEST";
|
||||||
@Mock
|
@Mock
|
||||||
private AudioManager mAudioManager;
|
private AudioManager mAudioManager;
|
||||||
@Mock
|
@Mock
|
||||||
private VolumeSeekBarPreference mPreference;
|
private VolumeSeekBarPreference mPreference;
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private SeekBar mSeekBar;
|
||||||
|
@Mock
|
||||||
|
private SeekBarVolumizer mVolumizer;
|
||||||
|
private VolumeSeekBarPreference.Listener mListener;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
|
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
|
||||||
|
doCallRealMethod().when(mPreference).updateContentDescription(CONTENT_DESCRIPTION);
|
||||||
|
mPreference.mSeekBar = mSeekBar;
|
||||||
mPreference.mAudioManager = mAudioManager;
|
mPreference.mAudioManager = mAudioManager;
|
||||||
|
mPreference.mVolumizer = mVolumizer;
|
||||||
|
mListener = () -> mPreference.updateContentDescription(CONTENT_DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -65,4 +78,24 @@ public class VolumeSeekBarPreferenceTest {
|
|||||||
verify(mPreference).setMin(min);
|
verify(mPreference).setMin(min);
|
||||||
verify(mPreference).setProgress(progress);
|
verify(mPreference).setProgress(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void init_listenerIsCalled() {
|
||||||
|
doCallRealMethod().when(mPreference).setListener(mListener);
|
||||||
|
doCallRealMethod().when(mPreference).init();
|
||||||
|
|
||||||
|
mPreference.setListener(mListener);
|
||||||
|
mPreference.init();
|
||||||
|
|
||||||
|
verify(mPreference).updateContentDescription(CONTENT_DESCRIPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void init_listenerNotSet_noException() {
|
||||||
|
doCallRealMethod().when(mPreference).init();
|
||||||
|
|
||||||
|
mPreference.init();
|
||||||
|
|
||||||
|
verify(mPreference, never()).updateContentDescription(CONTENT_DESCRIPTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -83,6 +83,36 @@ public class ApprovalPreferenceControllerTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_enabled() {
|
||||||
|
when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
|
||||||
|
AppOpsManager.MODE_ALLOWED);
|
||||||
|
when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
|
||||||
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
|
||||||
|
mContext);
|
||||||
|
pref.setAppOps(mAppOpsManager);
|
||||||
|
|
||||||
|
mController.updateState(pref);
|
||||||
|
|
||||||
|
assertThat(pref.isEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_invalidCn_disabled() {
|
||||||
|
ComponentName longCn = new ComponentName("com.example.package",
|
||||||
|
com.google.common.base.Strings.repeat("Blah", 150));
|
||||||
|
mController.setCn(longCn);
|
||||||
|
when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
|
||||||
|
AppOpsManager.MODE_ALLOWED);
|
||||||
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
|
||||||
|
mContext);
|
||||||
|
pref.setAppOps(mAppOpsManager);
|
||||||
|
|
||||||
|
mController.updateState(pref);
|
||||||
|
|
||||||
|
assertThat(pref.isEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_checked() {
|
public void updateState_checked() {
|
||||||
when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
|
when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
|
||||||
|
Reference in New Issue
Block a user