Home | History | Annotate | Download | only in plugins
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
      5  * except in compliance with the License. You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the
     10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     11  * KIND, either express or implied. See the License for the specific language governing
     12  * permissions and limitations under the License.
     13  */
     14 
     15 package com.android.systemui.plugins;
     16 
     17 import android.annotation.IntegerRes;
     18 import android.content.ComponentName;
     19 import android.media.AudioManager;
     20 import android.media.AudioSystem;
     21 import android.os.Handler;
     22 import android.util.SparseArray;
     23 
     24 import com.android.systemui.plugins.VolumeDialogController.Callbacks;
     25 import com.android.systemui.plugins.VolumeDialogController.State;
     26 import com.android.systemui.plugins.VolumeDialogController.StreamState;
     27 import com.android.systemui.plugins.annotations.DependsOn;
     28 import com.android.systemui.plugins.annotations.ProvidesInterface;
     29 
     30 /**
     31  * Manages the VolumeDialog.
     32  *
     33  * Accessible through {@link PluginDependency}
     34  */
     35 @ProvidesInterface(version = VolumeDialogController.VERSION)
     36 @DependsOn(target = StreamState.class)
     37 @DependsOn(target = State.class)
     38 @DependsOn(target = Callbacks.class)
     39 public interface VolumeDialogController {
     40     int VERSION = 1;
     41 
     42     void setActiveStream(int stream);
     43     void setStreamVolume(int stream, int userLevel);
     44     void setRingerMode(int ringerModeNormal, boolean external);
     45 
     46     boolean hasVibrator();
     47     void vibrate();
     48 
     49     AudioManager getAudioManager();
     50 
     51     void notifyVisible(boolean visible);
     52 
     53     void addCallback(Callbacks callbacks, Handler handler);
     54     void removeCallback(Callbacks callbacks);
     55 
     56     void userActivity();
     57     void getState();
     58 
     59     @ProvidesInterface(version = StreamState.VERSION)
     60     public static final class StreamState {
     61         public static final int VERSION = 1;
     62 
     63         public boolean dynamic;
     64         public int level;
     65         public int levelMin;
     66         public int levelMax;
     67         public boolean muted;
     68         public boolean muteSupported;
     69         public @IntegerRes int name;
     70         public String remoteLabel;
     71         public boolean routedToBluetooth;
     72 
     73         public StreamState copy() {
     74             final StreamState rt = new StreamState();
     75             rt.dynamic = dynamic;
     76             rt.level = level;
     77             rt.levelMin = levelMin;
     78             rt.levelMax = levelMax;
     79             rt.muted = muted;
     80             rt.muteSupported = muteSupported;
     81             rt.name = name;
     82             rt.remoteLabel = remoteLabel;
     83             rt.routedToBluetooth = routedToBluetooth;
     84             return rt;
     85         }
     86     }
     87 
     88     @ProvidesInterface(version = State.VERSION)
     89     public static final class State {
     90         public static final int VERSION = 1;
     91 
     92         public static int NO_ACTIVE_STREAM = -1;
     93 
     94         public final SparseArray<StreamState> states = new SparseArray<>();
     95 
     96         public int ringerModeInternal;
     97         public int ringerModeExternal;
     98         public int zenMode;
     99         public ComponentName effectsSuppressor;
    100         public String effectsSuppressorName;
    101         public int activeStream = NO_ACTIVE_STREAM;
    102 
    103         public State copy() {
    104             final State rt = new State();
    105             for (int i = 0; i < states.size(); i++) {
    106                 rt.states.put(states.keyAt(i), states.valueAt(i).copy());
    107             }
    108             rt.ringerModeExternal = ringerModeExternal;
    109             rt.ringerModeInternal = ringerModeInternal;
    110             rt.zenMode = zenMode;
    111             if (effectsSuppressor != null) {
    112                 rt.effectsSuppressor = effectsSuppressor.clone();
    113             }
    114             rt.effectsSuppressorName = effectsSuppressorName;
    115             rt.activeStream = activeStream;
    116             return rt;
    117         }
    118 
    119         @Override
    120         public String toString() {
    121             return toString(0);
    122         }
    123 
    124         public String toString(int indent) {
    125             final StringBuilder sb = new StringBuilder("{");
    126             if (indent > 0) sep(sb, indent);
    127             for (int i = 0; i < states.size(); i++) {
    128                 if (i > 0) {
    129                     sep(sb, indent);
    130                 }
    131                 final int stream = states.keyAt(i);
    132                 final StreamState ss = states.valueAt(i);
    133                 sb.append(AudioSystem.streamToString(stream)).append(":").append(ss.level)
    134                         .append('[').append(ss.levelMin).append("..").append(ss.levelMax)
    135                         .append(']');
    136                 if (ss.muted) sb.append(" [MUTED]");
    137                 if (ss.dynamic) sb.append(" [DYNAMIC]");
    138             }
    139             sep(sb, indent); sb.append("ringerModeExternal:").append(ringerModeExternal);
    140             sep(sb, indent); sb.append("ringerModeInternal:").append(ringerModeInternal);
    141             sep(sb, indent); sb.append("zenMode:").append(zenMode);
    142             sep(sb, indent); sb.append("effectsSuppressor:").append(effectsSuppressor);
    143             sep(sb, indent); sb.append("effectsSuppressorName:").append(effectsSuppressorName);
    144             sep(sb, indent); sb.append("activeStream:").append(activeStream);
    145             if (indent > 0) sep(sb, indent);
    146             return sb.append('}').toString();
    147         }
    148 
    149         private static void sep(StringBuilder sb, int indent) {
    150             if (indent > 0) {
    151                 sb.append('\n');
    152                 for (int i = 0; i < indent; i++) {
    153                     sb.append(' ');
    154                 }
    155             } else {
    156                 sb.append(',');
    157             }
    158         }
    159     }
    160 
    161     @ProvidesInterface(version = Callbacks.VERSION)
    162     public interface Callbacks {
    163         int VERSION = 1;
    164 
    165         void onShowRequested(int reason);
    166         void onDismissRequested(int reason);
    167         void onStateChanged(State state);
    168         void onLayoutDirectionChanged(int layoutDirection);
    169         void onConfigurationChanged();
    170         void onShowVibrateHint();
    171         void onShowSilentHint();
    172         void onScreenOff();
    173         void onShowSafetyWarning(int flags);
    174         void onAccessibilityModeChanged(Boolean showA11yStream);
    175     }
    176 }
    177