Distinguish between settings which are permanently unavailable on the device, and temporarily unavailable. This enables us to restrict which setting slices are exposed in onSliceGetDescendants. The primary changes in this CL are renaming: "DISABLED_UNSUPPORTED" -> "UNSUPPORTED_ON_DEVICE" to be more clear the the setting will cannot be accessed on the device, and, adding a new enum to encapsulate settings which are currently unavailable, but could be enabled in the future. Also remove UNAVAILABLE_UNKNOWN. Devs should never need this enum. Bug: 78910582 Bug: 79245656 Test: robotests Change-Id: I58821a6cfd6134b3b351657b6edf5f74ead00643
181 lines
5.9 KiB
Java
181 lines
5.9 KiB
Java
/*
|
|
* Copyright (C) 2016 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 android.app.NotificationManager;
|
|
import androidx.lifecycle.LifecycleObserver;
|
|
import androidx.lifecycle.OnLifecycleEvent;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.media.AudioManager;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import android.os.Vibrator;
|
|
|
|
import com.android.settings.R;
|
|
import com.android.settings.Utils;
|
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
|
|
import java.util.Objects;
|
|
|
|
public class RingVolumePreferenceController extends VolumeSeekBarPreferenceController {
|
|
|
|
private static final String TAG = "RingVolumeController";
|
|
private static final String KEY_RING_VOLUME = "ring_volume";
|
|
|
|
private Vibrator mVibrator;
|
|
private int mRingerMode = -1;
|
|
private ComponentName mSuppressor;
|
|
private final RingReceiver mReceiver = new RingReceiver();
|
|
private final H mHandler = new H();
|
|
|
|
public RingVolumePreferenceController(Context context) {
|
|
this(context, KEY_RING_VOLUME);
|
|
}
|
|
|
|
public RingVolumePreferenceController(Context context, String key) {
|
|
super(context, key);
|
|
mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
|
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
|
mVibrator = null;
|
|
}
|
|
updateRingerMode();
|
|
}
|
|
|
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
mReceiver.register(true);
|
|
updateEffectsSuppressor();
|
|
updatePreferenceIcon();
|
|
}
|
|
|
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
@Override
|
|
public void onPause() {
|
|
super.onPause();
|
|
mReceiver.register(false);
|
|
}
|
|
|
|
@Override
|
|
public String getPreferenceKey() {
|
|
return KEY_RING_VOLUME;
|
|
}
|
|
|
|
@Override
|
|
public int getAvailabilityStatus() {
|
|
return Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume()
|
|
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
|
}
|
|
|
|
@Override
|
|
public int getAudioStream() {
|
|
return AudioManager.STREAM_RING;
|
|
}
|
|
|
|
@Override
|
|
public int getMuteIcon() {
|
|
return R.drawable.ic_volume_ringer_vibrate;
|
|
}
|
|
|
|
private void updateRingerMode() {
|
|
final int ringerMode = mHelper.getRingerModeInternal();
|
|
if (mRingerMode == ringerMode) return;
|
|
mRingerMode = ringerMode;
|
|
updatePreferenceIcon();
|
|
}
|
|
|
|
private boolean wasRingerModeVibrate() {
|
|
return mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_SILENT
|
|
&& mHelper.getLastAudibleStreamVolume(getAudioStream()) == 0;
|
|
}
|
|
|
|
private void updateEffectsSuppressor() {
|
|
final ComponentName suppressor = NotificationManager.from(mContext).getEffectsSuppressor();
|
|
if (Objects.equals(suppressor, mSuppressor)) return;
|
|
mSuppressor = suppressor;
|
|
if (mPreference != null) {
|
|
final String text = SuppressorHelper.getSuppressionText(mContext, suppressor);
|
|
mPreference.setSuppressionText(text);
|
|
}
|
|
updatePreferenceIcon();
|
|
}
|
|
|
|
private void updatePreferenceIcon() {
|
|
if (mPreference != null) {
|
|
mPreference.showIcon(
|
|
mRingerMode == AudioManager.RINGER_MODE_VIBRATE || wasRingerModeVibrate()
|
|
? com.android.internal.R.drawable.ic_audio_ring_notif_vibrate
|
|
: com.android.internal.R.drawable.ic_audio_ring_notif);
|
|
}
|
|
}
|
|
|
|
private final class H extends Handler {
|
|
private static final int UPDATE_EFFECTS_SUPPRESSOR = 1;
|
|
private static final int UPDATE_RINGER_MODE = 2;
|
|
|
|
private H() {
|
|
super(Looper.getMainLooper());
|
|
}
|
|
|
|
@Override
|
|
public void handleMessage(Message msg) {
|
|
switch (msg.what) {
|
|
case UPDATE_EFFECTS_SUPPRESSOR:
|
|
updateEffectsSuppressor();
|
|
break;
|
|
case UPDATE_RINGER_MODE:
|
|
updateRingerMode();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private class RingReceiver extends BroadcastReceiver {
|
|
private boolean mRegistered;
|
|
|
|
public void register(boolean register) {
|
|
if (mRegistered == register) return;
|
|
if (register) {
|
|
final IntentFilter filter = new IntentFilter();
|
|
filter.addAction(NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED);
|
|
filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
|
|
mContext.registerReceiver(this, filter);
|
|
} else {
|
|
mContext.unregisterReceiver(this);
|
|
}
|
|
mRegistered = register;
|
|
}
|
|
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
final String action = intent.getAction();
|
|
if (NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED.equals(action)) {
|
|
mHandler.sendEmptyMessage(H.UPDATE_EFFECTS_SUPPRESSOR);
|
|
} else if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
|
|
mHandler.sendEmptyMessage(H.UPDATE_RINGER_MODE);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|