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()44     String getDefaultCallRedirectionApp();
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()59     String getDefaultCallScreeningApp();
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 app which fills the {@link android.app.role.RoleManager}
71      * {@link android.app.role.RoleManager#ROLE_DIALER} role.
72      * @return the package name of the app filling the role, {@code null} otherwise}.
73      */
getDefaultDialerApp(int user)74     String getDefaultDialerApp(int user);
75 
76     /**
77      * Observe changes to the package name of the app which fills the
78      * {@link android.app.role.RoleManager} {@link android.app.role.RoleManager#ROLE_DIALER} role.
79      */
observeDefaultDialerApp(Executor executor, IntConsumer observer)80     void observeDefaultDialerApp(Executor executor, IntConsumer observer);
81 
82     /**
83      * Override the {@link android.app.role.RoleManager} default dialer app with another value.
84      * Used for testing purposes only.
85      * @param packageName Package name of the app to fill the default dialer role.  Where
86      *                    {@code null}, the override is removed.
87      */
setTestDefaultDialer(String packageName)88     void setTestDefaultDialer(String packageName);
89 
90     /**
91      * @return List of package names of companion apps, or empty list if there are none.
92      */
getCallCompanionApps()93     List<String> getCallCompanionApps();
94 
95     /**
96      * Set a package to be added to the list of the companion apps. Used for testing purposes only.
97      * @param packageName Package name of the app to be added or removed as an override call
98      *                    companion app.
99      * @param isAdded {@code true} if the specified package should be added, {@code false} if it
100      *                            should be removed.
101      */
addOrRemoveTestCallCompanionApp(String packageName, boolean isAdded)102     void addOrRemoveTestCallCompanionApp(String packageName, boolean isAdded);
103 
104     /**
105      * Using role manager needs to know the current user handle.  Need to make sure the role manager
106      * adapter can pass this to role manager.  As it changes, we'll pass it in.
107      * @param currentUserHandle The new user handle.
108      */
setCurrentUserHandle(UserHandle currentUserHandle)109     void setCurrentUserHandle(UserHandle currentUserHandle);
110 
111     /**
112      * Returns the application label that corresponds to the given package name.
113      * @param packageName A valid package name.
114      * @return Application label for the given package name, or null if not found.
115      */
getApplicationLabelForPackageName(String packageName)116     String getApplicationLabelForPackageName(String packageName);
117 }
118