• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.car.settings.testutils;
18 
19 import android.content.Context;
20 import android.media.Ringtone;
21 import android.media.RingtoneManager;
22 import android.net.Uri;
23 
24 import org.robolectric.annotation.Implementation;
25 import org.robolectric.annotation.Implements;
26 import org.robolectric.annotation.Resetter;
27 
28 import java.util.HashMap;
29 import java.util.Map;
30 
31 @Implements(RingtoneManager.class)
32 public class ShadowRingtoneManager {
33     private static Ringtone sRingtone;
34     private static Map<Integer, Uri> sSetDefaultRingtoneCalled = new HashMap<>();
35 
setRingtone(Ringtone ringtone)36     public static void setRingtone(Ringtone ringtone) {
37         sRingtone = ringtone;
38     }
39 
40     @Implementation
getRingtone(final Context context, Uri ringtoneUri)41     protected static Ringtone getRingtone(final Context context, Uri ringtoneUri) {
42         return sRingtone;
43     }
44 
45     @Implementation
setActualDefaultRingtoneUri(Context context, int type, Uri ringtoneUri)46     public static void setActualDefaultRingtoneUri(Context context, int type, Uri ringtoneUri) {
47         sSetDefaultRingtoneCalled.put(type, ringtoneUri);
48     }
49 
50     @Implementation
getActualDefaultRingtoneUri(Context context, int type)51     public static Uri getActualDefaultRingtoneUri(Context context, int type) {
52         return sSetDefaultRingtoneCalled.getOrDefault(type, null);
53     }
54 
55     @Resetter
reset()56     public static void reset() {
57         sRingtone = null;
58         sSetDefaultRingtoneCalled.clear();
59     }
60 }
61