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.server.telecom;
18 
19 import android.content.Intent;
20 import android.os.UserHandle;
21 
22 import java.util.List;
23 import java.util.concurrent.Executor;
24 import java.util.function.IntConsumer;
25 
26 /**
27  * Provides a means of wrapping {@code RoleManager} operations which Telecom uses to aid in testing
28  * and remove direct dependencies.
29  */
30 public interface RoleManagerAdapter {
31 
32     /**
33      * The name of the dialer role.
34      *
35      * @see Intent#ACTION_DIAL
36      */
37     String ROLE_DIALER = "android.app.role.DIALER";
38 
39     /**
40      * Returns the package name of the app which fills the {@link android.app.role.RoleManager} call
41      * redirection role.
42      * @return the package name of the app filling the role, {@code null} otherwise}.
43      */
getDefaultCallRedirectionApp(UserHandle userHandle)44     String getDefaultCallRedirectionApp(UserHandle userHandle);
45 
46     /**
47      * Override the {@link android.app.role.RoleManager} call redirection app with another value.
48      * Used for testing purposes only.
49      * @param packageName Package name of the app to fill the call redirection role.  Where
50      *                    {@code null}, the override is removed.
51      */
setTestDefaultCallRedirectionApp(String packageName)52     void setTestDefaultCallRedirectionApp(String packageName);
53 
54     /**
55      * Returns the package name of the app which fills the {@link android.app.role.RoleManager} call
56      * screening role.
57      * @return the package name of the app filling the role, {@code null} otherwise.
58      */
getDefaultCallScreeningApp(UserHandle userHandle)59     String getDefaultCallScreeningApp(UserHandle userHandle);
60 
61     /**
62      * Override the {@link android.app.role.RoleManager} call screening app with another value.
63      * Used for testing purposes only.
64      * @param packageName Package name of the app to fill the call screening role.  Where
65      *                    {@code null}, the override is removed.
66      */
setTestDefaultCallScreeningApp(String packageName)67     void setTestDefaultCallScreeningApp(String packageName);
68 
69     /**
70      * Returns the package name of the package which fills the {@link android.app.role.RoleManager}
71      * bt in-call service role.
72      * @return the package name of the package filling the role, {@code null} otherwise.
73      */
getBTInCallService()74     String[] getBTInCallService();
75 
76     /**
77      * Override the {@link android.app.role.RoleManager} bt in-call service package with another
78      * value.
79      * Used for testing purposes only.
80      * @param packageName Package name of the package to fill the bt in-call service role. Where
81      *                    {@code null}, the override is removed.
82      */
setTestBTInCallService(String packageName)83     void setTestBTInCallService(String packageName);
84 
85     /**
86      * Returns the package name of the app which fills the {@link android.app.role.RoleManager}
87      * {@link android.app.role.RoleManager#ROLE_DIALER} role.
88      * @return the package name of the app filling the role, {@code null} otherwise.
89      */
getDefaultDialerApp(int user)90     String getDefaultDialerApp(int user);
91 
92     /**
93      * Observe changes to the package name of the app which fills the
94      * {@link android.app.role.RoleManager} {@link android.app.role.RoleManager#ROLE_DIALER} role.
95      */
observeDefaultDialerApp(Executor executor, IntConsumer observer)96     void observeDefaultDialerApp(Executor executor, IntConsumer observer);
97 
98     /**
99      * Override the {@link android.app.role.RoleManager} default dialer app with another value.
100      * Used for testing purposes only.
101      * @param packageName Package name of the app to fill the default dialer role.  Where
102      *                    {@code null}, the override is removed.
103      */
setTestDefaultDialer(String packageName)104     void setTestDefaultDialer(String packageName);
105 
106     /**
107      * @return List of package names of companion apps, or empty list if there are none.
108      */
getCallCompanionApps()109     List<String> getCallCompanionApps();
110 
111     /**
112      * Set a package to be added to the list of the companion apps. Used for testing purposes only.
113      * @param packageName Package name of the app to be added or removed as an override call
114      *                    companion app.
115      * @param isAdded {@code true} if the specified package should be added, {@code false} if it
116      *                            should be removed.
117      */
addOrRemoveTestCallCompanionApp(String packageName, boolean isAdded)118     void addOrRemoveTestCallCompanionApp(String packageName, boolean isAdded);
119 
120     /**
121      * Using role manager needs to know the current user handle.  Need to make sure the role manager
122      * adapter can pass this to role manager.  As it changes, we'll pass it in.
123      * @param currentUserHandle The new user handle.
124      */
setCurrentUserHandle(UserHandle currentUserHandle)125     void setCurrentUserHandle(UserHandle currentUserHandle);
126 
127     /**
128      * Returns the application label that corresponds to the given package name.
129      * @param packageName A valid package name.
130      * @return Application label for the given package name, or null if not found.
131      */
getApplicationLabelForPackageName(String packageName)132     String getApplicationLabelForPackageName(String packageName);
133 }
134