1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.settings.notification; 18 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 com.android.settings.Utils; 26 27 /** 28 * Helper class to wrap API for testing 29 */ 30 public class AudioHelper { 31 32 private Context mContext; 33 private AudioManager mAudioManager; 34 35 public AudioHelper(Context context) { 36 mContext = context; 37 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); 38 } 39 40 public boolean isSingleVolume() { 41 return AudioSystem.isSingleVolume(mContext); 42 } 43 44 public int getManagedProfileId(UserManager um) { 45 return Utils.getManagedProfileId(um, UserHandle.myUserId()); 46 } 47 48 public boolean isUserUnlocked(UserManager um, @UserIdInt int userId) { 49 return um.isUserUnlocked(userId); 50 } 51 52 public Context createPackageContextAsUser(@UserIdInt int profileId) { 53 return Utils.createPackageContextAsUser(mContext, profileId); 54 } 55 56 public int getRingerModeInternal() { 57 return mAudioManager.getRingerModeInternal(); 58 } 59 60 public int getLastAudibleStreamVolume(int stream) { 61 return mAudioManager.getLastAudibleStreamVolume(stream); 62 } 63 64 public int getStreamVolume(int stream) { 65 return mAudioManager.getStreamVolume(stream); 66 } 67 68 public boolean setStreamVolume(int stream, int volume) { 69 mAudioManager.setStreamVolume(stream, volume, 0); 70 return true; 71 } 72 73 public int getMaxVolume(int stream) { 74 return mAudioManager.getStreamMaxVolume(stream); 75 } 76 } 77