2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.notification;
19 import android.annotation.UserIdInt;
20 import android.content.Context;
21 import android.media.AudioManager;
22 import android.media.AudioSystem;
23 import android.os.UserHandle;
24 import android.os.UserManager;
25 import android.util.Log;
27 import com.android.settings.Utils;
30 * Helper class to wrap API for testing
32 public class AudioHelper {
34 private static final String TAG = "AudioHelper";
35 private Context mContext;
36 private AudioManager mAudioManager;
38 public AudioHelper(Context context) {
40 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
43 public boolean isSingleVolume() {
44 return AudioSystem.isSingleVolume(mContext);
47 public int getManagedProfileId(UserManager um) {
48 return Utils.getManagedProfileId(um, UserHandle.myUserId());
51 public boolean isUserUnlocked(UserManager um, @UserIdInt int userId) {
52 return um.isUserUnlocked(userId);
55 public Context createPackageContextAsUser(@UserIdInt int profileId) {
56 return Utils.createPackageContextAsUser(mContext, profileId);
59 public int getRingerModeInternal() {
60 return mAudioManager.getRingerModeInternal();
63 public int getLastAudibleStreamVolume(int stream) {
64 return mAudioManager.getLastAudibleStreamVolume(stream);
67 public int getStreamVolume(int stream) {
68 return mAudioManager.getStreamVolume(stream);
71 public boolean setStreamVolume(int stream, int volume) {
72 mAudioManager.setStreamVolume(stream, volume, 0);
76 public int getMaxVolume(int stream) {
77 return mAudioManager.getStreamMaxVolume(stream);
80 public int getMinVolume(int stream) {
83 minVolume = mAudioManager.getStreamMinVolume(stream);
84 } catch (IllegalArgumentException e) {
85 Log.w(TAG, "Invalid stream type " + stream);
86 // Fallback to STREAM_VOICE_CALL because CallVolumePreferenceController.java default
87 // return STREAM_VOICE_CALL in getAudioStream
88 minVolume = mAudioManager.getStreamMinVolume(AudioManager.STREAM_VOICE_CALL);