blob: d1ff56f25fc5f6e6044a48ddd0f7341f5d61b350 [file] [log] [blame]
James.cf Linaf3183c2019-10-24 00:59:00 +08001/*
2 * Copyright (C) 2019 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
17package com.android.phone;
18
19import android.content.Context;
20import android.net.Uri;
21import android.os.ServiceManager;
22import android.telephony.ims.aidl.IImsCapabilityCallback;
23import android.telephony.ims.aidl.IImsRcsController;
24import android.telephony.ims.aidl.IRcsUceControllerCallback;
25import android.telephony.ims.feature.RcsFeature;
26import android.util.Log;
27
28import java.util.List;
29
30/**
31 * Implementation of the IImsRcsController interface.
32 */
33public class ImsRcsController extends IImsRcsController.Stub {
34 private static final String TAG = "ImsRcsController";
35
36 /** The singleton instance. */
37 private static ImsRcsController sInstance;
38
39 private PhoneGlobals mApp;
40
41 /**
42 * Initialize the singleton ImsRcsController instance.
43 * This is only done once, at startup, from PhoneApp.onCreate().
44 */
45 static ImsRcsController init(PhoneGlobals app) {
46 synchronized (ImsRcsController.class) {
47 if (sInstance == null) {
48 sInstance = new ImsRcsController(app);
49 } else {
50 Log.wtf(TAG, "init() called multiple times! sInstance = " + sInstance);
51 }
52 return sInstance;
53 }
54 }
55
56 /** Private constructor; @see init() */
57 private ImsRcsController(PhoneGlobals app) {
58 Log.i(TAG, "ImsRcsController");
59 mApp = app;
60 ServiceManager.addService(Context.TELEPHONY_IMS_SERVICE, this);
61 }
62
63 @Override
64 public void registerRcsAvailabilityCallback(IImsCapabilityCallback c) {
65 enforceReadPrivilegedPermission("registerRcsAvailabilityCallback");
66 }
67
68 @Override
69 public void unregisterRcsAvailabilityCallback(IImsCapabilityCallback c) {
70 enforceReadPrivilegedPermission("unregisterRcsAvailabilityCallback");
71 }
72
73 @Override
74 public boolean isCapable(int subId,
75 @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability) {
76 enforceReadPrivilegedPermission("isCapable");
77 return false;
78 }
79
80 @Override
81 public boolean isAvailable(int subId,
82 @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability) {
83 enforceReadPrivilegedPermission("isAvailable");
84 return false;
85 }
86
87 @Override
88 public void requestCapabilities(int subId, List<Uri> contactNumbers,
89 IRcsUceControllerCallback c) {
90 enforceReadPrivilegedPermission("requestCapabilities");
91 }
92
93 @Override
94 public int getUcePublishState(int subId) {
95 enforceReadPrivilegedPermission("getUcePublishState");
96 return -1;
97 }
98
99 @Override
100 public boolean isUceSettingEnabled(int subId) {
101 enforceReadPrivilegedPermission("isUceSettingEnabled");
102 return false;
103 }
104
105 @Override
106 public void setUceSettingEnabled(int subId, boolean isEnabled) {
107 enforceModifyPermission();
108 }
109
110 /**
111 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
112 *
113 * @throws SecurityException if the caller does not have the required permission
114 */
115 private void enforceReadPrivilegedPermission(String message) {
116 mApp.enforceCallingOrSelfPermission(
117 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
118 }
119
120 /**
121 * Make sure the caller has the MODIFY_PHONE_STATE permission.
122 *
123 * @throws SecurityException if the caller does not have the required permission
124 */
125 private void enforceModifyPermission() {
126 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
127 }
128}