Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | package com.android.car; |
| 17 | |
Roberto Perez | 9fed5f6 | 2021-07-10 00:48:15 +0000 | [diff] [blame] | 18 | import android.car.Car; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 19 | import android.car.CarAppFocusManager; |
| 20 | import android.car.IAppFocus; |
| 21 | import android.car.IAppFocusListener; |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 22 | import android.car.IAppFocusOwnershipCallback; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Roberto Perez | 9fed5f6 | 2021-07-10 00:48:15 +0000 | [diff] [blame] | 24 | import android.content.PermissionChecker; |
| 25 | import android.content.pm.PackageManager; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 26 | import android.os.Binder; |
| 27 | import android.os.Handler; |
| 28 | import android.os.HandlerThread; |
| 29 | import android.os.Looper; |
| 30 | import android.os.Message; |
| 31 | import android.os.RemoteException; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 32 | import android.util.ArraySet; |
Felipe Leme | 176a5fd | 2021-01-20 15:48:33 -0800 | [diff] [blame] | 33 | import android.util.IndentingPrintWriter; |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 34 | import android.util.Slog; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 35 | import android.util.SparseArray; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 36 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 37 | import com.android.internal.annotations.GuardedBy; |
tadvana | 3b9ed20 | 2019-07-17 19:21:28 -0700 | [diff] [blame] | 38 | import com.android.internal.annotations.VisibleForTesting; |
| 39 | |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 40 | import java.lang.ref.WeakReference; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 41 | import java.util.ArrayList; |
Roberto Perez | 9fed5f6 | 2021-07-10 00:48:15 +0000 | [diff] [blame] | 42 | import java.util.Arrays; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 43 | import java.util.Collections; |
| 44 | import java.util.List; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 45 | import java.util.Set; |
| 46 | |
| 47 | /** |
| 48 | * App focus service ensures only one instance of application type is active at a time. |
| 49 | */ |
| 50 | public class AppFocusService extends IAppFocus.Stub implements CarServiceBase, |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 51 | BinderInterfaceContainer.BinderEventHandler<IAppFocusOwnershipCallback> { |
Vitalii Tomkiv | 1b1247b | 2016-09-30 11:27:19 -0700 | [diff] [blame] | 52 | private static final boolean DBG = false; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 53 | private static final boolean DBG_EVENT = false; |
| 54 | |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 55 | private final SystemActivityMonitoringService mSystemActivityMonitoringService; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 56 | |
| 57 | private final Object mLock = new Object(); |
| 58 | |
Keun young Park | a7bdd59 | 2020-04-15 17:57:40 -0700 | [diff] [blame] | 59 | @VisibleForTesting |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 60 | @GuardedBy("mLock") |
Keun young Park | a7bdd59 | 2020-04-15 17:57:40 -0700 | [diff] [blame] | 61 | final ClientHolder mAllChangeClients; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 62 | |
Keun young Park | a7bdd59 | 2020-04-15 17:57:40 -0700 | [diff] [blame] | 63 | @VisibleForTesting |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 64 | @GuardedBy("mLock") |
Keun young Park | a7bdd59 | 2020-04-15 17:57:40 -0700 | [diff] [blame] | 65 | final OwnershipClientHolder mAllOwnershipClients; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 66 | |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 67 | /** K: appType, V: client owning it */ |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 68 | @GuardedBy("mLock") |
| 69 | private final SparseArray<OwnershipClientInfo> mFocusOwners = new SparseArray<>(); |
| 70 | |
| 71 | @GuardedBy("mLock") |
| 72 | private final Set<Integer> mActiveAppTypes = new ArraySet<>(); |
| 73 | |
| 74 | @GuardedBy("mLock") |
| 75 | private final List<FocusOwnershipCallback> mFocusOwnershipCallbacks = new ArrayList<>(); |
| 76 | |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 77 | private final BinderInterfaceContainer.BinderEventHandler<IAppFocusListener> |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 78 | mAllBinderEventHandler = bInterface -> { /* nothing to do.*/ }; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 79 | |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 80 | private final HandlerThread mHandlerThread = CarServiceUtils.getHandlerThread( |
| 81 | getClass().getSimpleName()); |
| 82 | private final DispatchHandler mDispatchHandler = new DispatchHandler(mHandlerThread.getLooper(), |
| 83 | this); |
Roberto Perez | 9fed5f6 | 2021-07-10 00:48:15 +0000 | [diff] [blame] | 84 | private final Context mContext; |
Pavel Maltsev | ddbff98 | 2017-03-22 14:49:02 -0700 | [diff] [blame] | 85 | |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 86 | public AppFocusService(Context context, |
| 87 | SystemActivityMonitoringService systemActivityMonitoringService) { |
Roberto Perez | 9fed5f6 | 2021-07-10 00:48:15 +0000 | [diff] [blame] | 88 | mContext = context; |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 89 | mSystemActivityMonitoringService = systemActivityMonitoringService; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 90 | mAllChangeClients = new ClientHolder(mAllBinderEventHandler); |
| 91 | mAllOwnershipClients = new OwnershipClientHolder(this); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public void registerFocusListener(IAppFocusListener listener, int appType) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 96 | synchronized (mLock) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 97 | ClientInfo info = (ClientInfo) mAllChangeClients.getBinderInterface(listener); |
| 98 | if (info == null) { |
| 99 | info = new ClientInfo(mAllChangeClients, listener, Binder.getCallingUid(), |
| 100 | Binder.getCallingPid(), appType); |
| 101 | mAllChangeClients.addBinderInterface(info); |
| 102 | } else { |
| 103 | info.addAppType(appType); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void unregisterFocusListener(IAppFocusListener listener, int appType) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 110 | synchronized (mLock) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 111 | ClientInfo info = (ClientInfo) mAllChangeClients.getBinderInterface(listener); |
| 112 | if (info == null) { |
| 113 | return; |
| 114 | } |
| 115 | info.removeAppType(appType); |
| 116 | if (info.getAppTypes().isEmpty()) { |
| 117 | mAllChangeClients.removeBinder(listener); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public int[] getActiveAppTypes() { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 124 | synchronized (mLock) { |
| 125 | return mActiveAppTypes.stream().mapToInt(Integer::intValue).toArray(); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | @Override |
Roberto Perez | 9fed5f6 | 2021-07-10 00:48:15 +0000 | [diff] [blame] | 130 | public List<String> getAppTypeOwner(@CarAppFocusManager.AppFocusType int appType) { |
| 131 | OwnershipClientInfo owner; |
| 132 | synchronized (mLock) { |
| 133 | owner = mFocusOwners.get(appType); |
| 134 | } |
| 135 | if (owner == null) { |
| 136 | return null; |
| 137 | } |
| 138 | String[] packageNames = mContext.getPackageManager().getPackagesForUid(owner.getUid()); |
| 139 | if (packageNames == null) { |
| 140 | return null; |
| 141 | } |
| 142 | return Arrays.asList(packageNames); |
| 143 | } |
| 144 | |
| 145 | @Override |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 146 | public boolean isOwningFocus(IAppFocusOwnershipCallback callback, int appType) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 147 | OwnershipClientInfo info; |
| 148 | synchronized (mLock) { |
| 149 | info = (OwnershipClientInfo) mAllOwnershipClients.getBinderInterface(callback); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 150 | } |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 151 | if (info == null) { |
| 152 | return false; |
| 153 | } |
| 154 | return info.getOwnedAppTypes().contains(appType); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 158 | public int requestAppFocus(IAppFocusOwnershipCallback callback, int appType) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 159 | synchronized (mLock) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 160 | OwnershipClientInfo info = |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 161 | (OwnershipClientInfo) mAllOwnershipClients.getBinderInterface(callback); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 162 | if (info == null) { |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 163 | info = new OwnershipClientInfo(mAllOwnershipClients, callback, |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 164 | Binder.getCallingUid(), Binder.getCallingPid()); |
| 165 | mAllOwnershipClients.addBinderInterface(info); |
| 166 | } |
| 167 | Set<Integer> alreadyOwnedAppTypes = info.getOwnedAppTypes(); |
| 168 | if (!alreadyOwnedAppTypes.contains(appType)) { |
| 169 | OwnershipClientInfo ownerInfo = mFocusOwners.get(appType); |
| 170 | if (ownerInfo != null && ownerInfo != info) { |
Roberto Perez | 9fed5f6 | 2021-07-10 00:48:15 +0000 | [diff] [blame] | 171 | // Allow receiving focus if the requester has a foreground activity OR if the |
| 172 | // requester is privileged service. |
| 173 | if (isInForeground(ownerInfo) && !isInForeground(info) |
| 174 | && !hasPrivilegedPermission()) { |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 175 | Slog.w(CarLog.TAG_APP_FOCUS, "Focus request failed for non-foreground app(" |
Antonio Kantek | 6af8e98 | 2020-04-10 19:11:51 -0700 | [diff] [blame] | 176 | + "pid=" + info.getPid() + ", uid=" + info.getUid() + ")." |
| 177 | + "Foreground app (pid=" + ownerInfo.getPid() + ", uid=" |
| 178 | + ownerInfo.getUid() + ") owns it."); |
Vitalii Tomkiv | 8c7f297 | 2016-07-11 15:42:04 -0700 | [diff] [blame] | 179 | return CarAppFocusManager.APP_FOCUS_REQUEST_FAILED; |
| 180 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 181 | ownerInfo.removeOwnedAppType(appType); |
| 182 | mDispatchHandler.requestAppFocusOwnershipLossDispatch( |
| 183 | ownerInfo.binderInterface, appType); |
| 184 | if (DBG) { |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 185 | Slog.i(CarLog.TAG_APP_FOCUS, "losing app type " |
Keun young Park | 5dcf327 | 2020-06-03 15:01:30 -0700 | [diff] [blame] | 186 | + appType + "," + ownerInfo); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
Yuncheol Heo | 2be288a | 2021-03-02 15:19:31 -0800 | [diff] [blame] | 189 | mFocusOwners.put(appType, info); |
| 190 | dispatchAcquireFocusOwnerLocked(appType, info, mFocusOwnershipCallbacks); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 191 | } |
| 192 | info.addOwnedAppType(appType); |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 193 | mDispatchHandler.requestAppFocusOwnershipGrantDispatch( |
| 194 | info.binderInterface, appType); |
Keun young Park | 5dcf327 | 2020-06-03 15:01:30 -0700 | [diff] [blame] | 195 | mActiveAppTypes.add(appType); |
| 196 | if (DBG) { |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 197 | Slog.i(CarLog.TAG_APP_FOCUS, "updating active app type " + appType + "," |
Keun young Park | 5dcf327 | 2020-06-03 15:01:30 -0700 | [diff] [blame] | 198 | + info); |
| 199 | } |
| 200 | // Always dispatch. |
| 201 | for (BinderInterfaceContainer.BinderInterface<IAppFocusListener> client : |
| 202 | mAllChangeClients.getInterfaces()) { |
| 203 | ClientInfo clientInfo = (ClientInfo) client; |
| 204 | // dispatch events only when there is change after filter and the listener |
| 205 | // is not coming from the current caller. |
| 206 | if (clientInfo.getAppTypes().contains(appType)) { |
| 207 | mDispatchHandler.requestAppFocusChangeDispatch(clientInfo.binderInterface, |
| 208 | appType, true); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | } |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 212 | return CarAppFocusManager.APP_FOCUS_REQUEST_SUCCEEDED; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Roberto Perez | 9fed5f6 | 2021-07-10 00:48:15 +0000 | [diff] [blame] | 215 | private boolean isInForeground(OwnershipClientInfo info) { |
| 216 | return mSystemActivityMonitoringService.isInForeground(info.getPid(), info.getUid()); |
| 217 | } |
| 218 | |
| 219 | private boolean hasPrivilegedPermission() { |
| 220 | return mContext.checkCallingOrSelfPermission(Car.PERMISSION_CAR_DISPLAY_IN_CLUSTER) |
| 221 | == PermissionChecker.PERMISSION_GRANTED; |
| 222 | } |
| 223 | |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 224 | @Override |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 225 | public void abandonAppFocus(IAppFocusOwnershipCallback callback, int appType) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 226 | synchronized (mLock) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 227 | OwnershipClientInfo info = |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 228 | (OwnershipClientInfo) mAllOwnershipClients.getBinderInterface(callback); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 229 | if (info == null) { |
| 230 | // ignore as this client cannot have owned anything. |
| 231 | return; |
| 232 | } |
| 233 | if (!mActiveAppTypes.contains(appType)) { |
| 234 | // ignore as none of them are active; |
| 235 | return; |
| 236 | } |
| 237 | Set<Integer> currentlyOwnedAppTypes = info.getOwnedAppTypes(); |
| 238 | if (!currentlyOwnedAppTypes.contains(appType)) { |
| 239 | // ignore as listener doesn't own focus. |
| 240 | return; |
| 241 | } |
Saeid Farivar Asanjan | e03f361 | 2021-04-20 18:27:53 -0700 | [diff] [blame] | 242 | // Because this code will run as part of unit tests on older platform, we can't use |
| 243 | // APIs such as {@link SparseArray#contains} that are added with API 30. |
| 244 | if (mFocusOwners.indexOfKey(appType) >= 0) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 245 | mFocusOwners.remove(appType); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 246 | mActiveAppTypes.remove(appType); |
| 247 | info.removeOwnedAppType(appType); |
| 248 | if (DBG) { |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 249 | Slog.i(CarLog.TAG_APP_FOCUS, "abandoning focus " + appType + "," + info); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 250 | } |
Yuncheol Heo | 2be288a | 2021-03-02 15:19:31 -0800 | [diff] [blame] | 251 | dispatchAbandonFocusOwnerLocked(appType, info, mFocusOwnershipCallbacks); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 252 | for (BinderInterfaceContainer.BinderInterface<IAppFocusListener> client : |
| 253 | mAllChangeClients.getInterfaces()) { |
| 254 | ClientInfo clientInfo = (ClientInfo) client; |
| 255 | if (clientInfo.getAppTypes().contains(appType)) { |
| 256 | mDispatchHandler.requestAppFocusChangeDispatch(clientInfo.binderInterface, |
| 257 | appType, false); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public void init() { |
Keun young Park | a7bdd59 | 2020-04-15 17:57:40 -0700 | [diff] [blame] | 266 | // nothing to do |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 267 | } |
| 268 | |
tadvana | 3b9ed20 | 2019-07-17 19:21:28 -0700 | [diff] [blame] | 269 | @VisibleForTesting |
| 270 | public Looper getLooper() { |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 271 | return mHandlerThread.getLooper(); |
| 272 | |
tadvana | 3b9ed20 | 2019-07-17 19:21:28 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 275 | @Override |
| 276 | public void release() { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 277 | synchronized (mLock) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 278 | mAllChangeClients.clear(); |
| 279 | mAllOwnershipClients.clear(); |
| 280 | mFocusOwners.clear(); |
| 281 | mActiveAppTypes.clear(); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public void onBinderDeath( |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 287 | BinderInterfaceContainer.BinderInterface<IAppFocusOwnershipCallback> bInterface) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 288 | OwnershipClientInfo info = (OwnershipClientInfo) bInterface; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 289 | synchronized (mLock) { |
| 290 | for (Integer appType : info.getOwnedAppTypes()) { |
| 291 | abandonAppFocus(bInterface.binderInterface, appType); |
| 292 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | @Override |
Felipe Leme | 176a5fd | 2021-01-20 15:48:33 -0800 | [diff] [blame] | 297 | public void dump(IndentingPrintWriter writer) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 298 | writer.println("**AppFocusService**"); |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 299 | synchronized (mLock) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 300 | writer.println("mActiveAppTypes:" + mActiveAppTypes); |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 301 | for (BinderInterfaceContainer.BinderInterface<IAppFocusOwnershipCallback> client : |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 302 | mAllOwnershipClients.getInterfaces()) { |
| 303 | OwnershipClientInfo clientInfo = (OwnershipClientInfo) client; |
Keun young Park | 5dcf327 | 2020-06-03 15:01:30 -0700 | [diff] [blame] | 304 | writer.println(clientInfo); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Returns true if process with given uid and pid owns provided focus. |
| 311 | */ |
| 312 | public boolean isFocusOwner(int uid, int pid, int appType) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 313 | synchronized (mLock) { |
Saeid Farivar Asanjan | e03f361 | 2021-04-20 18:27:53 -0700 | [diff] [blame] | 314 | // Because this code will run as part of unit tests on older platform, we can't use |
| 315 | // APIs such as {@link SparseArray#contains} that are added with API 30. |
| 316 | if (mFocusOwners.indexOfKey(appType) >= 0) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 317 | OwnershipClientInfo clientInfo = mFocusOwners.get(appType); |
| 318 | return clientInfo.getUid() == uid && clientInfo.getPid() == pid; |
| 319 | } |
| 320 | } |
| 321 | return false; |
| 322 | } |
| 323 | |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 324 | /** |
| 325 | * Defines callback functions that will be called when ownership has been changed. |
| 326 | */ |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 327 | public interface FocusOwnershipCallback { |
Pavel Maltsev | ffb3fb5 | 2016-06-29 12:48:50 -0700 | [diff] [blame] | 328 | void onFocusAcquired(int appType, int uid, int pid); |
| 329 | void onFocusAbandoned(int appType, int uid, int pid); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 333 | * Registers callback. |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 334 | * |
| 335 | * If any focus already acquired it will trigger |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 336 | * {@link FocusOwnershipCallback#onFocusAcquired} call immediately in the same thread. |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 337 | */ |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 338 | public void registerContextOwnerChangedCallback(FocusOwnershipCallback callback) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 339 | SparseArray<OwnershipClientInfo> owners; |
| 340 | synchronized (mLock) { |
| 341 | mFocusOwnershipCallbacks.add(callback); |
| 342 | owners = mFocusOwners.clone(); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 343 | } |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 344 | for (int idx = 0; idx < owners.size(); idx++) { |
| 345 | int key = owners.keyAt(idx); |
| 346 | OwnershipClientInfo clientInfo = owners.valueAt(idx); |
| 347 | callback.onFocusAcquired(key, clientInfo.getUid(), clientInfo.getPid()); |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
| 351 | /** |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 352 | * Unregisters provided callback. |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 353 | */ |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 354 | public void unregisterContextOwnerChangedCallback(FocusOwnershipCallback callback) { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 355 | synchronized (mLock) { |
| 356 | mFocusOwnershipCallbacks.remove(callback); |
| 357 | } |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Yuncheol Heo | 2be288a | 2021-03-02 15:19:31 -0800 | [diff] [blame] | 360 | private void dispatchAcquireFocusOwnerLocked(int appType, OwnershipClientInfo owner, |
| 361 | List<FocusOwnershipCallback> focusOwnershipCallbacks) { |
| 362 | // Dispatches each callback separately, not to make the copy of mFocusOwnershipCallbacks. |
| 363 | for (int i = focusOwnershipCallbacks.size() - 1; i >= 0; --i) { |
| 364 | FocusOwnershipCallback callback = focusOwnershipCallbacks.get(i); |
| 365 | mDispatchHandler.post( |
| 366 | () -> callback.onFocusAcquired(appType, owner.getUid(), owner.getPid())); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | private void dispatchAbandonFocusOwnerLocked(int appType, OwnershipClientInfo owner, |
| 371 | List<FocusOwnershipCallback> focusOwnershipCallbacks) { |
| 372 | // Dispatches each callback separately, not to make the copy of mFocusOwnershipCallbacks. |
| 373 | for (int i = focusOwnershipCallbacks.size() - 1; i >= 0; --i) { |
| 374 | FocusOwnershipCallback callback = focusOwnershipCallbacks.get(i); |
| 375 | mDispatchHandler.post( |
| 376 | () -> callback.onFocusAbandoned(appType, owner.getUid(), owner.getPid())); |
| 377 | } |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 380 | private void dispatchAppFocusOwnershipLoss(IAppFocusOwnershipCallback callback, int appType) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 381 | try { |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 382 | callback.onAppFocusOwnershipLost(appType); |
| 383 | } catch (RemoteException e) { |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | private void dispatchAppFocusOwnershipGrant(IAppFocusOwnershipCallback callback, int appType) { |
| 388 | try { |
| 389 | callback.onAppFocusOwnershipGranted(appType); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 390 | } catch (RemoteException e) { |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | private void dispatchAppFocusChange(IAppFocusListener listener, int appType, boolean active) { |
| 395 | try { |
Jason Tholstrup | d72b535 | 2016-09-22 16:32:14 -0700 | [diff] [blame] | 396 | listener.onAppFocusChanged(appType, active); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 397 | } catch (RemoteException e) { |
| 398 | } |
| 399 | } |
| 400 | |
Keun young Park | a7bdd59 | 2020-04-15 17:57:40 -0700 | [diff] [blame] | 401 | @VisibleForTesting |
| 402 | static class ClientHolder extends BinderInterfaceContainer<IAppFocusListener> { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 403 | private ClientHolder(BinderEventHandler<IAppFocusListener> holder) { |
| 404 | super(holder); |
| 405 | } |
| 406 | } |
| 407 | |
Keun young Park | a7bdd59 | 2020-04-15 17:57:40 -0700 | [diff] [blame] | 408 | @VisibleForTesting |
| 409 | static class OwnershipClientHolder extends |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 410 | BinderInterfaceContainer<IAppFocusOwnershipCallback> { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 411 | private OwnershipClientHolder(AppFocusService service) { |
| 412 | super(service); |
| 413 | } |
| 414 | } |
| 415 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 416 | private class ClientInfo extends |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 417 | BinderInterfaceContainer.BinderInterface<IAppFocusListener> { |
| 418 | private final int mUid; |
| 419 | private final int mPid; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 420 | |
| 421 | @GuardedBy("AppFocusService.mLock") |
| 422 | private final Set<Integer> mAppTypes = new ArraySet<>(); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 423 | |
| 424 | private ClientInfo(ClientHolder holder, IAppFocusListener binder, int uid, int pid, |
| 425 | int appType) { |
| 426 | super(holder, binder); |
| 427 | this.mUid = uid; |
| 428 | this.mPid = pid; |
| 429 | this.mAppTypes.add(appType); |
| 430 | } |
| 431 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 432 | private Set<Integer> getAppTypes() { |
| 433 | synchronized (mLock) { |
| 434 | return Collections.unmodifiableSet(mAppTypes); |
| 435 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 438 | private boolean addAppType(Integer appType) { |
| 439 | synchronized (mLock) { |
| 440 | return mAppTypes.add(appType); |
| 441 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 444 | private boolean removeAppType(Integer appType) { |
| 445 | synchronized (mLock) { |
| 446 | return mAppTypes.remove(appType); |
| 447 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 450 | @Override |
| 451 | public String toString() { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 452 | synchronized (mLock) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 453 | return "ClientInfo{mUid=" + mUid + ",mPid=" + mPid |
| 454 | + ",appTypes=" + mAppTypes + "}"; |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 459 | private class OwnershipClientInfo extends |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 460 | BinderInterfaceContainer.BinderInterface<IAppFocusOwnershipCallback> { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 461 | private final int mUid; |
| 462 | private final int mPid; |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 463 | |
| 464 | @GuardedBy("AppFocusService.mLock") |
| 465 | private final Set<Integer> mOwnedAppTypes = new ArraySet<>(); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 466 | |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 467 | private OwnershipClientInfo(OwnershipClientHolder holder, IAppFocusOwnershipCallback binder, |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 468 | int uid, int pid) { |
| 469 | super(holder, binder); |
| 470 | this.mUid = uid; |
| 471 | this.mPid = pid; |
| 472 | } |
| 473 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 474 | private Set<Integer> getOwnedAppTypes() { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 475 | if (DBG_EVENT) { |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 476 | Slog.i(CarLog.TAG_APP_FOCUS, "getOwnedAppTypes " + mOwnedAppTypes); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 477 | } |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 478 | synchronized (mLock) { |
| 479 | return Collections.unmodifiableSet(mOwnedAppTypes); |
| 480 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 483 | private boolean addOwnedAppType(Integer appType) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 484 | if (DBG_EVENT) { |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 485 | Slog.i(CarLog.TAG_APP_FOCUS, "addOwnedAppType " + appType); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 486 | } |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 487 | synchronized (mLock) { |
| 488 | return mOwnedAppTypes.add(appType); |
| 489 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 492 | private boolean removeOwnedAppType(Integer appType) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 493 | if (DBG_EVENT) { |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 494 | Slog.i(CarLog.TAG_APP_FOCUS, "removeOwnedAppType " + appType); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 495 | } |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 496 | synchronized (mLock) { |
| 497 | return mOwnedAppTypes.remove(appType); |
| 498 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 501 | int getUid() { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 502 | return mUid; |
| 503 | } |
| 504 | |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 505 | int getPid() { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 506 | return mPid; |
| 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public String toString() { |
Antonio Kantek | 9f68954 | 2019-12-05 15:44:59 -0800 | [diff] [blame] | 511 | synchronized (mLock) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 512 | return "ClientInfo{mUid=" + mUid + ",mPid=" + mPid |
| 513 | + ",owned=" + mOwnedAppTypes + "}"; |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 518 | private static final class DispatchHandler extends Handler { |
Mayank Garg | 72c71d2 | 2021-02-03 23:54:45 -0800 | [diff] [blame] | 519 | private static final String TAG = CarLog.tagFor(AppFocusService.class); |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 520 | |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 521 | private static final int MSG_DISPATCH_OWNERSHIP_LOSS = 0; |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 522 | private static final int MSG_DISPATCH_OWNERSHIP_GRANT = 1; |
| 523 | private static final int MSG_DISPATCH_FOCUS_CHANGE = 2; |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 524 | |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 525 | private final WeakReference<AppFocusService> mService; |
| 526 | |
| 527 | private DispatchHandler(Looper looper, AppFocusService service) { |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 528 | super(looper); |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 529 | mService = new WeakReference<AppFocusService>(service); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 532 | private void requestAppFocusOwnershipLossDispatch(IAppFocusOwnershipCallback callback, |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 533 | int appType) { |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 534 | Message msg = obtainMessage(MSG_DISPATCH_OWNERSHIP_LOSS, appType, 0, callback); |
| 535 | sendMessage(msg); |
| 536 | } |
| 537 | |
| 538 | private void requestAppFocusOwnershipGrantDispatch(IAppFocusOwnershipCallback callback, |
| 539 | int appType) { |
| 540 | Message msg = obtainMessage(MSG_DISPATCH_OWNERSHIP_GRANT, appType, 0, callback); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 541 | sendMessage(msg); |
| 542 | } |
| 543 | |
| 544 | private void requestAppFocusChangeDispatch(IAppFocusListener listener, int appType, |
| 545 | boolean active) { |
| 546 | Message msg = obtainMessage(MSG_DISPATCH_FOCUS_CHANGE, appType, active ? 1 : 0, |
| 547 | listener); |
| 548 | sendMessage(msg); |
| 549 | } |
| 550 | |
| 551 | @Override |
| 552 | public void handleMessage(Message msg) { |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 553 | AppFocusService service = mService.get(); |
| 554 | if (service == null) { |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 555 | Slog.i(TAG, "handleMessage null service"); |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 556 | return; |
| 557 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 558 | switch (msg.what) { |
| 559 | case MSG_DISPATCH_OWNERSHIP_LOSS: |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 560 | service.dispatchAppFocusOwnershipLoss((IAppFocusOwnershipCallback) msg.obj, |
| 561 | msg.arg1); |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 562 | break; |
| 563 | case MSG_DISPATCH_OWNERSHIP_GRANT: |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 564 | service.dispatchAppFocusOwnershipGrant((IAppFocusOwnershipCallback) msg.obj, |
| 565 | msg.arg1); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 566 | break; |
| 567 | case MSG_DISPATCH_FOCUS_CHANGE: |
Keun young Park | b241d02 | 2020-04-20 20:31:34 -0700 | [diff] [blame] | 568 | service.dispatchAppFocusChange((IAppFocusListener) msg.obj, msg.arg1, |
| 569 | msg.arg2 == 1); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 570 | break; |
Vitalii Tomkiv | d15d887 | 2016-10-04 14:08:56 -0700 | [diff] [blame] | 571 | default: |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 572 | Slog.e(CarLog.TAG_APP_FOCUS, "Can't dispatch message: " + msg); |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | } |
Vitalii Tomkiv | 4637147 | 2016-05-23 16:55:22 -0700 | [diff] [blame] | 576 | } |