Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.tv; |
| 18 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 19 | import static android.media.tv.TvInputManager.INPUT_STATE_CONNECTED; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 20 | import static android.media.tv.TvInputManager.INPUT_STATE_CONNECTED_STANDBY; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 21 | |
Jae Seo | 4eee6a7 | 2016-02-06 11:11:35 +0900 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 23 | import android.app.ActivityManager; |
| 24 | import android.content.BroadcastReceiver; |
| 25 | import android.content.ComponentName; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 26 | import android.content.ContentResolver; |
| 27 | import android.content.ContentUris; |
| 28 | import android.content.ContentValues; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.content.IntentFilter; |
| 32 | import android.content.ServiceConnection; |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 33 | import android.content.pm.ActivityInfo; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageManager; |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager.NameNotFoundException; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 36 | import android.content.pm.ResolveInfo; |
| 37 | import android.content.pm.ServiceInfo; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 38 | import android.graphics.Rect; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 39 | import android.hardware.hdmi.HdmiControlManager; |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 40 | import android.hardware.hdmi.HdmiDeviceInfo; |
Jae Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 41 | import android.media.PlaybackParams; |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 42 | import android.media.tv.DvbDeviceInfo; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 43 | import android.media.tv.ITvInputClient; |
| 44 | import android.media.tv.ITvInputHardware; |
| 45 | import android.media.tv.ITvInputHardwareCallback; |
| 46 | import android.media.tv.ITvInputManager; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 47 | import android.media.tv.ITvInputManagerCallback; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 48 | import android.media.tv.ITvInputService; |
| 49 | import android.media.tv.ITvInputServiceCallback; |
| 50 | import android.media.tv.ITvInputSession; |
| 51 | import android.media.tv.ITvInputSessionCallback; |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 52 | import android.media.tv.TvContentRating; |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 53 | import android.media.tv.TvContentRatingSystemInfo; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 54 | import android.media.tv.TvContract; |
| 55 | import android.media.tv.TvInputHardwareInfo; |
| 56 | import android.media.tv.TvInputInfo; |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 57 | import android.media.tv.TvInputManager; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 58 | import android.media.tv.TvInputService; |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 59 | import android.media.tv.TvStreamConfig; |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 60 | import android.media.tv.TvTrackInfo; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 61 | import android.net.Uri; |
| 62 | import android.os.Binder; |
Youngsang Cho | 832860f | 2014-05-21 20:54:03 +0900 | [diff] [blame] | 63 | import android.os.Bundle; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 64 | import android.os.Handler; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 65 | import android.os.IBinder; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 66 | import android.os.Looper; |
| 67 | import android.os.Message; |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 68 | import android.os.ParcelFileDescriptor; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 69 | import android.os.Process; |
| 70 | import android.os.RemoteException; |
| 71 | import android.os.UserHandle; |
Jae Seo | c2a8951 | 2016-01-28 10:38:11 -0800 | [diff] [blame] | 72 | import android.text.TextUtils; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 73 | import android.util.Slog; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 74 | import android.util.SparseArray; |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 75 | import android.view.InputChannel; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 76 | import android.view.Surface; |
| 77 | |
| 78 | import com.android.internal.content.PackageMonitor; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 79 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 80 | import com.android.internal.util.DumpUtils; |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 81 | import com.android.internal.util.IndentingPrintWriter; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 82 | import com.android.server.IoThread; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 83 | import com.android.server.SystemService; |
| 84 | |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 85 | import java.io.File; |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 86 | import java.io.FileDescriptor; |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 87 | import java.io.FileNotFoundException; |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 88 | import java.io.PrintWriter; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 89 | import java.util.ArrayList; |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 90 | import java.util.Arrays; |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 91 | import java.util.Collections; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 92 | import java.util.HashMap; |
Jae Seo | 5c80ad2 | 2014-06-12 19:52:58 -0700 | [diff] [blame] | 93 | import java.util.HashSet; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 94 | import java.util.Iterator; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 95 | import java.util.List; |
| 96 | import java.util.Map; |
Jae Seo | 5c80ad2 | 2014-06-12 19:52:58 -0700 | [diff] [blame] | 97 | import java.util.Set; |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 98 | import java.util.regex.Matcher; |
| 99 | import java.util.regex.Pattern; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 100 | |
| 101 | /** This class provides a system service that manages television inputs. */ |
| 102 | public final class TvInputManagerService extends SystemService { |
Jae Seo | ee2ec05 | 2014-09-14 10:30:05 -0700 | [diff] [blame] | 103 | private static final boolean DEBUG = false; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 104 | private static final String TAG = "TvInputManagerService"; |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 105 | private static final String DVB_DIRECTORY = "/dev/dvb"; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 106 | |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 107 | // There are two different formats of DVB frontend devices. One is /dev/dvb%d.frontend%d, |
| 108 | // another one is /dev/dvb/adapter%d/frontend%d. Followings are the patterns for selecting the |
| 109 | // DVB frontend devices from the list of files in the /dev and /dev/dvb/adapter%d directory. |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 110 | private static final Pattern sFrontEndDevicePattern = |
| 111 | Pattern.compile("^dvb([0-9]+)\\.frontend([0-9]+)$"); |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 112 | private static final Pattern sAdapterDirPattern = |
| 113 | Pattern.compile("^adapter([0-9]+)$"); |
| 114 | private static final Pattern sFrontEndInAdapterDirPattern = |
| 115 | Pattern.compile("^frontend([0-9]+)$"); |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 116 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 117 | private final Context mContext; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 118 | private final TvInputHardwareManager mTvInputHardwareManager; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 119 | |
| 120 | // A global lock. |
| 121 | private final Object mLock = new Object(); |
| 122 | |
| 123 | // ID of the current user. |
Xiaohui Chen | 233d94c | 2015-07-30 15:08:00 -0700 | [diff] [blame] | 124 | private int mCurrentUserId = UserHandle.USER_SYSTEM; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 125 | |
| 126 | // A map from user id to UserState. |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 127 | private final SparseArray<UserState> mUserStates = new SparseArray<>(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 128 | |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 129 | private final WatchLogHandler mWatchLogHandler; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 130 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 131 | public TvInputManagerService(Context context) { |
| 132 | super(context); |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 133 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 134 | mContext = context; |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 135 | mWatchLogHandler = new WatchLogHandler(mContext.getContentResolver(), |
| 136 | IoThread.get().getLooper()); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 137 | mTvInputHardwareManager = new TvInputHardwareManager(context, new HardwareListener()); |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 138 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 139 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 140 | getOrCreateUserStateLocked(mCurrentUserId); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public void onStart() { |
| 146 | publishBinderService(Context.TV_INPUT_SERVICE, new BinderService()); |
| 147 | } |
| 148 | |
Ji-Hwan Lee | 0ceb7e4 | 2014-06-21 04:42:05 +0900 | [diff] [blame] | 149 | @Override |
| 150 | public void onBootPhase(int phase) { |
| 151 | if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { |
| 152 | registerBroadcastReceivers(); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 153 | } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { |
Ji-Hwan Lee | 0ceb7e4 | 2014-06-21 04:42:05 +0900 | [diff] [blame] | 154 | synchronized (mLock) { |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 155 | buildTvInputListLocked(mCurrentUserId, null); |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 156 | buildTvContentRatingSystemListLocked(mCurrentUserId); |
Ji-Hwan Lee | 0ceb7e4 | 2014-06-21 04:42:05 +0900 | [diff] [blame] | 157 | } |
| 158 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 159 | mTvInputHardwareManager.onBootPhase(phase); |
Ji-Hwan Lee | 0ceb7e4 | 2014-06-21 04:42:05 +0900 | [diff] [blame] | 160 | } |
| 161 | |
Youngsang Cho | 19c47d7 | 2016-05-05 09:21:24 -0700 | [diff] [blame] | 162 | @Override |
| 163 | public void onUnlockUser(int userHandle) { |
| 164 | if (DEBUG) Slog.d(TAG, "onUnlockUser(userHandle=" + userHandle + ")"); |
| 165 | synchronized (mLock) { |
| 166 | if (mCurrentUserId != userHandle) { |
| 167 | return; |
| 168 | } |
| 169 | buildTvInputListLocked(mCurrentUserId, null); |
| 170 | buildTvContentRatingSystemListLocked(mCurrentUserId); |
| 171 | } |
| 172 | } |
| 173 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 174 | private void registerBroadcastReceivers() { |
| 175 | PackageMonitor monitor = new PackageMonitor() { |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 176 | private void buildTvInputList(String[] packages) { |
| 177 | synchronized (mLock) { |
Dongwon Kang | a897e5f | 2016-04-19 13:39:47 -0700 | [diff] [blame] | 178 | if (mCurrentUserId == getChangingUserId()) { |
| 179 | buildTvInputListLocked(mCurrentUserId, packages); |
| 180 | buildTvContentRatingSystemListLocked(mCurrentUserId); |
| 181 | } |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public void onPackageUpdateFinished(String packageName, int uid) { |
| 187 | if (DEBUG) Slog.d(TAG, "onPackageUpdateFinished(packageName=" + packageName + ")"); |
| 188 | // This callback is invoked when the TV input is reinstalled. |
| 189 | // In this case, isReplacing() always returns true. |
| 190 | buildTvInputList(new String[] { packageName }); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public void onPackagesAvailable(String[] packages) { |
| 195 | if (DEBUG) { |
| 196 | Slog.d(TAG, "onPackagesAvailable(packages=" + Arrays.toString(packages) + ")"); |
| 197 | } |
| 198 | // This callback is invoked when the media on which some packages exist become |
| 199 | // available. |
| 200 | if (isReplacing()) { |
| 201 | buildTvInputList(packages); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void onPackagesUnavailable(String[] packages) { |
| 207 | // This callback is invoked when the media on which some packages exist become |
| 208 | // unavailable. |
| 209 | if (DEBUG) { |
| 210 | Slog.d(TAG, "onPackagesUnavailable(packages=" + Arrays.toString(packages) |
| 211 | + ")"); |
| 212 | } |
| 213 | if (isReplacing()) { |
| 214 | buildTvInputList(packages); |
| 215 | } |
| 216 | } |
| 217 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 218 | @Override |
| 219 | public void onSomePackagesChanged() { |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 220 | // TODO: Use finer-grained methods(e.g. onPackageAdded, onPackageRemoved) to manage |
| 221 | // the TV inputs. |
Dongwon Kang | 426c9a4 | 2014-08-26 17:39:21 +0900 | [diff] [blame] | 222 | if (DEBUG) Slog.d(TAG, "onSomePackagesChanged()"); |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 223 | if (isReplacing()) { |
| 224 | if (DEBUG) Slog.d(TAG, "Skipped building TV input list due to replacing"); |
| 225 | // When the package is updated, buildTvInputListLocked is called in other |
| 226 | // methods instead. |
| 227 | return; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 228 | } |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 229 | buildTvInputList(null); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 230 | } |
Jae Seo | 5c80ad2 | 2014-06-12 19:52:58 -0700 | [diff] [blame] | 231 | |
| 232 | @Override |
Dongwon Kang | 31a8f84 | 2015-04-08 18:26:23 -0700 | [diff] [blame] | 233 | public boolean onPackageChanged(String packageName, int uid, String[] components) { |
| 234 | // The input list needs to be updated in any cases, regardless of whether |
| 235 | // it happened to the whole package or a specific component. Returning true so that |
| 236 | // the update can be handled in {@link #onSomePackagesChanged}. |
| 237 | return true; |
| 238 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 239 | }; |
| 240 | monitor.register(mContext, null, UserHandle.ALL, true); |
| 241 | |
| 242 | IntentFilter intentFilter = new IntentFilter(); |
| 243 | intentFilter.addAction(Intent.ACTION_USER_SWITCHED); |
| 244 | intentFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 245 | mContext.registerReceiverAsUser(new BroadcastReceiver() { |
| 246 | @Override |
| 247 | public void onReceive(Context context, Intent intent) { |
| 248 | String action = intent.getAction(); |
| 249 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 250 | switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0)); |
| 251 | } else if (Intent.ACTION_USER_REMOVED.equals(action)) { |
| 252 | removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0)); |
| 253 | } |
| 254 | } |
| 255 | }, UserHandle.ALL, intentFilter, null, null); |
| 256 | } |
| 257 | |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 258 | private static boolean hasHardwarePermission(PackageManager pm, ComponentName component) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 259 | return pm.checkPermission(android.Manifest.permission.TV_INPUT_HARDWARE, |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 260 | component.getPackageName()) == PackageManager.PERMISSION_GRANTED; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 261 | } |
| 262 | |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 263 | private void buildTvInputListLocked(int userId, String[] updatedPackages) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 264 | UserState userState = getOrCreateUserStateLocked(userId); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 265 | userState.packageSet.clear(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 266 | |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 267 | if (DEBUG) Slog.d(TAG, "buildTvInputList"); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 268 | PackageManager pm = mContext.getPackageManager(); |
Jae Seo | 76976fa | 2015-05-20 21:51:16 -0700 | [diff] [blame] | 269 | List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
Chulwoo Lee | e7bb7d6 | 2014-05-27 14:10:37 +0900 | [diff] [blame] | 270 | new Intent(TvInputService.SERVICE_INTERFACE), |
Jae Seo | 76976fa | 2015-05-20 21:51:16 -0700 | [diff] [blame] | 271 | PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, |
| 272 | userId); |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 273 | List<TvInputInfo> inputList = new ArrayList<>(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 274 | for (ResolveInfo ri : services) { |
| 275 | ServiceInfo si = ri.serviceInfo; |
| 276 | if (!android.Manifest.permission.BIND_TV_INPUT.equals(si.permission)) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 277 | Slog.w(TAG, "Skipping TV input " + si.name + ": it does not require the permission " |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 278 | + android.Manifest.permission.BIND_TV_INPUT); |
| 279 | continue; |
| 280 | } |
Jae Seo | 9cc28e5 | 2014-08-12 16:45:58 -0700 | [diff] [blame] | 281 | |
| 282 | ComponentName component = new ComponentName(si.packageName, si.name); |
| 283 | if (hasHardwarePermission(pm, component)) { |
| 284 | ServiceState serviceState = userState.serviceStateMap.get(component); |
| 285 | if (serviceState == null) { |
Jae Seo | c980f43d | 2016-02-09 23:46:58 -0800 | [diff] [blame] | 286 | // New hardware input found. Create a new ServiceState and connect to the |
| 287 | // service to populate the hardware list. |
Jae Seo | 9cc28e5 | 2014-08-12 16:45:58 -0700 | [diff] [blame] | 288 | serviceState = new ServiceState(component, userId); |
| 289 | userState.serviceStateMap.put(component, serviceState); |
Wonsik Kim | f271eac | 2014-08-30 12:55:10 +0900 | [diff] [blame] | 290 | updateServiceConnectionLocked(component, userId); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 291 | } else { |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 292 | inputList.addAll(serviceState.hardwareInputMap.values()); |
Jae Seo | 9cc28e5 | 2014-08-12 16:45:58 -0700 | [diff] [blame] | 293 | } |
| 294 | } else { |
| 295 | try { |
Jae Seo | c03671f | 2016-01-26 15:15:22 -0800 | [diff] [blame] | 296 | TvInputInfo info = new TvInputInfo.Builder(mContext, ri).build(); |
| 297 | inputList.add(info); |
Jae Seo | 18c0cfb | 2016-05-16 18:19:11 -0700 | [diff] [blame] | 298 | } catch (Exception e) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 299 | Slog.e(TAG, "failed to load TV input " + si.name, e); |
Jae Seo | 9cc28e5 | 2014-08-12 16:45:58 -0700 | [diff] [blame] | 300 | continue; |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 301 | } |
Chulwoo Lee | e7bb7d6 | 2014-05-27 14:10:37 +0900 | [diff] [blame] | 302 | } |
Jae Seo | 9cc28e5 | 2014-08-12 16:45:58 -0700 | [diff] [blame] | 303 | userState.packageSet.add(si.packageName); |
| 304 | } |
| 305 | |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 306 | Map<String, TvInputState> inputMap = new HashMap<>(); |
Jae Seo | 9cc28e5 | 2014-08-12 16:45:58 -0700 | [diff] [blame] | 307 | for (TvInputInfo info : inputList) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 308 | if (DEBUG) { |
| 309 | Slog.d(TAG, "add " + info.getId()); |
| 310 | } |
Jae Seo | abda420 | 2016-01-28 19:13:04 -0800 | [diff] [blame] | 311 | TvInputState inputState = userState.inputMap.get(info.getId()); |
| 312 | if (inputState == null) { |
| 313 | inputState = new TvInputState(); |
Jae Seo | 9cc28e5 | 2014-08-12 16:45:58 -0700 | [diff] [blame] | 314 | } |
Shubang | 2263fb0 | 2016-05-13 16:51:53 -0700 | [diff] [blame] | 315 | inputState.info = info; |
Jae Seo | abda420 | 2016-01-28 19:13:04 -0800 | [diff] [blame] | 316 | inputMap.put(info.getId(), inputState); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 317 | } |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 318 | |
| 319 | for (String inputId : inputMap.keySet()) { |
| 320 | if (!userState.inputMap.containsKey(inputId)) { |
| 321 | notifyInputAddedLocked(userState, inputId); |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 322 | } else if (updatedPackages != null) { |
| 323 | // Notify the package updates |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 324 | ComponentName component = inputMap.get(inputId).info.getComponent(); |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 325 | for (String updatedPackage : updatedPackages) { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 326 | if (component.getPackageName().equals(updatedPackage)) { |
| 327 | updateServiceConnectionLocked(component, userId); |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 328 | notifyInputUpdatedLocked(userState, inputId); |
| 329 | break; |
| 330 | } |
| 331 | } |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
| 335 | for (String inputId : userState.inputMap.keySet()) { |
| 336 | if (!inputMap.containsKey(inputId)) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 337 | TvInputInfo info = userState.inputMap.get(inputId).info; |
Dongwon Kang | 426c9a4 | 2014-08-26 17:39:21 +0900 | [diff] [blame] | 338 | ServiceState serviceState = userState.serviceStateMap.get(info.getComponent()); |
| 339 | if (serviceState != null) { |
| 340 | abortPendingCreateSessionRequestsLocked(serviceState, inputId, userId); |
| 341 | } |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 342 | notifyInputRemovedLocked(userState, inputId); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | userState.inputMap.clear(); |
| 347 | userState.inputMap = inputMap; |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 348 | } |
Sungsoo Lim | 5c5b83f | 2014-07-29 11:48:36 +0900 | [diff] [blame] | 349 | |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 350 | private void buildTvContentRatingSystemListLocked(int userId) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 351 | UserState userState = getOrCreateUserStateLocked(userId); |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 352 | userState.contentRatingSystemList.clear(); |
| 353 | |
| 354 | final PackageManager pm = mContext.getPackageManager(); |
| 355 | Intent intent = new Intent(TvInputManager.ACTION_QUERY_CONTENT_RATING_SYSTEMS); |
| 356 | for (ResolveInfo resolveInfo : |
| 357 | pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA)) { |
| 358 | ActivityInfo receiver = resolveInfo.activityInfo; |
| 359 | Bundle metaData = receiver.metaData; |
| 360 | if (metaData == null) { |
| 361 | continue; |
Sungsoo Lim | 5c5b83f | 2014-07-29 11:48:36 +0900 | [diff] [blame] | 362 | } |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 363 | |
| 364 | int xmlResId = metaData.getInt(TvInputManager.META_DATA_CONTENT_RATING_SYSTEMS); |
| 365 | if (xmlResId == 0) { |
| 366 | Slog.w(TAG, "Missing meta-data '" |
| 367 | + TvInputManager.META_DATA_CONTENT_RATING_SYSTEMS + "' on receiver " |
| 368 | + receiver.packageName + "/" + receiver.name); |
| 369 | continue; |
| 370 | } |
| 371 | userState.contentRatingSystemList.add( |
| 372 | TvContentRatingSystemInfo.createTvContentRatingSystemInfo(xmlResId, |
| 373 | receiver.applicationInfo)); |
Sungsoo Lim | 5c5b83f | 2014-07-29 11:48:36 +0900 | [diff] [blame] | 374 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | private void switchUser(int userId) { |
| 378 | synchronized (mLock) { |
| 379 | if (mCurrentUserId == userId) { |
| 380 | return; |
| 381 | } |
shubang | 8049f20 | 2016-04-25 11:21:42 -0700 | [diff] [blame] | 382 | UserState userState = mUserStates.get(mCurrentUserId); |
| 383 | List<SessionState> sessionStatesToRelease = new ArrayList<>(); |
| 384 | for (SessionState sessionState : userState.sessionStateMap.values()) { |
| 385 | if (sessionState.session != null && !sessionState.isRecordingSession) { |
| 386 | sessionStatesToRelease.add(sessionState); |
| 387 | } |
| 388 | } |
| 389 | for (SessionState sessionState : sessionStatesToRelease) { |
| 390 | try { |
| 391 | sessionState.session.release(); |
| 392 | } catch (RemoteException e) { |
| 393 | Slog.e(TAG, "error in release", e); |
| 394 | } |
| 395 | clearSessionAndNotifyClientLocked(sessionState); |
| 396 | } |
| 397 | |
| 398 | for (Iterator<ComponentName> it = userState.serviceStateMap.keySet().iterator(); |
| 399 | it.hasNext(); ) { |
| 400 | ComponentName component = it.next(); |
| 401 | ServiceState serviceState = userState.serviceStateMap.get(component); |
| 402 | if (serviceState != null && serviceState.sessionTokens.isEmpty()) { |
| 403 | if (serviceState.callback != null) { |
| 404 | try { |
| 405 | serviceState.service.unregisterCallback(serviceState.callback); |
| 406 | } catch (RemoteException e) { |
| 407 | Slog.e(TAG, "error in unregisterCallback", e); |
| 408 | } |
| 409 | } |
| 410 | mContext.unbindService(serviceState.connection); |
| 411 | it.remove(); |
| 412 | } |
| 413 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 414 | |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 415 | mCurrentUserId = userId; |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 416 | getOrCreateUserStateLocked(userId); |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 417 | buildTvInputListLocked(userId, null); |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 418 | buildTvContentRatingSystemListLocked(userId); |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 419 | mWatchLogHandler.obtainMessage(WatchLogHandler.MSG_SWITCH_CONTENT_RESOLVER, |
| 420 | getContentResolverForUser(userId)).sendToTarget(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
shubang | 8049f20 | 2016-04-25 11:21:42 -0700 | [diff] [blame] | 424 | private void clearSessionAndNotifyClientLocked(SessionState state) { |
| 425 | if (state.client != null) { |
| 426 | try { |
| 427 | state.client.onSessionReleased(state.seq); |
| 428 | } catch(RemoteException e) { |
| 429 | Slog.e(TAG, "error in onSessionReleased", e); |
| 430 | } |
| 431 | } |
| 432 | // If there are any other sessions based on this session, they should be released. |
| 433 | UserState userState = getOrCreateUserStateLocked(state.userId); |
| 434 | for (SessionState sessionState : userState.sessionStateMap.values()) { |
| 435 | if (state.sessionToken == sessionState.hardwareSessionToken) { |
| 436 | releaseSessionLocked(sessionState.sessionToken, Process.SYSTEM_UID, state.userId); |
| 437 | try { |
| 438 | sessionState.client.onSessionReleased(sessionState.seq); |
| 439 | } catch (RemoteException e) { |
| 440 | Slog.e(TAG, "error in onSessionReleased", e); |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | removeSessionStateLocked(state.sessionToken, state.userId); |
| 445 | } |
| 446 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 447 | private void removeUser(int userId) { |
| 448 | synchronized (mLock) { |
Jae Seo | b06cb88 | 2014-04-09 12:08:17 -0700 | [diff] [blame] | 449 | UserState userState = mUserStates.get(userId); |
| 450 | if (userState == null) { |
| 451 | return; |
| 452 | } |
shubang | 8049f20 | 2016-04-25 11:21:42 -0700 | [diff] [blame] | 453 | // Release all created sessions. |
| 454 | for (SessionState state : userState.sessionStateMap.values()) { |
| 455 | if (state.session != null) { |
| 456 | try { |
| 457 | state.session.release(); |
| 458 | } catch (RemoteException e) { |
| 459 | Slog.e(TAG, "error in release", e); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | userState.sessionStateMap.clear(); |
| 464 | |
| 465 | // Unregister all callbacks and unbind all services. |
| 466 | for (ServiceState serviceState : userState.serviceStateMap.values()) { |
| 467 | if (serviceState.service != null) { |
| 468 | if (serviceState.callback != null) { |
| 469 | try { |
| 470 | serviceState.service.unregisterCallback(serviceState.callback); |
| 471 | } catch (RemoteException e) { |
| 472 | Slog.e(TAG, "error in unregisterCallback", e); |
| 473 | } |
| 474 | } |
| 475 | mContext.unbindService(serviceState.connection); |
| 476 | } |
| 477 | } |
| 478 | userState.serviceStateMap.clear(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 479 | |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 480 | // Clear everything else. |
| 481 | userState.inputMap.clear(); |
| 482 | userState.packageSet.clear(); |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 483 | userState.contentRatingSystemList.clear(); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 484 | userState.clientStateMap.clear(); |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 485 | userState.callbackSet.clear(); |
| 486 | userState.mainSessionToken = null; |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 487 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 488 | mUserStates.remove(userId); |
| 489 | } |
| 490 | } |
| 491 | |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 492 | private ContentResolver getContentResolverForUser(int userId) { |
| 493 | UserHandle user = new UserHandle(userId); |
| 494 | Context context; |
| 495 | try { |
| 496 | context = mContext.createPackageContextAsUser("android", 0, user); |
| 497 | } catch (NameNotFoundException e) { |
Jae Seo | 2a2b299 | 2016-01-12 23:13:14 -0800 | [diff] [blame] | 498 | Slog.e(TAG, "failed to create package context as user " + user); |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 499 | context = mContext; |
| 500 | } |
| 501 | return context.getContentResolver(); |
| 502 | } |
| 503 | |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 504 | private UserState getOrCreateUserStateLocked(int userId) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 505 | UserState userState = mUserStates.get(userId); |
| 506 | if (userState == null) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 507 | userState = new UserState(mContext, userId); |
| 508 | mUserStates.put(userId, userState); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 509 | } |
| 510 | return userState; |
| 511 | } |
| 512 | |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 513 | private ServiceState getServiceStateLocked(ComponentName component, int userId) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 514 | UserState userState = getOrCreateUserStateLocked(userId); |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 515 | ServiceState serviceState = userState.serviceStateMap.get(component); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 516 | if (serviceState == null) { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 517 | throw new IllegalStateException("Service state not found for " + component + " (userId=" |
Sungsoo Lim | 7de5e23 | 2014-04-12 16:51:27 +0900 | [diff] [blame] | 518 | + userId + ")"); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 519 | } |
| 520 | return serviceState; |
| 521 | } |
| 522 | |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 523 | private SessionState getSessionStateLocked(IBinder sessionToken, int callingUid, int userId) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 524 | UserState userState = getOrCreateUserStateLocked(userId); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 525 | SessionState sessionState = userState.sessionStateMap.get(sessionToken); |
| 526 | if (sessionState == null) { |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 527 | throw new SessionNotFoundException("Session state not found for token " + sessionToken); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 528 | } |
| 529 | // Only the application that requested this session or the system can access it. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 530 | if (callingUid != Process.SYSTEM_UID && callingUid != sessionState.callingUid) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 531 | throw new SecurityException("Illegal access to the session with token " + sessionToken |
| 532 | + " from uid " + callingUid); |
| 533 | } |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 534 | return sessionState; |
| 535 | } |
| 536 | |
| 537 | private ITvInputSession getSessionLocked(IBinder sessionToken, int callingUid, int userId) { |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 538 | return getSessionLocked(getSessionStateLocked(sessionToken, callingUid, userId)); |
| 539 | } |
| 540 | |
| 541 | private ITvInputSession getSessionLocked(SessionState sessionState) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 542 | ITvInputSession session = sessionState.session; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 543 | if (session == null) { |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 544 | throw new IllegalStateException("Session not yet created for token " |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 545 | + sessionState.sessionToken); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 546 | } |
| 547 | return session; |
| 548 | } |
| 549 | |
| 550 | private int resolveCallingUserId(int callingPid, int callingUid, int requestedUserId, |
| 551 | String methodName) { |
| 552 | return ActivityManager.handleIncomingUser(callingPid, callingUid, requestedUserId, false, |
| 553 | false, methodName, null); |
| 554 | } |
| 555 | |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 556 | private void updateServiceConnectionLocked(ComponentName component, int userId) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 557 | UserState userState = getOrCreateUserStateLocked(userId); |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 558 | ServiceState serviceState = userState.serviceStateMap.get(component); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 559 | if (serviceState == null) { |
| 560 | return; |
| 561 | } |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 562 | if (serviceState.reconnecting) { |
| 563 | if (!serviceState.sessionTokens.isEmpty()) { |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 564 | // wait until all the sessions are removed. |
| 565 | return; |
| 566 | } |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 567 | serviceState.reconnecting = false; |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 568 | } |
shubang | 8049f20 | 2016-04-25 11:21:42 -0700 | [diff] [blame] | 569 | |
| 570 | boolean shouldBind; |
| 571 | if (userId == mCurrentUserId) { |
| 572 | shouldBind = !serviceState.sessionTokens.isEmpty() || serviceState.isHardware; |
| 573 | } else { |
| 574 | // For a non-current user, |
| 575 | // if sessionTokens is not empty, it contains recording sessions only |
| 576 | // because other sessions must have been removed while switching user |
| 577 | // and non-recording sessions are not created by createSession(). |
| 578 | shouldBind = !serviceState.sessionTokens.isEmpty(); |
| 579 | } |
| 580 | |
| 581 | if (serviceState.service == null && shouldBind) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 582 | // This means that the service is not yet connected but its state indicates that we |
| 583 | // have pending requests. Then, connect the service. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 584 | if (serviceState.bound) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 585 | // We have already bound to the service so we don't try to bind again until after we |
| 586 | // unbind later on. |
| 587 | return; |
| 588 | } |
| 589 | if (DEBUG) { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 590 | Slog.d(TAG, "bindServiceAsUser(service=" + component + ", userId=" + userId + ")"); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 591 | } |
Sungsoo Lim | d6672b5 | 2014-04-30 10:43:26 +0900 | [diff] [blame] | 592 | |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 593 | Intent i = new Intent(TvInputService.SERVICE_INTERFACE).setComponent(component); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 594 | serviceState.bound = mContext.bindServiceAsUser( |
Dianne Hackborn | d69e4c1 | 2015-04-24 09:54:54 -0700 | [diff] [blame] | 595 | i, serviceState.connection, |
| 596 | Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, |
| 597 | new UserHandle(userId)); |
shubang | 8049f20 | 2016-04-25 11:21:42 -0700 | [diff] [blame] | 598 | } else if (serviceState.service != null && !shouldBind) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 599 | // This means that the service is already connected but its state indicates that we have |
| 600 | // nothing to do with it. Then, disconnect the service. |
| 601 | if (DEBUG) { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 602 | Slog.d(TAG, "unbindService(service=" + component + ")"); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 603 | } |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 604 | mContext.unbindService(serviceState.connection); |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 605 | userState.serviceStateMap.remove(component); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
Dongwon Kang | 426c9a4 | 2014-08-26 17:39:21 +0900 | [diff] [blame] | 609 | private void abortPendingCreateSessionRequestsLocked(ServiceState serviceState, |
| 610 | String inputId, int userId) { |
| 611 | // Let clients know the create session requests are failed. |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 612 | UserState userState = getOrCreateUserStateLocked(userId); |
Dongwon Kang | f7f49dd | 2014-08-27 20:48:22 +0900 | [diff] [blame] | 613 | List<SessionState> sessionsToAbort = new ArrayList<>(); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 614 | for (IBinder sessionToken : serviceState.sessionTokens) { |
Dongwon Kang | 426c9a4 | 2014-08-26 17:39:21 +0900 | [diff] [blame] | 615 | SessionState sessionState = userState.sessionStateMap.get(sessionToken); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 616 | if (sessionState.session == null && (inputId == null |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 617 | || sessionState.inputId.equals(inputId))) { |
Dongwon Kang | f7f49dd | 2014-08-27 20:48:22 +0900 | [diff] [blame] | 618 | sessionsToAbort.add(sessionState); |
Dongwon Kang | 426c9a4 | 2014-08-26 17:39:21 +0900 | [diff] [blame] | 619 | } |
| 620 | } |
Dongwon Kang | f7f49dd | 2014-08-27 20:48:22 +0900 | [diff] [blame] | 621 | for (SessionState sessionState : sessionsToAbort) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 622 | removeSessionStateLocked(sessionState.sessionToken, sessionState.userId); |
| 623 | sendSessionTokenToClientLocked(sessionState.client, |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 624 | sessionState.inputId, null, null, sessionState.seq); |
Dongwon Kang | f7f49dd | 2014-08-27 20:48:22 +0900 | [diff] [blame] | 625 | } |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 626 | updateServiceConnectionLocked(serviceState.component, userId); |
Dongwon Kang | 426c9a4 | 2014-08-26 17:39:21 +0900 | [diff] [blame] | 627 | } |
| 628 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 629 | private void createSessionInternalLocked(ITvInputService service, IBinder sessionToken, |
| 630 | int userId) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 631 | UserState userState = getOrCreateUserStateLocked(userId); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 632 | SessionState sessionState = userState.sessionStateMap.get(sessionToken); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 633 | if (DEBUG) { |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 634 | Slog.d(TAG, "createSessionInternalLocked(inputId=" + sessionState.inputId + ")"); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 635 | } |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 636 | InputChannel[] channels = InputChannel.openInputChannelPair(sessionToken.toString()); |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 637 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 638 | // Set up a callback to send the session token. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 639 | ITvInputSessionCallback callback = new SessionCallback(sessionState, channels); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 640 | |
| 641 | // Create a session. When failed, send a null token immediately. |
| 642 | try { |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 643 | if (sessionState.isRecordingSession) { |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 644 | service.createRecordingSession(callback, sessionState.inputId); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 645 | } else { |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 646 | service.createSession(channels[1], callback, sessionState.inputId); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 647 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 648 | } catch (RemoteException e) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 649 | Slog.e(TAG, "error in createSession", e); |
Dongwon Kang | fd5b72f | 2014-04-15 17:23:24 +0900 | [diff] [blame] | 650 | removeSessionStateLocked(sessionToken, userId); |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 651 | sendSessionTokenToClientLocked(sessionState.client, sessionState.inputId, null, |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 652 | null, sessionState.seq); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 653 | } |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 654 | channels[1].dispose(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 655 | } |
| 656 | |
Sungsoo Lim | d6672b5 | 2014-04-30 10:43:26 +0900 | [diff] [blame] | 657 | private void sendSessionTokenToClientLocked(ITvInputClient client, String inputId, |
Jae Seo | 5c80ad2 | 2014-06-12 19:52:58 -0700 | [diff] [blame] | 658 | IBinder sessionToken, InputChannel channel, int seq) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 659 | try { |
Sungsoo Lim | d6672b5 | 2014-04-30 10:43:26 +0900 | [diff] [blame] | 660 | client.onSessionCreated(inputId, sessionToken, channel, seq); |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 661 | } catch (RemoteException e) { |
| 662 | Slog.e(TAG, "error in onSessionCreated", e); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 663 | } |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 664 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 665 | |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 666 | private void releaseSessionLocked(IBinder sessionToken, int callingUid, int userId) { |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 667 | SessionState sessionState = null; |
| 668 | try { |
| 669 | sessionState = getSessionStateLocked(sessionToken, callingUid, userId); |
| 670 | if (sessionState.session != null) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 671 | UserState userState = getOrCreateUserStateLocked(userId); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 672 | if (sessionToken == userState.mainSessionToken) { |
| 673 | setMainLocked(sessionToken, false, callingUid, userId); |
| 674 | } |
Jae Seo | e3c11e8 | 2016-02-08 23:18:49 -0800 | [diff] [blame] | 675 | sessionState.session.release(); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 676 | } |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 677 | } catch (RemoteException | SessionNotFoundException e) { |
| 678 | Slog.e(TAG, "error in releaseSession", e); |
| 679 | } finally { |
| 680 | if (sessionState != null) { |
| 681 | sessionState.session = null; |
| 682 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 683 | } |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 684 | removeSessionStateLocked(sessionToken, userId); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Dongwon Kang | fd5b72f | 2014-04-15 17:23:24 +0900 | [diff] [blame] | 687 | private void removeSessionStateLocked(IBinder sessionToken, int userId) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 688 | UserState userState = getOrCreateUserStateLocked(userId); |
Ji-Hwan Lee | abca0ee | 2014-07-24 17:34:19 +0900 | [diff] [blame] | 689 | if (sessionToken == userState.mainSessionToken) { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 690 | if (DEBUG) { |
| 691 | Slog.d(TAG, "mainSessionToken=null"); |
| 692 | } |
Ji-Hwan Lee | abca0ee | 2014-07-24 17:34:19 +0900 | [diff] [blame] | 693 | userState.mainSessionToken = null; |
| 694 | } |
| 695 | |
| 696 | // Remove the session state from the global session state map of the current user. |
Dongwon Kang | fd5b72f | 2014-04-15 17:23:24 +0900 | [diff] [blame] | 697 | SessionState sessionState = userState.sessionStateMap.remove(sessionToken); |
| 698 | |
Chulwoo Lee | 8d4ded0 | 2014-07-10 03:56:39 +0900 | [diff] [blame] | 699 | if (sessionState == null) { |
| 700 | return; |
| 701 | } |
| 702 | |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 703 | // Also remove the session token from the session token list of the current client and |
| 704 | // service. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 705 | ClientState clientState = userState.clientStateMap.get(sessionState.client.asBinder()); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 706 | if (clientState != null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 707 | clientState.sessionTokens.remove(sessionToken); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 708 | if (clientState.isEmpty()) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 709 | userState.clientStateMap.remove(sessionState.client.asBinder()); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 713 | ServiceState serviceState = userState.serviceStateMap.get(sessionState.componentName); |
| 714 | if (serviceState != null) { |
| 715 | serviceState.sessionTokens.remove(sessionToken); |
Dongwon Kang | fd5b72f | 2014-04-15 17:23:24 +0900 | [diff] [blame] | 716 | } |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 717 | updateServiceConnectionLocked(sessionState.componentName, userId); |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 718 | |
| 719 | // Log the end of watch. |
| 720 | SomeArgs args = SomeArgs.obtain(); |
| 721 | args.arg1 = sessionToken; |
| 722 | args.arg2 = System.currentTimeMillis(); |
| 723 | mWatchLogHandler.obtainMessage(WatchLogHandler.MSG_LOG_WATCH_END, args).sendToTarget(); |
Dongwon Kang | fd5b72f | 2014-04-15 17:23:24 +0900 | [diff] [blame] | 724 | } |
| 725 | |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 726 | private void setMainLocked(IBinder sessionToken, boolean isMain, int callingUid, int userId) { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 727 | try { |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 728 | SessionState sessionState = getSessionStateLocked(sessionToken, callingUid, userId); |
| 729 | if (sessionState.hardwareSessionToken != null) { |
| 730 | sessionState = getSessionStateLocked(sessionState.hardwareSessionToken, |
| 731 | Process.SYSTEM_UID, userId); |
| 732 | } |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 733 | ServiceState serviceState = getServiceStateLocked(sessionState.componentName, userId); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 734 | if (!serviceState.isHardware) { |
| 735 | return; |
| 736 | } |
| 737 | ITvInputSession session = getSessionLocked(sessionState); |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 738 | session.setMain(isMain); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 739 | } catch (RemoteException | SessionNotFoundException e) { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 740 | Slog.e(TAG, "error in setMain", e); |
| 741 | } |
| 742 | } |
| 743 | |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 744 | private void notifyInputAddedLocked(UserState userState, String inputId) { |
| 745 | if (DEBUG) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 746 | Slog.d(TAG, "notifyInputAddedLocked(inputId=" + inputId + ")"); |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 747 | } |
| 748 | for (ITvInputManagerCallback callback : userState.callbackSet) { |
| 749 | try { |
| 750 | callback.onInputAdded(inputId); |
| 751 | } catch (RemoteException e) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 752 | Slog.e(TAG, "failed to report added input to callback", e); |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | private void notifyInputRemovedLocked(UserState userState, String inputId) { |
| 758 | if (DEBUG) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 759 | Slog.d(TAG, "notifyInputRemovedLocked(inputId=" + inputId + ")"); |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 760 | } |
| 761 | for (ITvInputManagerCallback callback : userState.callbackSet) { |
| 762 | try { |
| 763 | callback.onInputRemoved(inputId); |
| 764 | } catch (RemoteException e) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 765 | Slog.e(TAG, "failed to report removed input to callback", e); |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | } |
| 769 | |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 770 | private void notifyInputUpdatedLocked(UserState userState, String inputId) { |
| 771 | if (DEBUG) { |
| 772 | Slog.d(TAG, "notifyInputUpdatedLocked(inputId=" + inputId + ")"); |
| 773 | } |
| 774 | for (ITvInputManagerCallback callback : userState.callbackSet) { |
| 775 | try { |
| 776 | callback.onInputUpdated(inputId); |
| 777 | } catch (RemoteException e) { |
| 778 | Slog.e(TAG, "failed to report updated input to callback", e); |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 783 | private void notifyInputStateChangedLocked(UserState userState, String inputId, |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 784 | int state, ITvInputManagerCallback targetCallback) { |
| 785 | if (DEBUG) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 786 | Slog.d(TAG, "notifyInputStateChangedLocked(inputId=" + inputId |
| 787 | + ", state=" + state + ")"); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 788 | } |
| 789 | if (targetCallback == null) { |
| 790 | for (ITvInputManagerCallback callback : userState.callbackSet) { |
| 791 | try { |
| 792 | callback.onInputStateChanged(inputId, state); |
| 793 | } catch (RemoteException e) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 794 | Slog.e(TAG, "failed to report state change to callback", e); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 795 | } |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 796 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 797 | } else { |
| 798 | try { |
| 799 | targetCallback.onInputStateChanged(inputId, state); |
| 800 | } catch (RemoteException e) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 801 | Slog.e(TAG, "failed to report state change to callback", e); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
Jae Seo | aa5605f | 2016-02-13 01:38:08 -0800 | [diff] [blame] | 806 | private void updateTvInputInfoLocked(UserState userState, TvInputInfo inputInfo) { |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 807 | if (DEBUG) { |
Jae Seo | aa5605f | 2016-02-13 01:38:08 -0800 | [diff] [blame] | 808 | Slog.d(TAG, "updateTvInputInfoLocked(inputInfo=" + inputInfo + ")"); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 809 | } |
Jae Seo | abda420 | 2016-01-28 19:13:04 -0800 | [diff] [blame] | 810 | String inputId = inputInfo.getId(); |
| 811 | TvInputState inputState = userState.inputMap.get(inputId); |
| 812 | if (inputState == null) { |
| 813 | Slog.e(TAG, "failed to set input info - unknown input id " + inputId); |
| 814 | return; |
| 815 | } |
Jae Seo | abda420 | 2016-01-28 19:13:04 -0800 | [diff] [blame] | 816 | inputState.info = inputInfo; |
| 817 | |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 818 | for (ITvInputManagerCallback callback : userState.callbackSet) { |
| 819 | try { |
Jae Seo | aa5605f | 2016-02-13 01:38:08 -0800 | [diff] [blame] | 820 | callback.onTvInputInfoUpdated(inputInfo); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 821 | } catch (RemoteException e) { |
Jae Seo | aa5605f | 2016-02-13 01:38:08 -0800 | [diff] [blame] | 822 | Slog.e(TAG, "failed to report updated input info to callback", e); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | } |
| 826 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 827 | private void setStateLocked(String inputId, int state, int userId) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 828 | UserState userState = getOrCreateUserStateLocked(userId); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 829 | TvInputState inputState = userState.inputMap.get(inputId); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 830 | ServiceState serviceState = userState.serviceStateMap.get(inputState.info.getComponent()); |
| 831 | int oldState = inputState.state; |
| 832 | inputState.state = state; |
| 833 | if (serviceState != null && serviceState.service == null |
shubang | 8049f20 | 2016-04-25 11:21:42 -0700 | [diff] [blame] | 834 | && (!serviceState.sessionTokens.isEmpty() || serviceState.isHardware)) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 835 | // We don't notify state change while reconnecting. It should remain disconnected. |
| 836 | return; |
| 837 | } |
| 838 | if (oldState != state) { |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 839 | notifyInputStateChangedLocked(userState, inputId, state, null); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 843 | private final class BinderService extends ITvInputManager.Stub { |
| 844 | @Override |
| 845 | public List<TvInputInfo> getTvInputList(int userId) { |
| 846 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 847 | Binder.getCallingUid(), userId, "getTvInputList"); |
| 848 | final long identity = Binder.clearCallingIdentity(); |
| 849 | try { |
| 850 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 851 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 852 | List<TvInputInfo> inputList = new ArrayList<>(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 853 | for (TvInputState state : userState.inputMap.values()) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 854 | inputList.add(state.info); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 855 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 856 | return inputList; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 857 | } |
| 858 | } finally { |
| 859 | Binder.restoreCallingIdentity(identity); |
| 860 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | @Override |
Jae Seo | b375805 | 2014-07-12 19:25:24 -0700 | [diff] [blame] | 864 | public TvInputInfo getTvInputInfo(String inputId, int userId) { |
| 865 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 866 | Binder.getCallingUid(), userId, "getTvInputInfo"); |
| 867 | final long identity = Binder.clearCallingIdentity(); |
| 868 | try { |
| 869 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 870 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | b375805 | 2014-07-12 19:25:24 -0700 | [diff] [blame] | 871 | TvInputState state = userState.inputMap.get(inputId); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 872 | return state == null ? null : state.info; |
Jae Seo | b375805 | 2014-07-12 19:25:24 -0700 | [diff] [blame] | 873 | } |
| 874 | } finally { |
| 875 | Binder.restoreCallingIdentity(identity); |
| 876 | } |
| 877 | } |
| 878 | |
Jae Seo | aa5605f | 2016-02-13 01:38:08 -0800 | [diff] [blame] | 879 | public void updateTvInputInfo(TvInputInfo inputInfo, int userId) { |
Jae Seo | c2a8951 | 2016-01-28 10:38:11 -0800 | [diff] [blame] | 880 | String inputInfoPackageName = inputInfo.getServiceInfo().packageName; |
| 881 | String callingPackageName = getCallingPackageName(); |
Dongwon Kang | 9d0e0f1 | 2016-10-11 15:14:01 -0700 | [diff] [blame] | 882 | if (!TextUtils.equals(inputInfoPackageName, callingPackageName) |
| 883 | && mContext.checkCallingPermission( |
| 884 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 885 | != PackageManager.PERMISSION_GRANTED) { |
| 886 | // Only the app owning the input and system settings are allowed to update info. |
Jae Seo | c2a8951 | 2016-01-28 10:38:11 -0800 | [diff] [blame] | 887 | throw new IllegalArgumentException("calling package " + callingPackageName |
| 888 | + " is not allowed to change TvInputInfo for " + inputInfoPackageName); |
| 889 | } |
| 890 | |
| 891 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
Jae Seo | aa5605f | 2016-02-13 01:38:08 -0800 | [diff] [blame] | 892 | Binder.getCallingUid(), userId, "updateTvInputInfo"); |
Jae Seo | c2a8951 | 2016-01-28 10:38:11 -0800 | [diff] [blame] | 893 | final long identity = Binder.clearCallingIdentity(); |
| 894 | try { |
| 895 | synchronized (mLock) { |
| 896 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | aa5605f | 2016-02-13 01:38:08 -0800 | [diff] [blame] | 897 | updateTvInputInfoLocked(userState, inputInfo); |
Jae Seo | c2a8951 | 2016-01-28 10:38:11 -0800 | [diff] [blame] | 898 | } |
| 899 | } finally { |
| 900 | Binder.restoreCallingIdentity(identity); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | private String getCallingPackageName() { |
| 905 | final String[] packages = mContext.getPackageManager().getPackagesForUid( |
| 906 | Binder.getCallingUid()); |
| 907 | if (packages != null && packages.length > 0) { |
| 908 | return packages[0]; |
| 909 | } |
| 910 | return "unknown"; |
| 911 | } |
| 912 | |
Jae Seo | b375805 | 2014-07-12 19:25:24 -0700 | [diff] [blame] | 913 | @Override |
Dongwon Kang | 993f81e | 2014-11-27 19:34:18 +0900 | [diff] [blame] | 914 | public int getTvInputState(String inputId, int userId) { |
| 915 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 916 | Binder.getCallingUid(), userId, "getTvInputState"); |
| 917 | final long identity = Binder.clearCallingIdentity(); |
| 918 | try { |
| 919 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 920 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Dongwon Kang | 993f81e | 2014-11-27 19:34:18 +0900 | [diff] [blame] | 921 | TvInputState state = userState.inputMap.get(inputId); |
Jae Seo | 82fce64 | 2015-04-20 15:37:50 -0700 | [diff] [blame] | 922 | return state == null ? INPUT_STATE_CONNECTED : state.state; |
Dongwon Kang | 993f81e | 2014-11-27 19:34:18 +0900 | [diff] [blame] | 923 | } |
| 924 | } finally { |
| 925 | Binder.restoreCallingIdentity(identity); |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | @Override |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 930 | public List<TvContentRatingSystemInfo> getTvContentRatingSystemList(int userId) { |
Shubang | dd3ec0b | 2017-06-23 13:54:10 -0700 | [diff] [blame] | 931 | if (mContext.checkCallingPermission( |
| 932 | android.Manifest.permission.READ_CONTENT_RATING_SYSTEMS) |
| 933 | != PackageManager.PERMISSION_GRANTED) { |
| 934 | throw new SecurityException( |
| 935 | "The caller does not have permission to read content rating systems"); |
| 936 | } |
Sungsoo Lim | 5c5b83f | 2014-07-29 11:48:36 +0900 | [diff] [blame] | 937 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 938 | Binder.getCallingUid(), userId, "getTvContentRatingSystemList"); |
Sungsoo Lim | 5c5b83f | 2014-07-29 11:48:36 +0900 | [diff] [blame] | 939 | final long identity = Binder.clearCallingIdentity(); |
| 940 | try { |
| 941 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 942 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 943 | return userState.contentRatingSystemList; |
Sungsoo Lim | 5c5b83f | 2014-07-29 11:48:36 +0900 | [diff] [blame] | 944 | } |
| 945 | } finally { |
| 946 | Binder.restoreCallingIdentity(identity); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | @Override |
Conrad Chen | 558acf9 | 2017-04-05 17:31:01 -0700 | [diff] [blame] | 951 | public void sendTvInputNotifyIntent(Intent intent, int userId) { |
| 952 | if (mContext.checkCallingPermission(android.Manifest.permission.NOTIFY_TV_INPUTS) |
| 953 | != PackageManager.PERMISSION_GRANTED) { |
| 954 | throw new SecurityException("The caller: " + getCallingPackageName() |
| 955 | + " doesn't have permission: " |
| 956 | + android.Manifest.permission.NOTIFY_TV_INPUTS); |
| 957 | } |
| 958 | if (TextUtils.isEmpty(intent.getPackage())) { |
| 959 | throw new IllegalArgumentException("Must specify package name to notify."); |
| 960 | } |
| 961 | switch (intent.getAction()) { |
| 962 | case TvContract.ACTION_PREVIEW_PROGRAM_BROWSABLE_DISABLED: |
| 963 | if (intent.getLongExtra(TvContract.EXTRA_PREVIEW_PROGRAM_ID, -1) < 0) { |
| 964 | throw new IllegalArgumentException("Invalid preview program ID."); |
| 965 | } |
| 966 | break; |
| 967 | case TvContract.ACTION_WATCH_NEXT_PROGRAM_BROWSABLE_DISABLED: |
| 968 | if (intent.getLongExtra(TvContract.EXTRA_WATCH_NEXT_PROGRAM_ID, -1) < 0) { |
| 969 | throw new IllegalArgumentException("Invalid watch next program ID."); |
| 970 | } |
| 971 | break; |
| 972 | case TvContract.ACTION_PREVIEW_PROGRAM_ADDED_TO_WATCH_NEXT: |
| 973 | if (intent.getLongExtra(TvContract.EXTRA_PREVIEW_PROGRAM_ID, -1) < 0) { |
| 974 | throw new IllegalArgumentException("Invalid preview program ID."); |
| 975 | } |
| 976 | if (intent.getLongExtra(TvContract.EXTRA_WATCH_NEXT_PROGRAM_ID, -1) < 0) { |
| 977 | throw new IllegalArgumentException("Invalid watch next program ID."); |
| 978 | } |
| 979 | break; |
| 980 | default: |
| 981 | throw new IllegalArgumentException("Invalid TV input notifying action: " |
| 982 | + intent.getAction()); |
| 983 | } |
| 984 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 985 | Binder.getCallingUid(), userId, "sendTvInputNotifyIntent"); |
| 986 | final long identity = Binder.clearCallingIdentity(); |
| 987 | try { |
| 988 | getContext().sendBroadcastAsUser(intent, new UserHandle(resolvedUserId)); |
| 989 | } finally { |
| 990 | Binder.restoreCallingIdentity(identity); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | @Override |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 995 | public void registerCallback(final ITvInputManagerCallback callback, int userId) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 996 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 997 | Binder.getCallingUid(), userId, "registerCallback"); |
| 998 | final long identity = Binder.clearCallingIdentity(); |
| 999 | try { |
| 1000 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1001 | final UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1002 | userState.callbackSet.add(callback); |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 1003 | try { |
| 1004 | callback.asBinder().linkToDeath(new IBinder.DeathRecipient() { |
| 1005 | @Override |
| 1006 | public void binderDied() { |
| 1007 | synchronized (mLock) { |
| 1008 | if (userState.callbackSet != null) { |
| 1009 | userState.callbackSet.remove(callback); |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | }, 0); |
| 1014 | } catch (RemoteException e) { |
| 1015 | Slog.e(TAG, "client process has already died", e); |
| 1016 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1017 | } |
| 1018 | } finally { |
| 1019 | Binder.restoreCallingIdentity(identity); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | @Override |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1024 | public void unregisterCallback(ITvInputManagerCallback callback, int userId) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1025 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 1026 | Binder.getCallingUid(), userId, "unregisterCallback"); |
| 1027 | final long identity = Binder.clearCallingIdentity(); |
| 1028 | try { |
| 1029 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1030 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1031 | userState.callbackSet.remove(callback); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1032 | } |
| 1033 | } finally { |
| 1034 | Binder.restoreCallingIdentity(identity); |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | @Override |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 1039 | public boolean isParentalControlsEnabled(int userId) { |
| 1040 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 1041 | Binder.getCallingUid(), userId, "isParentalControlsEnabled"); |
| 1042 | final long identity = Binder.clearCallingIdentity(); |
| 1043 | try { |
| 1044 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1045 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 1046 | return userState.persistentDataStore.isParentalControlsEnabled(); |
| 1047 | } |
| 1048 | } finally { |
| 1049 | Binder.restoreCallingIdentity(identity); |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | @Override |
| 1054 | public void setParentalControlsEnabled(boolean enabled, int userId) { |
| 1055 | ensureParentalControlsPermission(); |
| 1056 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 1057 | Binder.getCallingUid(), userId, "setParentalControlsEnabled"); |
| 1058 | final long identity = Binder.clearCallingIdentity(); |
| 1059 | try { |
| 1060 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1061 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 1062 | userState.persistentDataStore.setParentalControlsEnabled(enabled); |
| 1063 | } |
| 1064 | } finally { |
| 1065 | Binder.restoreCallingIdentity(identity); |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | @Override |
| 1070 | public boolean isRatingBlocked(String rating, int userId) { |
| 1071 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 1072 | Binder.getCallingUid(), userId, "isRatingBlocked"); |
| 1073 | final long identity = Binder.clearCallingIdentity(); |
| 1074 | try { |
| 1075 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1076 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 1077 | return userState.persistentDataStore.isRatingBlocked( |
| 1078 | TvContentRating.unflattenFromString(rating)); |
| 1079 | } |
| 1080 | } finally { |
| 1081 | Binder.restoreCallingIdentity(identity); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | @Override |
| 1086 | public List<String> getBlockedRatings(int userId) { |
| 1087 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 1088 | Binder.getCallingUid(), userId, "getBlockedRatings"); |
| 1089 | final long identity = Binder.clearCallingIdentity(); |
| 1090 | try { |
| 1091 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1092 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 1093 | List<String> ratings = new ArrayList<>(); |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 1094 | for (TvContentRating rating |
| 1095 | : userState.persistentDataStore.getBlockedRatings()) { |
| 1096 | ratings.add(rating.flattenToString()); |
| 1097 | } |
| 1098 | return ratings; |
| 1099 | } |
| 1100 | } finally { |
| 1101 | Binder.restoreCallingIdentity(identity); |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | @Override |
| 1106 | public void addBlockedRating(String rating, int userId) { |
| 1107 | ensureParentalControlsPermission(); |
| 1108 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 1109 | Binder.getCallingUid(), userId, "addBlockedRating"); |
| 1110 | final long identity = Binder.clearCallingIdentity(); |
| 1111 | try { |
| 1112 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1113 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 1114 | userState.persistentDataStore.addBlockedRating( |
| 1115 | TvContentRating.unflattenFromString(rating)); |
| 1116 | } |
| 1117 | } finally { |
| 1118 | Binder.restoreCallingIdentity(identity); |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | @Override |
| 1123 | public void removeBlockedRating(String rating, int userId) { |
| 1124 | ensureParentalControlsPermission(); |
| 1125 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), |
| 1126 | Binder.getCallingUid(), userId, "removeBlockedRating"); |
| 1127 | final long identity = Binder.clearCallingIdentity(); |
| 1128 | try { |
| 1129 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1130 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 1131 | userState.persistentDataStore.removeBlockedRating( |
| 1132 | TvContentRating.unflattenFromString(rating)); |
| 1133 | } |
| 1134 | } finally { |
| 1135 | Binder.restoreCallingIdentity(identity); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | private void ensureParentalControlsPermission() { |
Jae Seo | fc836f6 | 2014-08-27 00:47:56 +0000 | [diff] [blame] | 1140 | if (mContext.checkCallingPermission( |
| 1141 | android.Manifest.permission.MODIFY_PARENTAL_CONTROLS) |
| 1142 | != PackageManager.PERMISSION_GRANTED) { |
| 1143 | throw new SecurityException( |
| 1144 | "The caller does not have parental controls permission"); |
| 1145 | } |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | @Override |
Sungsoo Lim | d6672b5 | 2014-04-30 10:43:26 +0900 | [diff] [blame] | 1149 | public void createSession(final ITvInputClient client, final String inputId, |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 1150 | boolean isRecordingSession, int seq, int userId) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1151 | final int callingUid = Binder.getCallingUid(); |
| 1152 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1153 | userId, "createSession"); |
| 1154 | final long identity = Binder.clearCallingIdentity(); |
| 1155 | try { |
| 1156 | synchronized (mLock) { |
shubang | 8049f20 | 2016-04-25 11:21:42 -0700 | [diff] [blame] | 1157 | if (userId != mCurrentUserId && !isRecordingSession) { |
| 1158 | // A non-recording session of a backgroud (non-current) user |
| 1159 | // should not be created. |
| 1160 | // Let the client get onConnectionFailed callback for this case. |
| 1161 | sendSessionTokenToClientLocked(client, inputId, null, null, seq); |
| 1162 | return; |
| 1163 | } |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1164 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Dongwon Kang | 426c9a4 | 2014-08-26 17:39:21 +0900 | [diff] [blame] | 1165 | TvInputState inputState = userState.inputMap.get(inputId); |
| 1166 | if (inputState == null) { |
| 1167 | Slog.w(TAG, "Failed to find input state for inputId=" + inputId); |
| 1168 | sendSessionTokenToClientLocked(client, inputId, null, null, seq); |
| 1169 | return; |
| 1170 | } |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1171 | TvInputInfo info = inputState.info; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1172 | ServiceState serviceState = userState.serviceStateMap.get(info.getComponent()); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1173 | if (serviceState == null) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1174 | serviceState = new ServiceState(info.getComponent(), resolvedUserId); |
| 1175 | userState.serviceStateMap.put(info.getComponent(), serviceState); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1176 | } |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1177 | // Send a null token immediately while reconnecting. |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 1178 | if (serviceState.reconnecting) { |
Jae Seo | 5c80ad2 | 2014-06-12 19:52:58 -0700 | [diff] [blame] | 1179 | sendSessionTokenToClientLocked(client, inputId, null, null, seq); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1180 | return; |
| 1181 | } |
| 1182 | |
| 1183 | // Create a new session token and a session state. |
| 1184 | IBinder sessionToken = new Binder(); |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 1185 | SessionState sessionState = new SessionState(sessionToken, info.getId(), |
| 1186 | info.getComponent(), isRecordingSession, client, seq, callingUid, |
| 1187 | resolvedUserId); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1188 | |
| 1189 | // Add them to the global session state map of the current user. |
| 1190 | userState.sessionStateMap.put(sessionToken, sessionState); |
| 1191 | |
| 1192 | // Also, add them to the session state map of the current service. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1193 | serviceState.sessionTokens.add(sessionToken); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1194 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1195 | if (serviceState.service != null) { |
| 1196 | createSessionInternalLocked(serviceState.service, sessionToken, |
Sungsoo Lim | 7de5e23 | 2014-04-12 16:51:27 +0900 | [diff] [blame] | 1197 | resolvedUserId); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1198 | } else { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 1199 | updateServiceConnectionLocked(info.getComponent(), resolvedUserId); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | } finally { |
| 1203 | Binder.restoreCallingIdentity(identity); |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | @Override |
| 1208 | public void releaseSession(IBinder sessionToken, int userId) { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1209 | if (DEBUG) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 1210 | Slog.d(TAG, "releaseSession(sessionToken=" + sessionToken + ")"); |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1211 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1212 | final int callingUid = Binder.getCallingUid(); |
| 1213 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1214 | userId, "releaseSession"); |
| 1215 | final long identity = Binder.clearCallingIdentity(); |
| 1216 | try { |
| 1217 | synchronized (mLock) { |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1218 | releaseSessionLocked(sessionToken, callingUid, resolvedUserId); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1219 | } |
| 1220 | } finally { |
| 1221 | Binder.restoreCallingIdentity(identity); |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | @Override |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 1226 | public void setMainSession(IBinder sessionToken, int userId) { |
Shubang | e41b76f | 2017-06-07 13:23:12 -0700 | [diff] [blame] | 1227 | if (mContext.checkCallingPermission( |
| 1228 | android.Manifest.permission.CHANGE_HDMI_CEC_ACTIVE_SOURCE) |
| 1229 | != PackageManager.PERMISSION_GRANTED) { |
| 1230 | throw new SecurityException( |
| 1231 | "The caller does not have CHANGE_HDMI_CEC_ACTIVE_SOURCE permission"); |
| 1232 | } |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1233 | if (DEBUG) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 1234 | Slog.d(TAG, "setMainSession(sessionToken=" + sessionToken + ")"); |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1235 | } |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 1236 | final int callingUid = Binder.getCallingUid(); |
| 1237 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1238 | userId, "setMainSession"); |
| 1239 | final long identity = Binder.clearCallingIdentity(); |
| 1240 | try { |
| 1241 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1242 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Ji-Hwan Lee | 956afc2 | 2014-07-26 11:31:39 +0900 | [diff] [blame] | 1243 | if (userState.mainSessionToken == sessionToken) { |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 1244 | return; |
| 1245 | } |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1246 | if (DEBUG) { |
| 1247 | Slog.d(TAG, "mainSessionToken=" + sessionToken); |
Ji-Hwan Lee | 956afc2 | 2014-07-26 11:31:39 +0900 | [diff] [blame] | 1248 | } |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1249 | IBinder oldMainSessionToken = userState.mainSessionToken; |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 1250 | userState.mainSessionToken = sessionToken; |
| 1251 | |
Ji-Hwan Lee | 956afc2 | 2014-07-26 11:31:39 +0900 | [diff] [blame] | 1252 | // Inform the new main session first. |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1253 | // See {@link TvInputService.Session#onSetMain}. |
| 1254 | if (sessionToken != null) { |
| 1255 | setMainLocked(sessionToken, true, callingUid, userId); |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 1256 | } |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1257 | if (oldMainSessionToken != null) { |
| 1258 | setMainLocked(oldMainSessionToken, false, Process.SYSTEM_UID, userId); |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | } finally { |
| 1262 | Binder.restoreCallingIdentity(identity); |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | @Override |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1267 | public void setSurface(IBinder sessionToken, Surface surface, int userId) { |
| 1268 | final int callingUid = Binder.getCallingUid(); |
| 1269 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1270 | userId, "setSurface"); |
| 1271 | final long identity = Binder.clearCallingIdentity(); |
| 1272 | try { |
| 1273 | synchronized (mLock) { |
| 1274 | try { |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1275 | SessionState sessionState = getSessionStateLocked(sessionToken, callingUid, |
| 1276 | resolvedUserId); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1277 | if (sessionState.hardwareSessionToken == null) { |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1278 | getSessionLocked(sessionState).setSurface(surface); |
| 1279 | } else { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1280 | getSessionLocked(sessionState.hardwareSessionToken, |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1281 | Process.SYSTEM_UID, resolvedUserId).setSurface(surface); |
| 1282 | } |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1283 | } catch (RemoteException | SessionNotFoundException e) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1284 | Slog.e(TAG, "error in setSurface", e); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | } finally { |
Youngsang Cho | f836206 | 2014-04-30 17:24:20 +0900 | [diff] [blame] | 1288 | if (surface != null) { |
| 1289 | // surface is not used in TvInputManagerService. |
| 1290 | surface.release(); |
| 1291 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1292 | Binder.restoreCallingIdentity(identity); |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | @Override |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 1297 | public void dispatchSurfaceChanged(IBinder sessionToken, int format, int width, |
| 1298 | int height, int userId) { |
| 1299 | final int callingUid = Binder.getCallingUid(); |
| 1300 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1301 | userId, "dispatchSurfaceChanged"); |
| 1302 | final long identity = Binder.clearCallingIdentity(); |
| 1303 | try { |
| 1304 | synchronized (mLock) { |
| 1305 | try { |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1306 | SessionState sessionState = getSessionStateLocked(sessionToken, callingUid, |
| 1307 | resolvedUserId); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1308 | getSessionLocked(sessionState).dispatchSurfaceChanged(format, width, |
| 1309 | height); |
| 1310 | if (sessionState.hardwareSessionToken != null) { |
| 1311 | getSessionLocked(sessionState.hardwareSessionToken, Process.SYSTEM_UID, |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1312 | resolvedUserId).dispatchSurfaceChanged(format, width, height); |
| 1313 | } |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1314 | } catch (RemoteException | SessionNotFoundException e) { |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 1315 | Slog.e(TAG, "error in dispatchSurfaceChanged", e); |
| 1316 | } |
| 1317 | } |
| 1318 | } finally { |
| 1319 | Binder.restoreCallingIdentity(identity); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | @Override |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1324 | public void setVolume(IBinder sessionToken, float volume, int userId) { |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1325 | final float REMOTE_VOLUME_ON = 1.0f; |
| 1326 | final float REMOTE_VOLUME_OFF = 0f; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1327 | final int callingUid = Binder.getCallingUid(); |
| 1328 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1329 | userId, "setVolume"); |
| 1330 | final long identity = Binder.clearCallingIdentity(); |
| 1331 | try { |
| 1332 | synchronized (mLock) { |
| 1333 | try { |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1334 | SessionState sessionState = getSessionStateLocked(sessionToken, callingUid, |
| 1335 | resolvedUserId); |
| 1336 | getSessionLocked(sessionState).setVolume(volume); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1337 | if (sessionState.hardwareSessionToken != null) { |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1338 | // Here, we let the hardware session know only whether volume is on or |
| 1339 | // off to prevent that the volume is controlled in the both side. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1340 | getSessionLocked(sessionState.hardwareSessionToken, |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1341 | Process.SYSTEM_UID, resolvedUserId).setVolume((volume > 0.0f) |
| 1342 | ? REMOTE_VOLUME_ON : REMOTE_VOLUME_OFF); |
| 1343 | } |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1344 | } catch (RemoteException | SessionNotFoundException e) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1345 | Slog.e(TAG, "error in setVolume", e); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | } finally { |
| 1349 | Binder.restoreCallingIdentity(identity); |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | @Override |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 1354 | public void tune(IBinder sessionToken, final Uri channelUri, Bundle params, int userId) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1355 | final int callingUid = Binder.getCallingUid(); |
| 1356 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1357 | userId, "tune"); |
| 1358 | final long identity = Binder.clearCallingIdentity(); |
| 1359 | try { |
| 1360 | synchronized (mLock) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1361 | try { |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 1362 | getSessionLocked(sessionToken, callingUid, resolvedUserId).tune( |
| 1363 | channelUri, params); |
Jae Seo | c22d0c0 | 2014-08-15 13:03:21 -0700 | [diff] [blame] | 1364 | if (TvContract.isChannelUriForPassthroughInput(channelUri)) { |
Youngsang Cho | 008f6d4 | 2014-07-22 21:29:47 -0700 | [diff] [blame] | 1365 | // Do not log the watch history for passthrough inputs. |
| 1366 | return; |
| 1367 | } |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 1368 | |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1369 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 1370 | SessionState sessionState = userState.sessionStateMap.get(sessionToken); |
Jae Seo | e3c11e8 | 2016-02-08 23:18:49 -0800 | [diff] [blame] | 1371 | if (sessionState.isRecordingSession) { |
| 1372 | return; |
| 1373 | } |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 1374 | |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 1375 | // Log the start of watch. |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 1376 | SomeArgs args = SomeArgs.obtain(); |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 1377 | args.arg1 = sessionState.componentName.getPackageName(); |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 1378 | args.arg2 = System.currentTimeMillis(); |
| 1379 | args.arg3 = ContentUris.parseId(channelUri); |
| 1380 | args.arg4 = params; |
| 1381 | args.arg5 = sessionToken; |
| 1382 | mWatchLogHandler.obtainMessage(WatchLogHandler.MSG_LOG_WATCH_START, args) |
| 1383 | .sendToTarget(); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1384 | } catch (RemoteException | SessionNotFoundException e) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1385 | Slog.e(TAG, "error in tune", e); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | } finally { |
| 1389 | Binder.restoreCallingIdentity(identity); |
| 1390 | } |
| 1391 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1392 | |
| 1393 | @Override |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 1394 | public void unblockContent( |
Sungsoo Lim | 9bf671f | 2014-07-19 12:59:51 +0900 | [diff] [blame] | 1395 | IBinder sessionToken, String unblockedRating, int userId) { |
Dongwon Kang | e12d810 | 2016-03-04 16:45:39 -0800 | [diff] [blame] | 1396 | ensureParentalControlsPermission(); |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 1397 | final int callingUid = Binder.getCallingUid(); |
| 1398 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1399 | userId, "unblockContent"); |
| 1400 | final long identity = Binder.clearCallingIdentity(); |
| 1401 | try { |
| 1402 | synchronized (mLock) { |
| 1403 | try { |
| 1404 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 1405 | .unblockContent(unblockedRating); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1406 | } catch (RemoteException | SessionNotFoundException e) { |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 1407 | Slog.e(TAG, "error in unblockContent", e); |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 1408 | } |
| 1409 | } |
| 1410 | } finally { |
| 1411 | Binder.restoreCallingIdentity(identity); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | @Override |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 1416 | public void setCaptionEnabled(IBinder sessionToken, boolean enabled, int userId) { |
| 1417 | final int callingUid = Binder.getCallingUid(); |
| 1418 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1419 | userId, "setCaptionEnabled"); |
| 1420 | final long identity = Binder.clearCallingIdentity(); |
| 1421 | try { |
| 1422 | synchronized (mLock) { |
| 1423 | try { |
| 1424 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
| 1425 | .setCaptionEnabled(enabled); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1426 | } catch (RemoteException | SessionNotFoundException e) { |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 1427 | Slog.e(TAG, "error in setCaptionEnabled", e); |
| 1428 | } |
| 1429 | } |
| 1430 | } finally { |
| 1431 | Binder.restoreCallingIdentity(identity); |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | @Override |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 1436 | public void selectTrack(IBinder sessionToken, int type, String trackId, int userId) { |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 1437 | final int callingUid = Binder.getCallingUid(); |
| 1438 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1439 | userId, "selectTrack"); |
| 1440 | final long identity = Binder.clearCallingIdentity(); |
| 1441 | try { |
| 1442 | synchronized (mLock) { |
| 1443 | try { |
| 1444 | getSessionLocked(sessionToken, callingUid, resolvedUserId).selectTrack( |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 1445 | type, trackId); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1446 | } catch (RemoteException | SessionNotFoundException e) { |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 1447 | Slog.e(TAG, "error in selectTrack", e); |
| 1448 | } |
| 1449 | } |
| 1450 | } finally { |
| 1451 | Binder.restoreCallingIdentity(identity); |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | @Override |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 1456 | public void sendAppPrivateCommand(IBinder sessionToken, String command, Bundle data, |
| 1457 | int userId) { |
| 1458 | final int callingUid = Binder.getCallingUid(); |
| 1459 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1460 | userId, "sendAppPrivateCommand"); |
| 1461 | final long identity = Binder.clearCallingIdentity(); |
| 1462 | try { |
| 1463 | synchronized (mLock) { |
| 1464 | try { |
| 1465 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
| 1466 | .appPrivateCommand(command, data); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1467 | } catch (RemoteException | SessionNotFoundException e) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 1468 | Slog.e(TAG, "error in appPrivateCommand", e); |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | } finally { |
| 1472 | Binder.restoreCallingIdentity(identity); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | @Override |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1477 | public void createOverlayView(IBinder sessionToken, IBinder windowToken, Rect frame, |
| 1478 | int userId) { |
| 1479 | final int callingUid = Binder.getCallingUid(); |
| 1480 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1481 | userId, "createOverlayView"); |
| 1482 | final long identity = Binder.clearCallingIdentity(); |
| 1483 | try { |
| 1484 | synchronized (mLock) { |
| 1485 | try { |
| 1486 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
| 1487 | .createOverlayView(windowToken, frame); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1488 | } catch (RemoteException | SessionNotFoundException e) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1489 | Slog.e(TAG, "error in createOverlayView", e); |
| 1490 | } |
| 1491 | } |
| 1492 | } finally { |
| 1493 | Binder.restoreCallingIdentity(identity); |
| 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | @Override |
| 1498 | public void relayoutOverlayView(IBinder sessionToken, Rect frame, int userId) { |
| 1499 | final int callingUid = Binder.getCallingUid(); |
| 1500 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1501 | userId, "relayoutOverlayView"); |
| 1502 | final long identity = Binder.clearCallingIdentity(); |
| 1503 | try { |
| 1504 | synchronized (mLock) { |
| 1505 | try { |
| 1506 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
| 1507 | .relayoutOverlayView(frame); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1508 | } catch (RemoteException | SessionNotFoundException e) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1509 | Slog.e(TAG, "error in relayoutOverlayView", e); |
| 1510 | } |
| 1511 | } |
| 1512 | } finally { |
| 1513 | Binder.restoreCallingIdentity(identity); |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | @Override |
| 1518 | public void removeOverlayView(IBinder sessionToken, int userId) { |
| 1519 | final int callingUid = Binder.getCallingUid(); |
| 1520 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1521 | userId, "removeOverlayView"); |
| 1522 | final long identity = Binder.clearCallingIdentity(); |
| 1523 | try { |
| 1524 | synchronized (mLock) { |
| 1525 | try { |
| 1526 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
| 1527 | .removeOverlayView(); |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 1528 | } catch (RemoteException | SessionNotFoundException e) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1529 | Slog.e(TAG, "error in removeOverlayView", e); |
| 1530 | } |
| 1531 | } |
| 1532 | } finally { |
| 1533 | Binder.restoreCallingIdentity(identity); |
| 1534 | } |
| 1535 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1536 | |
| 1537 | @Override |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 1538 | public void timeShiftPlay(IBinder sessionToken, final Uri recordedProgramUri, int userId) { |
| 1539 | final int callingUid = Binder.getCallingUid(); |
| 1540 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1541 | userId, "timeShiftPlay"); |
| 1542 | final long identity = Binder.clearCallingIdentity(); |
| 1543 | try { |
| 1544 | synchronized (mLock) { |
| 1545 | try { |
| 1546 | getSessionLocked(sessionToken, callingUid, resolvedUserId).timeShiftPlay( |
| 1547 | recordedProgramUri); |
| 1548 | } catch (RemoteException | SessionNotFoundException e) { |
| 1549 | Slog.e(TAG, "error in timeShiftPlay", e); |
| 1550 | } |
| 1551 | } |
| 1552 | } finally { |
| 1553 | Binder.restoreCallingIdentity(identity); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | @Override |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1558 | public void timeShiftPause(IBinder sessionToken, int userId) { |
| 1559 | final int callingUid = Binder.getCallingUid(); |
| 1560 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1561 | userId, "timeShiftPause"); |
| 1562 | final long identity = Binder.clearCallingIdentity(); |
| 1563 | try { |
| 1564 | synchronized (mLock) { |
| 1565 | try { |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 1566 | getSessionLocked(sessionToken, callingUid, resolvedUserId).timeShiftPause(); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1567 | } catch (RemoteException | SessionNotFoundException e) { |
| 1568 | Slog.e(TAG, "error in timeShiftPause", e); |
| 1569 | } |
| 1570 | } |
| 1571 | } finally { |
| 1572 | Binder.restoreCallingIdentity(identity); |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | @Override |
| 1577 | public void timeShiftResume(IBinder sessionToken, int userId) { |
| 1578 | final int callingUid = Binder.getCallingUid(); |
| 1579 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1580 | userId, "timeShiftResume"); |
| 1581 | final long identity = Binder.clearCallingIdentity(); |
| 1582 | try { |
| 1583 | synchronized (mLock) { |
| 1584 | try { |
| 1585 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
| 1586 | .timeShiftResume(); |
| 1587 | } catch (RemoteException | SessionNotFoundException e) { |
| 1588 | Slog.e(TAG, "error in timeShiftResume", e); |
| 1589 | } |
| 1590 | } |
| 1591 | } finally { |
| 1592 | Binder.restoreCallingIdentity(identity); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | @Override |
| 1597 | public void timeShiftSeekTo(IBinder sessionToken, long timeMs, int userId) { |
| 1598 | final int callingUid = Binder.getCallingUid(); |
| 1599 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1600 | userId, "timeShiftSeekTo"); |
| 1601 | final long identity = Binder.clearCallingIdentity(); |
| 1602 | try { |
| 1603 | synchronized (mLock) { |
| 1604 | try { |
| 1605 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
| 1606 | .timeShiftSeekTo(timeMs); |
| 1607 | } catch (RemoteException | SessionNotFoundException e) { |
| 1608 | Slog.e(TAG, "error in timeShiftSeekTo", e); |
| 1609 | } |
| 1610 | } |
| 1611 | } finally { |
| 1612 | Binder.restoreCallingIdentity(identity); |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | @Override |
Jae Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 1617 | public void timeShiftSetPlaybackParams(IBinder sessionToken, PlaybackParams params, |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1618 | int userId) { |
| 1619 | final int callingUid = Binder.getCallingUid(); |
| 1620 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
Jae Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 1621 | userId, "timeShiftSetPlaybackParams"); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1622 | final long identity = Binder.clearCallingIdentity(); |
| 1623 | try { |
| 1624 | synchronized (mLock) { |
| 1625 | try { |
| 1626 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
Jae Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 1627 | .timeShiftSetPlaybackParams(params); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1628 | } catch (RemoteException | SessionNotFoundException e) { |
Jae Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 1629 | Slog.e(TAG, "error in timeShiftSetPlaybackParams", e); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | } finally { |
| 1633 | Binder.restoreCallingIdentity(identity); |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | @Override |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 1638 | public void timeShiftEnablePositionTracking(IBinder sessionToken, boolean enable, |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1639 | int userId) { |
| 1640 | final int callingUid = Binder.getCallingUid(); |
| 1641 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 1642 | userId, "timeShiftEnablePositionTracking"); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1643 | final long identity = Binder.clearCallingIdentity(); |
| 1644 | try { |
| 1645 | synchronized (mLock) { |
| 1646 | try { |
| 1647 | getSessionLocked(sessionToken, callingUid, resolvedUserId) |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 1648 | .timeShiftEnablePositionTracking(enable); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1649 | } catch (RemoteException | SessionNotFoundException e) { |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 1650 | Slog.e(TAG, "error in timeShiftEnablePositionTracking", e); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1651 | } |
| 1652 | } |
| 1653 | } finally { |
| 1654 | Binder.restoreCallingIdentity(identity); |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | @Override |
Dongwon Kang | 0cb5244 | 2016-04-22 11:00:03 -0700 | [diff] [blame] | 1659 | public void startRecording(IBinder sessionToken, @Nullable Uri programUri, int userId) { |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 1660 | final int callingUid = Binder.getCallingUid(); |
| 1661 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1662 | userId, "startRecording"); |
| 1663 | final long identity = Binder.clearCallingIdentity(); |
| 1664 | try { |
| 1665 | synchronized (mLock) { |
| 1666 | try { |
Jae Seo | 4eee6a7 | 2016-02-06 11:11:35 +0900 | [diff] [blame] | 1667 | getSessionLocked(sessionToken, callingUid, resolvedUserId).startRecording( |
Dongwon Kang | 0cb5244 | 2016-04-22 11:00:03 -0700 | [diff] [blame] | 1668 | programUri); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 1669 | } catch (RemoteException | SessionNotFoundException e) { |
| 1670 | Slog.e(TAG, "error in startRecording", e); |
| 1671 | } |
| 1672 | } |
| 1673 | } finally { |
| 1674 | Binder.restoreCallingIdentity(identity); |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | @Override |
| 1679 | public void stopRecording(IBinder sessionToken, int userId) { |
| 1680 | final int callingUid = Binder.getCallingUid(); |
| 1681 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1682 | userId, "stopRecording"); |
| 1683 | final long identity = Binder.clearCallingIdentity(); |
| 1684 | try { |
| 1685 | synchronized (mLock) { |
| 1686 | try { |
| 1687 | getSessionLocked(sessionToken, callingUid, resolvedUserId).stopRecording(); |
| 1688 | } catch (RemoteException | SessionNotFoundException e) { |
| 1689 | Slog.e(TAG, "error in stopRecording", e); |
| 1690 | } |
| 1691 | } |
| 1692 | } finally { |
| 1693 | Binder.restoreCallingIdentity(identity); |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | @Override |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1698 | public List<TvInputHardwareInfo> getHardwareList() throws RemoteException { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1699 | if (mContext.checkCallingPermission(android.Manifest.permission.TV_INPUT_HARDWARE) |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1700 | != PackageManager.PERMISSION_GRANTED) { |
| 1701 | return null; |
| 1702 | } |
| 1703 | |
| 1704 | final long identity = Binder.clearCallingIdentity(); |
| 1705 | try { |
| 1706 | return mTvInputHardwareManager.getHardwareList(); |
| 1707 | } finally { |
| 1708 | Binder.restoreCallingIdentity(identity); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | @Override |
| 1713 | public ITvInputHardware acquireTvInputHardware(int deviceId, |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1714 | ITvInputHardwareCallback callback, TvInputInfo info, int userId) |
| 1715 | throws RemoteException { |
| 1716 | if (mContext.checkCallingPermission(android.Manifest.permission.TV_INPUT_HARDWARE) |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1717 | != PackageManager.PERMISSION_GRANTED) { |
| 1718 | return null; |
| 1719 | } |
| 1720 | |
| 1721 | final long identity = Binder.clearCallingIdentity(); |
| 1722 | final int callingUid = Binder.getCallingUid(); |
| 1723 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1724 | userId, "acquireTvInputHardware"); |
| 1725 | try { |
| 1726 | return mTvInputHardwareManager.acquireHardware( |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1727 | deviceId, callback, info, callingUid, resolvedUserId); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1728 | } finally { |
| 1729 | Binder.restoreCallingIdentity(identity); |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | @Override |
| 1734 | public void releaseTvInputHardware(int deviceId, ITvInputHardware hardware, int userId) |
| 1735 | throws RemoteException { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 1736 | if (mContext.checkCallingPermission(android.Manifest.permission.TV_INPUT_HARDWARE) |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 1737 | != PackageManager.PERMISSION_GRANTED) { |
| 1738 | return; |
| 1739 | } |
| 1740 | |
| 1741 | final long identity = Binder.clearCallingIdentity(); |
| 1742 | final int callingUid = Binder.getCallingUid(); |
| 1743 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1744 | userId, "releaseTvInputHardware"); |
| 1745 | try { |
| 1746 | mTvInputHardwareManager.releaseHardware( |
| 1747 | deviceId, hardware, callingUid, resolvedUserId); |
| 1748 | } finally { |
| 1749 | Binder.restoreCallingIdentity(identity); |
| 1750 | } |
| 1751 | } |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 1752 | |
| 1753 | @Override |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1754 | public List<DvbDeviceInfo> getDvbDeviceList() throws RemoteException { |
| 1755 | if (mContext.checkCallingPermission(android.Manifest.permission.DVB_DEVICE) |
| 1756 | != PackageManager.PERMISSION_GRANTED) { |
| 1757 | throw new SecurityException("Requires DVB_DEVICE permission"); |
| 1758 | } |
| 1759 | |
| 1760 | final long identity = Binder.clearCallingIdentity(); |
| 1761 | try { |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 1762 | // Pattern1: /dev/dvb%d.frontend%d |
| 1763 | ArrayList<DvbDeviceInfo> deviceInfosFromPattern1 = new ArrayList<>(); |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1764 | File devDirectory = new File("/dev"); |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 1765 | boolean dvbDirectoryFound = false; |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1766 | for (String fileName : devDirectory.list()) { |
| 1767 | Matcher matcher = sFrontEndDevicePattern.matcher(fileName); |
| 1768 | if (matcher.find()) { |
| 1769 | int adapterId = Integer.parseInt(matcher.group(1)); |
| 1770 | int deviceId = Integer.parseInt(matcher.group(2)); |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 1771 | deviceInfosFromPattern1.add(new DvbDeviceInfo(adapterId, deviceId)); |
| 1772 | } |
| 1773 | if (TextUtils.equals("dvb", fileName)) { |
| 1774 | dvbDirectoryFound = true; |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1775 | } |
| 1776 | } |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 1777 | if (!dvbDirectoryFound) { |
| 1778 | return Collections.unmodifiableList(deviceInfosFromPattern1); |
| 1779 | } |
| 1780 | File dvbDirectory = new File(DVB_DIRECTORY); |
| 1781 | // Pattern2: /dev/dvb/adapter%d/frontend%d |
| 1782 | ArrayList<DvbDeviceInfo> deviceInfosFromPattern2 = new ArrayList<>(); |
| 1783 | for (String fileNameInDvb : dvbDirectory.list()) { |
| 1784 | Matcher adapterMatcher = sAdapterDirPattern.matcher(fileNameInDvb); |
| 1785 | if (adapterMatcher.find()) { |
| 1786 | int adapterId = Integer.parseInt(adapterMatcher.group(1)); |
| 1787 | File adapterDirectory = new File(DVB_DIRECTORY + "/" + fileNameInDvb); |
| 1788 | for (String fileNameInAdapter : adapterDirectory.list()) { |
| 1789 | Matcher frontendMatcher = sFrontEndInAdapterDirPattern.matcher( |
| 1790 | fileNameInAdapter); |
| 1791 | if (frontendMatcher.find()) { |
| 1792 | int deviceId = Integer.parseInt(frontendMatcher.group(1)); |
| 1793 | deviceInfosFromPattern2.add( |
| 1794 | new DvbDeviceInfo(adapterId, deviceId)); |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | } |
| 1799 | return deviceInfosFromPattern2.isEmpty() |
| 1800 | ? Collections.unmodifiableList(deviceInfosFromPattern1) |
| 1801 | : Collections.unmodifiableList(deviceInfosFromPattern2); |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1802 | } finally { |
| 1803 | Binder.restoreCallingIdentity(identity); |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | @Override |
| 1808 | public ParcelFileDescriptor openDvbDevice(DvbDeviceInfo info, int device) |
| 1809 | throws RemoteException { |
| 1810 | if (mContext.checkCallingPermission(android.Manifest.permission.DVB_DEVICE) |
| 1811 | != PackageManager.PERMISSION_GRANTED) { |
| 1812 | throw new SecurityException("Requires DVB_DEVICE permission"); |
| 1813 | } |
| 1814 | |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 1815 | File devDirectory = new File("/dev"); |
| 1816 | boolean dvbDeviceFound = false; |
| 1817 | for (String fileName : devDirectory.list()) { |
| 1818 | if (TextUtils.equals("dvb", fileName)) { |
| 1819 | File dvbDirectory = new File(DVB_DIRECTORY); |
| 1820 | for (String fileNameInDvb : dvbDirectory.list()) { |
| 1821 | Matcher adapterMatcher = sAdapterDirPattern.matcher(fileNameInDvb); |
| 1822 | if (adapterMatcher.find()) { |
| 1823 | File adapterDirectory = new File(DVB_DIRECTORY + "/" + fileNameInDvb); |
| 1824 | for (String fileNameInAdapter : adapterDirectory.list()) { |
| 1825 | Matcher frontendMatcher = sFrontEndInAdapterDirPattern.matcher( |
| 1826 | fileNameInAdapter); |
| 1827 | if (frontendMatcher.find()) { |
| 1828 | dvbDeviceFound = true; |
| 1829 | break; |
| 1830 | } |
| 1831 | } |
| 1832 | } |
| 1833 | if (dvbDeviceFound) { |
| 1834 | break; |
| 1835 | } |
| 1836 | } |
| 1837 | } |
| 1838 | if (dvbDeviceFound) { |
| 1839 | break; |
| 1840 | } |
| 1841 | } |
| 1842 | |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1843 | final long identity = Binder.clearCallingIdentity(); |
| 1844 | try { |
| 1845 | String deviceFileName; |
| 1846 | switch (device) { |
| 1847 | case TvInputManager.DVB_DEVICE_DEMUX: |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 1848 | deviceFileName = String.format(dvbDeviceFound |
| 1849 | ? "/dev/dvb/adapter%d/demux%d" : "/dev/dvb%d.demux%d", |
| 1850 | info.getAdapterId(), info.getDeviceId()); |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1851 | break; |
| 1852 | case TvInputManager.DVB_DEVICE_DVR: |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 1853 | deviceFileName = String.format(dvbDeviceFound |
| 1854 | ? "/dev/dvb/adapter%d/dvr%d" : "/dev/dvb%d.dvr%d", |
| 1855 | info.getAdapterId(), info.getDeviceId()); |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1856 | break; |
| 1857 | case TvInputManager.DVB_DEVICE_FRONTEND: |
Jiabin | ef1659f | 2016-11-18 10:50:15 +0900 | [diff] [blame] | 1858 | deviceFileName = String.format(dvbDeviceFound |
| 1859 | ? "/dev/dvb/adapter%d/frontend%d" : "/dev/dvb%d.frontend%d", |
| 1860 | info.getAdapterId(), info.getDeviceId()); |
Jaesung Chung | 58739e7 | 2015-04-24 19:39:59 +0900 | [diff] [blame] | 1861 | break; |
| 1862 | default: |
| 1863 | throw new IllegalArgumentException("Invalid DVB device: " + device); |
| 1864 | } |
| 1865 | try { |
| 1866 | // The DVB frontend device only needs to be opened in read/write mode, which |
| 1867 | // allows performing tuning operations. The DVB demux and DVR device are enough |
| 1868 | // to be opened in read only mode. |
| 1869 | return ParcelFileDescriptor.open(new File(deviceFileName), |
| 1870 | TvInputManager.DVB_DEVICE_FRONTEND == device |
| 1871 | ? ParcelFileDescriptor.MODE_READ_WRITE |
| 1872 | : ParcelFileDescriptor.MODE_READ_ONLY); |
| 1873 | } catch (FileNotFoundException e) { |
| 1874 | return null; |
| 1875 | } |
| 1876 | } finally { |
| 1877 | Binder.restoreCallingIdentity(identity); |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | @Override |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 1882 | public List<TvStreamConfig> getAvailableTvStreamConfigList(String inputId, int userId) |
| 1883 | throws RemoteException { |
Shubang | dd3ec0b | 2017-06-23 13:54:10 -0700 | [diff] [blame] | 1884 | ensureCaptureTvInputPermission(); |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 1885 | |
| 1886 | final long identity = Binder.clearCallingIdentity(); |
| 1887 | final int callingUid = Binder.getCallingUid(); |
| 1888 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1889 | userId, "getAvailableTvStreamConfigList"); |
| 1890 | try { |
| 1891 | return mTvInputHardwareManager.getAvailableTvStreamConfigList( |
| 1892 | inputId, callingUid, resolvedUserId); |
| 1893 | } finally { |
| 1894 | Binder.restoreCallingIdentity(identity); |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | @Override |
| 1899 | public boolean captureFrame(String inputId, Surface surface, TvStreamConfig config, |
| 1900 | int userId) |
| 1901 | throws RemoteException { |
Shubang | dd3ec0b | 2017-06-23 13:54:10 -0700 | [diff] [blame] | 1902 | ensureCaptureTvInputPermission(); |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 1903 | |
| 1904 | final long identity = Binder.clearCallingIdentity(); |
| 1905 | final int callingUid = Binder.getCallingUid(); |
| 1906 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1907 | userId, "captureFrame"); |
| 1908 | try { |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1909 | String hardwareInputId = null; |
Terry Heo | 79124a7 | 2014-07-21 15:17:17 +0900 | [diff] [blame] | 1910 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1911 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1912 | if (userState.inputMap.get(inputId) == null) { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 1913 | Slog.e(TAG, "input not found for " + inputId); |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1914 | return false; |
| 1915 | } |
| 1916 | for (SessionState sessionState : userState.sessionStateMap.values()) { |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 1917 | if (sessionState.inputId.equals(inputId) |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1918 | && sessionState.hardwareSessionToken != null) { |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1919 | hardwareInputId = userState.sessionStateMap.get( |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 1920 | sessionState.hardwareSessionToken).inputId; |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1921 | break; |
| 1922 | } |
| 1923 | } |
Terry Heo | 79124a7 | 2014-07-21 15:17:17 +0900 | [diff] [blame] | 1924 | } |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 1925 | return mTvInputHardwareManager.captureFrame( |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 1926 | (hardwareInputId != null) ? hardwareInputId : inputId, |
Terry Heo | 79124a7 | 2014-07-21 15:17:17 +0900 | [diff] [blame] | 1927 | surface, config, callingUid, resolvedUserId); |
Terry Heo | c086a3d | 2014-06-18 14:26:44 +0900 | [diff] [blame] | 1928 | } finally { |
| 1929 | Binder.restoreCallingIdentity(identity); |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | @Override |
Terry Heo | df9f0a3 | 2014-08-06 13:53:33 +0900 | [diff] [blame] | 1934 | public boolean isSingleSessionActive(int userId) throws RemoteException { |
Shubang | dd3ec0b | 2017-06-23 13:54:10 -0700 | [diff] [blame] | 1935 | ensureCaptureTvInputPermission(); |
Terry Heo | df9f0a3 | 2014-08-06 13:53:33 +0900 | [diff] [blame] | 1936 | final long identity = Binder.clearCallingIdentity(); |
| 1937 | final int callingUid = Binder.getCallingUid(); |
| 1938 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1939 | userId, "isSingleSessionActive"); |
| 1940 | try { |
| 1941 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 1942 | UserState userState = getOrCreateUserStateLocked(resolvedUserId); |
Terry Heo | df9f0a3 | 2014-08-06 13:53:33 +0900 | [diff] [blame] | 1943 | if (userState.sessionStateMap.size() == 1) { |
| 1944 | return true; |
Jae Seo | 93ff14b | 2015-06-21 14:08:54 -0700 | [diff] [blame] | 1945 | } else if (userState.sessionStateMap.size() == 2) { |
Terry Heo | df9f0a3 | 2014-08-06 13:53:33 +0900 | [diff] [blame] | 1946 | SessionState[] sessionStates = userState.sessionStateMap.values().toArray( |
Jae Seo | 93ff14b | 2015-06-21 14:08:54 -0700 | [diff] [blame] | 1947 | new SessionState[2]); |
Terry Heo | df9f0a3 | 2014-08-06 13:53:33 +0900 | [diff] [blame] | 1948 | // Check if there is a wrapper input. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 1949 | if (sessionStates[0].hardwareSessionToken != null |
| 1950 | || sessionStates[1].hardwareSessionToken != null) { |
Terry Heo | df9f0a3 | 2014-08-06 13:53:33 +0900 | [diff] [blame] | 1951 | return true; |
| 1952 | } |
| 1953 | } |
| 1954 | return false; |
| 1955 | } |
| 1956 | } finally { |
| 1957 | Binder.restoreCallingIdentity(identity); |
| 1958 | } |
| 1959 | } |
| 1960 | |
Shubang | dd3ec0b | 2017-06-23 13:54:10 -0700 | [diff] [blame] | 1961 | private void ensureCaptureTvInputPermission() { |
| 1962 | if (mContext.checkCallingPermission( |
| 1963 | android.Manifest.permission.CAPTURE_TV_INPUT) |
| 1964 | != PackageManager.PERMISSION_GRANTED) { |
| 1965 | throw new SecurityException("Requires CAPTURE_TV_INPUT permission"); |
| 1966 | } |
| 1967 | } |
| 1968 | |
Terry Heo | df9f0a3 | 2014-08-06 13:53:33 +0900 | [diff] [blame] | 1969 | @Override |
Dongwon Kang | 2e7f5ce | 2017-04-05 18:33:50 -0700 | [diff] [blame] | 1970 | public void requestChannelBrowsable(Uri channelUri, int userId) |
| 1971 | throws RemoteException { |
| 1972 | final String callingPackageName = getCallingPackageName(); |
| 1973 | final long identity = Binder.clearCallingIdentity(); |
| 1974 | final int callingUid = Binder.getCallingUid(); |
| 1975 | final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, |
| 1976 | userId, "requestChannelBrowsable"); |
| 1977 | try { |
| 1978 | Intent intent = new Intent(TvContract.ACTION_CHANNEL_BROWSABLE_REQUESTED); |
| 1979 | List<ResolveInfo> list = getContext().getPackageManager() |
| 1980 | .queryBroadcastReceivers(intent, 0); |
| 1981 | if (list != null) { |
| 1982 | for (ResolveInfo info : list) { |
| 1983 | String receiverPackageName = info.activityInfo.packageName; |
| 1984 | intent.putExtra(TvContract.EXTRA_CHANNEL_ID, ContentUris.parseId( |
| 1985 | channelUri)); |
| 1986 | intent.putExtra(TvContract.EXTRA_PACKAGE_NAME, callingPackageName); |
| 1987 | intent.setPackage(receiverPackageName); |
| 1988 | getContext().sendBroadcastAsUser(intent, new UserHandle(resolvedUserId)); |
| 1989 | } |
| 1990 | } |
| 1991 | } finally { |
| 1992 | Binder.restoreCallingIdentity(identity); |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | @Override |
Jae Seo | 0f8fc34 | 2014-07-02 10:47:08 -0700 | [diff] [blame] | 1997 | @SuppressWarnings("resource") |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 1998 | protected void dump(FileDescriptor fd, final PrintWriter writer, String[] args) { |
| 1999 | final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 2000 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2001 | |
| 2002 | synchronized (mLock) { |
| 2003 | pw.println("User Ids (Current user: " + mCurrentUserId + "):"); |
| 2004 | pw.increaseIndent(); |
| 2005 | for (int i = 0; i < mUserStates.size(); i++) { |
| 2006 | int userId = mUserStates.keyAt(i); |
| 2007 | pw.println(Integer.valueOf(userId)); |
| 2008 | } |
| 2009 | pw.decreaseIndent(); |
| 2010 | |
| 2011 | for (int i = 0; i < mUserStates.size(); i++) { |
| 2012 | int userId = mUserStates.keyAt(i); |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 2013 | UserState userState = getOrCreateUserStateLocked(userId); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2014 | pw.println("UserState (" + userId + "):"); |
| 2015 | pw.increaseIndent(); |
| 2016 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2017 | pw.println("inputMap: inputId -> TvInputState"); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2018 | pw.increaseIndent(); |
Jaewan Kim | 8e6b51b | 2014-07-15 13:01:57 +0900 | [diff] [blame] | 2019 | for (Map.Entry<String, TvInputState> entry: userState.inputMap.entrySet()) { |
| 2020 | pw.println(entry.getKey() + ": " + entry.getValue()); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2021 | } |
| 2022 | pw.decreaseIndent(); |
| 2023 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2024 | pw.println("packageSet:"); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2025 | pw.increaseIndent(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2026 | for (String packageName : userState.packageSet) { |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2027 | pw.println(packageName); |
| 2028 | } |
| 2029 | pw.decreaseIndent(); |
| 2030 | |
| 2031 | pw.println("clientStateMap: ITvInputClient -> ClientState"); |
| 2032 | pw.increaseIndent(); |
| 2033 | for (Map.Entry<IBinder, ClientState> entry : |
| 2034 | userState.clientStateMap.entrySet()) { |
| 2035 | ClientState client = entry.getValue(); |
| 2036 | pw.println(entry.getKey() + ": " + client); |
| 2037 | |
| 2038 | pw.increaseIndent(); |
| 2039 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2040 | pw.println("sessionTokens:"); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2041 | pw.increaseIndent(); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2042 | for (IBinder token : client.sessionTokens) { |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2043 | pw.println("" + token); |
| 2044 | } |
| 2045 | pw.decreaseIndent(); |
| 2046 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2047 | pw.println("clientTokens: " + client.clientToken); |
| 2048 | pw.println("userId: " + client.userId); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2049 | |
| 2050 | pw.decreaseIndent(); |
| 2051 | } |
| 2052 | pw.decreaseIndent(); |
| 2053 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2054 | pw.println("serviceStateMap: ComponentName -> ServiceState"); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2055 | pw.increaseIndent(); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2056 | for (Map.Entry<ComponentName, ServiceState> entry : |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2057 | userState.serviceStateMap.entrySet()) { |
| 2058 | ServiceState service = entry.getValue(); |
| 2059 | pw.println(entry.getKey() + ": " + service); |
| 2060 | |
| 2061 | pw.increaseIndent(); |
| 2062 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2063 | pw.println("sessionTokens:"); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2064 | pw.increaseIndent(); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2065 | for (IBinder token : service.sessionTokens) { |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2066 | pw.println("" + token); |
| 2067 | } |
| 2068 | pw.decreaseIndent(); |
| 2069 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2070 | pw.println("service: " + service.service); |
| 2071 | pw.println("callback: " + service.callback); |
| 2072 | pw.println("bound: " + service.bound); |
| 2073 | pw.println("reconnecting: " + service.reconnecting); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2074 | |
| 2075 | pw.decreaseIndent(); |
| 2076 | } |
| 2077 | pw.decreaseIndent(); |
| 2078 | |
| 2079 | pw.println("sessionStateMap: ITvInputSession -> SessionState"); |
| 2080 | pw.increaseIndent(); |
| 2081 | for (Map.Entry<IBinder, SessionState> entry : |
| 2082 | userState.sessionStateMap.entrySet()) { |
| 2083 | SessionState session = entry.getValue(); |
| 2084 | pw.println(entry.getKey() + ": " + session); |
| 2085 | |
| 2086 | pw.increaseIndent(); |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 2087 | pw.println("inputId: " + session.inputId); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2088 | pw.println("client: " + session.client); |
| 2089 | pw.println("seq: " + session.seq); |
| 2090 | pw.println("callingUid: " + session.callingUid); |
| 2091 | pw.println("userId: " + session.userId); |
| 2092 | pw.println("sessionToken: " + session.sessionToken); |
| 2093 | pw.println("session: " + session.session); |
| 2094 | pw.println("logUri: " + session.logUri); |
| 2095 | pw.println("hardwareSessionToken: " + session.hardwareSessionToken); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2096 | pw.decreaseIndent(); |
| 2097 | } |
| 2098 | pw.decreaseIndent(); |
| 2099 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2100 | pw.println("callbackSet:"); |
| 2101 | pw.increaseIndent(); |
| 2102 | for (ITvInputManagerCallback callback : userState.callbackSet) { |
| 2103 | pw.println(callback.toString()); |
| 2104 | } |
| 2105 | pw.decreaseIndent(); |
| 2106 | |
Ji-Hwan Lee | 956afc2 | 2014-07-26 11:31:39 +0900 | [diff] [blame] | 2107 | pw.println("mainSessionToken: " + userState.mainSessionToken); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2108 | pw.decreaseIndent(); |
| 2109 | } |
| 2110 | } |
yangren | 8d718e1 | 2016-02-15 17:02:49 +0900 | [diff] [blame] | 2111 | mTvInputHardwareManager.dump(fd, writer, args); |
Jaewan Kim | e14c3f4 | 2014-06-27 13:47:48 +0900 | [diff] [blame] | 2112 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2113 | } |
| 2114 | |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2115 | private static final class UserState { |
| 2116 | // A mapping from the TV input id to its TvInputState. |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2117 | private Map<String, TvInputState> inputMap = new HashMap<>(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2118 | |
| 2119 | // A set of all TV input packages. |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2120 | private final Set<String> packageSet = new HashSet<>(); |
Jae Seo | 5c80ad2 | 2014-06-12 19:52:58 -0700 | [diff] [blame] | 2121 | |
Jae Seo | 9c165d6 | 2014-08-25 14:39:26 -0700 | [diff] [blame] | 2122 | // A list of all TV content rating systems defined. |
| 2123 | private final List<TvContentRatingSystemInfo> |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2124 | contentRatingSystemList = new ArrayList<>(); |
Sungsoo Lim | 5c5b83f | 2014-07-29 11:48:36 +0900 | [diff] [blame] | 2125 | |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2126 | // A mapping from the token of a client to its state. |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2127 | private final Map<IBinder, ClientState> clientStateMap = new HashMap<>(); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2128 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2129 | // A mapping from the name of a TV input service to its state. |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2130 | private final Map<ComponentName, ServiceState> serviceStateMap = new HashMap<>(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2131 | |
| 2132 | // A mapping from the token of a TV input session to its state. |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2133 | private final Map<IBinder, SessionState> sessionStateMap = new HashMap<>(); |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2134 | |
| 2135 | // A set of callbacks. |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2136 | private final Set<ITvInputManagerCallback> callbackSet = new HashSet<>(); |
Terry Heo | 79124a7 | 2014-07-21 15:17:17 +0900 | [diff] [blame] | 2137 | |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 2138 | // The token of a "main" TV input session. |
| 2139 | private IBinder mainSessionToken = null; |
Jae Seo | 783645e | 2014-07-28 17:30:50 +0900 | [diff] [blame] | 2140 | |
| 2141 | // Persistent data store for all internal settings maintained by the TV input manager |
| 2142 | // service. |
| 2143 | private final PersistentDataStore persistentDataStore; |
| 2144 | |
| 2145 | private UserState(Context context, int userId) { |
| 2146 | persistentDataStore = new PersistentDataStore(context, userId); |
| 2147 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2150 | private final class ClientState implements IBinder.DeathRecipient { |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2151 | private final List<IBinder> sessionTokens = new ArrayList<>(); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2152 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2153 | private IBinder clientToken; |
| 2154 | private final int userId; |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2155 | |
| 2156 | ClientState(IBinder clientToken, int userId) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2157 | this.clientToken = clientToken; |
| 2158 | this.userId = userId; |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | public boolean isEmpty() { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2162 | return sessionTokens.isEmpty(); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | @Override |
| 2166 | public void binderDied() { |
| 2167 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 2168 | UserState userState = getOrCreateUserStateLocked(userId); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2169 | // DO NOT remove the client state of clientStateMap in this method. It will be |
Ji-Hwan Lee | a65118e | 2014-07-24 16:30:02 +0900 | [diff] [blame] | 2170 | // removed in releaseSessionLocked(). |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2171 | ClientState clientState = userState.clientStateMap.get(clientToken); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2172 | if (clientState != null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2173 | while (clientState.sessionTokens.size() > 0) { |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2174 | releaseSessionLocked( |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2175 | clientState.sessionTokens.get(0), Process.SYSTEM_UID, userId); |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2176 | } |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2177 | } |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2178 | clientToken = null; |
Sungsoo Lim | 72ad7bf | 2014-05-14 09:21:08 +0900 | [diff] [blame] | 2179 | } |
| 2180 | } |
| 2181 | } |
| 2182 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2183 | private final class ServiceState { |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2184 | private final List<IBinder> sessionTokens = new ArrayList<>(); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2185 | private final ServiceConnection connection; |
| 2186 | private final ComponentName component; |
| 2187 | private final boolean isHardware; |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 2188 | private final Map<String, TvInputInfo> hardwareInputMap = new HashMap<>(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2189 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2190 | private ITvInputService service; |
| 2191 | private ServiceCallback callback; |
| 2192 | private boolean bound; |
| 2193 | private boolean reconnecting; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2194 | |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2195 | private ServiceState(ComponentName component, int userId) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2196 | this.component = component; |
| 2197 | this.connection = new InputServiceConnection(component, userId); |
| 2198 | this.isHardware = hasHardwarePermission(mContext.getPackageManager(), component); |
| 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | private static final class TvInputState { |
| 2203 | // A TvInputInfo object which represents the TV input. |
| 2204 | private TvInputInfo info; |
| 2205 | |
| 2206 | // The state of TV input. Connected by default. |
| 2207 | private int state = INPUT_STATE_CONNECTED; |
| 2208 | |
| 2209 | @Override |
| 2210 | public String toString() { |
| 2211 | return "info: " + info + "; state: " + state; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2212 | } |
| 2213 | } |
| 2214 | |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 2215 | private final class SessionState implements IBinder.DeathRecipient { |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 2216 | private final String inputId; |
| 2217 | private final ComponentName componentName; |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2218 | private final boolean isRecordingSession; |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2219 | private final ITvInputClient client; |
| 2220 | private final int seq; |
| 2221 | private final int callingUid; |
| 2222 | private final int userId; |
| 2223 | private final IBinder sessionToken; |
| 2224 | private ITvInputSession session; |
| 2225 | private Uri logUri; |
Dongwon Kang | bd2fa2c | 2014-07-25 19:52:08 +0900 | [diff] [blame] | 2226 | // Not null if this session represents an external device connected to a hardware TV input. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2227 | private IBinder hardwareSessionToken; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2228 | |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 2229 | private SessionState(IBinder sessionToken, String inputId, ComponentName componentName, |
| 2230 | boolean isRecordingSession, ITvInputClient client, int seq, int callingUid, |
| 2231 | int userId) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2232 | this.sessionToken = sessionToken; |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 2233 | this.inputId = inputId; |
| 2234 | this.componentName = componentName; |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2235 | this.isRecordingSession = isRecordingSession; |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2236 | this.client = client; |
| 2237 | this.seq = seq; |
| 2238 | this.callingUid = callingUid; |
| 2239 | this.userId = userId; |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | @Override |
| 2243 | public void binderDied() { |
| 2244 | synchronized (mLock) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2245 | session = null; |
shubang | 8049f20 | 2016-04-25 11:21:42 -0700 | [diff] [blame] | 2246 | clearSessionAndNotifyClientLocked(this); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 2247 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | private final class InputServiceConnection implements ServiceConnection { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2252 | private final ComponentName mComponent; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2253 | private final int mUserId; |
| 2254 | |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2255 | private InputServiceConnection(ComponentName component, int userId) { |
| 2256 | mComponent = component; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2257 | mUserId = userId; |
| 2258 | } |
| 2259 | |
| 2260 | @Override |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2261 | public void onServiceConnected(ComponentName component, IBinder service) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2262 | if (DEBUG) { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2263 | Slog.d(TAG, "onServiceConnected(component=" + component + ")"); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2264 | } |
| 2265 | synchronized (mLock) { |
Dongwon Kang | 81e3c3e | 2015-09-11 15:24:25 -0700 | [diff] [blame] | 2266 | UserState userState = mUserStates.get(mUserId); |
| 2267 | if (userState == null) { |
| 2268 | // The user was removed while connecting. |
| 2269 | mContext.unbindService(this); |
| 2270 | return; |
| 2271 | } |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2272 | ServiceState serviceState = userState.serviceStateMap.get(mComponent); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2273 | serviceState.service = ITvInputService.Stub.asInterface(service); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2274 | |
| 2275 | // Register a callback, if we need to. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2276 | if (serviceState.isHardware && serviceState.callback == null) { |
| 2277 | serviceState.callback = new ServiceCallback(mComponent, mUserId); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2278 | try { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2279 | serviceState.service.registerCallback(serviceState.callback); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2280 | } catch (RemoteException e) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 2281 | Slog.e(TAG, "error in registerCallback", e); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | // And create sessions, if any. |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2286 | for (IBinder sessionToken : serviceState.sessionTokens) { |
| 2287 | createSessionInternalLocked(serviceState.service, sessionToken, mUserId); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2288 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2289 | |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2290 | for (TvInputState inputState : userState.inputMap.values()) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2291 | if (inputState.info.getComponent().equals(component) |
Jae Seo | 82fce64 | 2015-04-20 15:37:50 -0700 | [diff] [blame] | 2292 | && inputState.state != INPUT_STATE_CONNECTED) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2293 | notifyInputStateChangedLocked(userState, inputState.info.getId(), |
| 2294 | inputState.state, null); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2295 | } |
| 2296 | } |
| 2297 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2298 | if (serviceState.isHardware) { |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 2299 | serviceState.hardwareInputMap.clear(); |
Jae Seo | c980f43d | 2016-02-09 23:46:58 -0800 | [diff] [blame] | 2300 | for (TvInputHardwareInfo hardware : mTvInputHardwareManager.getHardwareList()) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2301 | try { |
Jae Seo | c980f43d | 2016-02-09 23:46:58 -0800 | [diff] [blame] | 2302 | serviceState.service.notifyHardwareAdded(hardware); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2303 | } catch (RemoteException e) { |
| 2304 | Slog.e(TAG, "error in notifyHardwareAdded", e); |
| 2305 | } |
| 2306 | } |
Jae Seo | c980f43d | 2016-02-09 23:46:58 -0800 | [diff] [blame] | 2307 | for (HdmiDeviceInfo device : mTvInputHardwareManager.getHdmiDeviceList()) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2308 | try { |
Jae Seo | c980f43d | 2016-02-09 23:46:58 -0800 | [diff] [blame] | 2309 | serviceState.service.notifyHdmiDeviceAdded(device); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2310 | } catch (RemoteException e) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 2311 | Slog.e(TAG, "error in notifyHdmiDeviceAdded", e); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2312 | } |
| 2313 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2314 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | @Override |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2319 | public void onServiceDisconnected(ComponentName component) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2320 | if (DEBUG) { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2321 | Slog.d(TAG, "onServiceDisconnected(component=" + component + ")"); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2322 | } |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2323 | if (!mComponent.equals(component)) { |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 2324 | throw new IllegalArgumentException("Mismatched ComponentName: " |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2325 | + mComponent + " (expected), " + component + " (actual)."); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 2326 | } |
| 2327 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 2328 | UserState userState = getOrCreateUserStateLocked(mUserId); |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2329 | ServiceState serviceState = userState.serviceStateMap.get(mComponent); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 2330 | if (serviceState != null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2331 | serviceState.reconnecting = true; |
| 2332 | serviceState.bound = false; |
| 2333 | serviceState.service = null; |
| 2334 | serviceState.callback = null; |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 2335 | |
Dongwon Kang | 426c9a4 | 2014-08-26 17:39:21 +0900 | [diff] [blame] | 2336 | abortPendingCreateSessionRequestsLocked(serviceState, null, mUserId); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 2337 | } |
| 2338 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | private final class ServiceCallback extends ITvInputServiceCallback.Stub { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2343 | private final ComponentName mComponent; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2344 | private final int mUserId; |
| 2345 | |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2346 | ServiceCallback(ComponentName component, int userId) { |
| 2347 | mComponent = component; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2348 | mUserId = userId; |
| 2349 | } |
| 2350 | |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2351 | private void ensureHardwarePermission() { |
| 2352 | if (mContext.checkCallingPermission(android.Manifest.permission.TV_INPUT_HARDWARE) |
| 2353 | != PackageManager.PERMISSION_GRANTED) { |
| 2354 | throw new SecurityException("The caller does not have hardware permission"); |
| 2355 | } |
| 2356 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2357 | |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2358 | private void ensureValidInput(TvInputInfo inputInfo) { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2359 | if (inputInfo.getId() == null || !mComponent.equals(inputInfo.getComponent())) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2360 | throw new IllegalArgumentException("Invalid TvInputInfo"); |
| 2361 | } |
| 2362 | } |
| 2363 | |
Jae Seo | 1abbbcd | 2016-01-28 22:20:41 -0800 | [diff] [blame] | 2364 | private void addHardwareInputLocked(TvInputInfo inputInfo) { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2365 | ServiceState serviceState = getServiceStateLocked(mComponent, mUserId); |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 2366 | serviceState.hardwareInputMap.put(inputInfo.getId(), inputInfo); |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 2367 | buildTvInputListLocked(mUserId, null); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2368 | } |
| 2369 | |
Jae Seo | 1abbbcd | 2016-01-28 22:20:41 -0800 | [diff] [blame] | 2370 | public void addHardwareInput(int deviceId, TvInputInfo inputInfo) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2371 | ensureHardwarePermission(); |
| 2372 | ensureValidInput(inputInfo); |
| 2373 | synchronized (mLock) { |
Jae Seo | 1abbbcd | 2016-01-28 22:20:41 -0800 | [diff] [blame] | 2374 | mTvInputHardwareManager.addHardwareInput(deviceId, inputInfo); |
| 2375 | addHardwareInputLocked(inputInfo); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | |
Jae Seo | 1abbbcd | 2016-01-28 22:20:41 -0800 | [diff] [blame] | 2379 | public void addHdmiInput(int id, TvInputInfo inputInfo) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2380 | ensureHardwarePermission(); |
| 2381 | ensureValidInput(inputInfo); |
| 2382 | synchronized (mLock) { |
Jae Seo | 1abbbcd | 2016-01-28 22:20:41 -0800 | [diff] [blame] | 2383 | mTvInputHardwareManager.addHdmiInput(id, inputInfo); |
| 2384 | addHardwareInputLocked(inputInfo); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | |
Jae Seo | 1abbbcd | 2016-01-28 22:20:41 -0800 | [diff] [blame] | 2388 | public void removeHardwareInput(String inputId) { |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2389 | ensureHardwarePermission(); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2390 | synchronized (mLock) { |
Ji-Hwan Lee | 9e8ade2 | 2014-07-25 20:20:38 +0900 | [diff] [blame] | 2391 | ServiceState serviceState = getServiceStateLocked(mComponent, mUserId); |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 2392 | boolean removed = serviceState.hardwareInputMap.remove(inputId) != null; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2393 | if (removed) { |
Chulwoo Lee | 19ba61a | 2014-09-03 00:59:35 +0900 | [diff] [blame] | 2394 | buildTvInputListLocked(mUserId, null); |
Jae Seo | 1abbbcd | 2016-01-28 22:20:41 -0800 | [diff] [blame] | 2395 | mTvInputHardwareManager.removeHardwareInput(inputId); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2396 | } else { |
Jae Seo | fea8dd4 | 2014-08-26 13:57:41 -0700 | [diff] [blame] | 2397 | Slog.e(TAG, "failed to remove input " + inputId); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2398 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2399 | } |
| 2400 | } |
| 2401 | } |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2402 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2403 | private final class SessionCallback extends ITvInputSessionCallback.Stub { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2404 | private final SessionState mSessionState; |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2405 | private final InputChannel[] mChannels; |
| 2406 | |
| 2407 | SessionCallback(SessionState sessionState, InputChannel[] channels) { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2408 | mSessionState = sessionState; |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2409 | mChannels = channels; |
| 2410 | } |
| 2411 | |
| 2412 | @Override |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2413 | public void onSessionCreated(ITvInputSession session, IBinder hardwareSessionToken) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2414 | if (DEBUG) { |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 2415 | Slog.d(TAG, "onSessionCreated(inputId=" + mSessionState.inputId + ")"); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2416 | } |
| 2417 | synchronized (mLock) { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2418 | mSessionState.session = session; |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2419 | mSessionState.hardwareSessionToken = hardwareSessionToken; |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2420 | if (session != null && addSessionTokenToClientStateLocked(session)) { |
| 2421 | sendSessionTokenToClientLocked(mSessionState.client, |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 2422 | mSessionState.inputId, mSessionState.sessionToken, mChannels[0], |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2423 | mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2424 | } else { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2425 | removeSessionStateLocked(mSessionState.sessionToken, mSessionState.userId); |
| 2426 | sendSessionTokenToClientLocked(mSessionState.client, |
Jae Seo | 2cdb05e | 2016-02-04 22:17:13 +0900 | [diff] [blame] | 2427 | mSessionState.inputId, null, null, mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2428 | } |
| 2429 | mChannels[0].dispose(); |
| 2430 | } |
| 2431 | } |
| 2432 | |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2433 | private boolean addSessionTokenToClientStateLocked(ITvInputSession session) { |
| 2434 | try { |
| 2435 | session.asBinder().linkToDeath(mSessionState, 0); |
| 2436 | } catch (RemoteException e) { |
| 2437 | Slog.e(TAG, "session process has already died", e); |
| 2438 | return false; |
| 2439 | } |
| 2440 | |
| 2441 | IBinder clientToken = mSessionState.client.asBinder(); |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 2442 | UserState userState = getOrCreateUserStateLocked(mSessionState.userId); |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2443 | ClientState clientState = userState.clientStateMap.get(clientToken); |
| 2444 | if (clientState == null) { |
| 2445 | clientState = new ClientState(clientToken, mSessionState.userId); |
| 2446 | try { |
| 2447 | clientToken.linkToDeath(clientState, 0); |
| 2448 | } catch (RemoteException e) { |
| 2449 | Slog.e(TAG, "client process has already died", e); |
| 2450 | return false; |
| 2451 | } |
| 2452 | userState.clientStateMap.put(clientToken, clientState); |
| 2453 | } |
| 2454 | clientState.sessionTokens.add(mSessionState.sessionToken); |
| 2455 | return true; |
| 2456 | } |
| 2457 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2458 | @Override |
| 2459 | public void onChannelRetuned(Uri channelUri) { |
| 2460 | synchronized (mLock) { |
| 2461 | if (DEBUG) { |
| 2462 | Slog.d(TAG, "onChannelRetuned(" + channelUri + ")"); |
| 2463 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2464 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2465 | return; |
| 2466 | } |
| 2467 | try { |
| 2468 | // TODO: Consider adding this channel change in the watch log. When we do |
| 2469 | // that, how we can protect the watch log from malicious tv inputs should |
| 2470 | // be addressed. e.g. add a field which represents where the channel change |
| 2471 | // originated from. |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2472 | mSessionState.client.onChannelRetuned(channelUri, mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2473 | } catch (RemoteException e) { |
| 2474 | Slog.e(TAG, "error in onChannelRetuned", e); |
| 2475 | } |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | @Override |
| 2480 | public void onTracksChanged(List<TvTrackInfo> tracks) { |
| 2481 | synchronized (mLock) { |
| 2482 | if (DEBUG) { |
| 2483 | Slog.d(TAG, "onTracksChanged(" + tracks + ")"); |
| 2484 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2485 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2486 | return; |
| 2487 | } |
| 2488 | try { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2489 | mSessionState.client.onTracksChanged(tracks, mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2490 | } catch (RemoteException e) { |
| 2491 | Slog.e(TAG, "error in onTracksChanged", e); |
| 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | @Override |
| 2497 | public void onTrackSelected(int type, String trackId) { |
| 2498 | synchronized (mLock) { |
| 2499 | if (DEBUG) { |
| 2500 | Slog.d(TAG, "onTrackSelected(type=" + type + ", trackId=" + trackId + ")"); |
| 2501 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2502 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2503 | return; |
| 2504 | } |
| 2505 | try { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2506 | mSessionState.client.onTrackSelected(type, trackId, mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2507 | } catch (RemoteException e) { |
| 2508 | Slog.e(TAG, "error in onTrackSelected", e); |
| 2509 | } |
| 2510 | } |
| 2511 | } |
| 2512 | |
| 2513 | @Override |
| 2514 | public void onVideoAvailable() { |
| 2515 | synchronized (mLock) { |
| 2516 | if (DEBUG) { |
| 2517 | Slog.d(TAG, "onVideoAvailable()"); |
| 2518 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2519 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2520 | return; |
| 2521 | } |
| 2522 | try { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2523 | mSessionState.client.onVideoAvailable(mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2524 | } catch (RemoteException e) { |
| 2525 | Slog.e(TAG, "error in onVideoAvailable", e); |
| 2526 | } |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | @Override |
| 2531 | public void onVideoUnavailable(int reason) { |
| 2532 | synchronized (mLock) { |
| 2533 | if (DEBUG) { |
| 2534 | Slog.d(TAG, "onVideoUnavailable(" + reason + ")"); |
| 2535 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2536 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2537 | return; |
| 2538 | } |
| 2539 | try { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2540 | mSessionState.client.onVideoUnavailable(reason, mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2541 | } catch (RemoteException e) { |
| 2542 | Slog.e(TAG, "error in onVideoUnavailable", e); |
| 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | @Override |
| 2548 | public void onContentAllowed() { |
| 2549 | synchronized (mLock) { |
| 2550 | if (DEBUG) { |
| 2551 | Slog.d(TAG, "onContentAllowed()"); |
| 2552 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2553 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2554 | return; |
| 2555 | } |
| 2556 | try { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2557 | mSessionState.client.onContentAllowed(mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2558 | } catch (RemoteException e) { |
| 2559 | Slog.e(TAG, "error in onContentAllowed", e); |
| 2560 | } |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | @Override |
| 2565 | public void onContentBlocked(String rating) { |
| 2566 | synchronized (mLock) { |
| 2567 | if (DEBUG) { |
| 2568 | Slog.d(TAG, "onContentBlocked()"); |
| 2569 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2570 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2571 | return; |
| 2572 | } |
| 2573 | try { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2574 | mSessionState.client.onContentBlocked(rating, mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2575 | } catch (RemoteException e) { |
| 2576 | Slog.e(TAG, "error in onContentBlocked", e); |
| 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | @Override |
| 2582 | public void onLayoutSurface(int left, int top, int right, int bottom) { |
| 2583 | synchronized (mLock) { |
| 2584 | if (DEBUG) { |
| 2585 | Slog.d(TAG, "onLayoutSurface (left=" + left + ", top=" + top |
| 2586 | + ", right=" + right + ", bottom=" + bottom + ",)"); |
| 2587 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2588 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2589 | return; |
| 2590 | } |
| 2591 | try { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2592 | mSessionState.client.onLayoutSurface(left, top, right, bottom, |
| 2593 | mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2594 | } catch (RemoteException e) { |
| 2595 | Slog.e(TAG, "error in onLayoutSurface", e); |
| 2596 | } |
| 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | @Override |
| 2601 | public void onSessionEvent(String eventType, Bundle eventArgs) { |
| 2602 | synchronized (mLock) { |
| 2603 | if (DEBUG) { |
Jae Seo | 4eee6a7 | 2016-02-06 11:11:35 +0900 | [diff] [blame] | 2604 | Slog.d(TAG, "onEvent(eventType=" + eventType + ", eventArgs=" + eventArgs |
| 2605 | + ")"); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2606 | } |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2607 | if (mSessionState.session == null || mSessionState.client == null) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2608 | return; |
| 2609 | } |
| 2610 | try { |
Ji-Hwan Lee | 9c6b5b7 | 2014-09-17 00:22:39 +0900 | [diff] [blame] | 2611 | mSessionState.client.onSessionEvent(eventType, eventArgs, mSessionState.seq); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2612 | } catch (RemoteException e) { |
| 2613 | Slog.e(TAG, "error in onSessionEvent", e); |
| 2614 | } |
| 2615 | } |
| 2616 | } |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 2617 | |
| 2618 | @Override |
| 2619 | public void onTimeShiftStatusChanged(int status) { |
| 2620 | synchronized (mLock) { |
| 2621 | if (DEBUG) { |
Jae Seo | 4eee6a7 | 2016-02-06 11:11:35 +0900 | [diff] [blame] | 2622 | Slog.d(TAG, "onTimeShiftStatusChanged(status=" + status + ")"); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 2623 | } |
| 2624 | if (mSessionState.session == null || mSessionState.client == null) { |
| 2625 | return; |
| 2626 | } |
| 2627 | try { |
| 2628 | mSessionState.client.onTimeShiftStatusChanged(status, mSessionState.seq); |
| 2629 | } catch (RemoteException e) { |
| 2630 | Slog.e(TAG, "error in onTimeShiftStatusChanged", e); |
| 2631 | } |
| 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | @Override |
| 2636 | public void onTimeShiftStartPositionChanged(long timeMs) { |
| 2637 | synchronized (mLock) { |
| 2638 | if (DEBUG) { |
Jae Seo | 4eee6a7 | 2016-02-06 11:11:35 +0900 | [diff] [blame] | 2639 | Slog.d(TAG, "onTimeShiftStartPositionChanged(timeMs=" + timeMs + ")"); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 2640 | } |
| 2641 | if (mSessionState.session == null || mSessionState.client == null) { |
| 2642 | return; |
| 2643 | } |
| 2644 | try { |
| 2645 | mSessionState.client.onTimeShiftStartPositionChanged(timeMs, mSessionState.seq); |
| 2646 | } catch (RemoteException e) { |
| 2647 | Slog.e(TAG, "error in onTimeShiftStartPositionChanged", e); |
| 2648 | } |
| 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | @Override |
| 2653 | public void onTimeShiftCurrentPositionChanged(long timeMs) { |
| 2654 | synchronized (mLock) { |
| 2655 | if (DEBUG) { |
Jae Seo | 4eee6a7 | 2016-02-06 11:11:35 +0900 | [diff] [blame] | 2656 | Slog.d(TAG, "onTimeShiftCurrentPositionChanged(timeMs=" + timeMs + ")"); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 2657 | } |
| 2658 | if (mSessionState.session == null || mSessionState.client == null) { |
| 2659 | return; |
| 2660 | } |
| 2661 | try { |
| 2662 | mSessionState.client.onTimeShiftCurrentPositionChanged(timeMs, |
| 2663 | mSessionState.seq); |
| 2664 | } catch (RemoteException e) { |
| 2665 | Slog.e(TAG, "error in onTimeShiftCurrentPositionChanged", e); |
| 2666 | } |
| 2667 | } |
| 2668 | } |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2669 | |
| 2670 | // For the recording session only |
| 2671 | @Override |
Dongwon Kang | b55c751 | 2016-03-01 09:36:07 -0800 | [diff] [blame] | 2672 | public void onTuned(Uri channelUri) { |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2673 | synchronized (mLock) { |
| 2674 | if (DEBUG) { |
Jae Seo | e3c11e8 | 2016-02-08 23:18:49 -0800 | [diff] [blame] | 2675 | Slog.d(TAG, "onTuned()"); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2676 | } |
| 2677 | if (mSessionState.session == null || mSessionState.client == null) { |
| 2678 | return; |
| 2679 | } |
| 2680 | try { |
Dongwon Kang | b55c751 | 2016-03-01 09:36:07 -0800 | [diff] [blame] | 2681 | mSessionState.client.onTuned(mSessionState.seq, channelUri); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2682 | } catch (RemoteException e) { |
Jae Seo | e3c11e8 | 2016-02-08 23:18:49 -0800 | [diff] [blame] | 2683 | Slog.e(TAG, "error in onTuned", e); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2684 | } |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | // For the recording session only |
| 2689 | @Override |
| 2690 | public void onRecordingStopped(Uri recordedProgramUri) { |
| 2691 | synchronized (mLock) { |
| 2692 | if (DEBUG) { |
Jae Seo | 4eee6a7 | 2016-02-06 11:11:35 +0900 | [diff] [blame] | 2693 | Slog.d(TAG, "onRecordingStopped(recordedProgramUri=" + recordedProgramUri |
| 2694 | + ")"); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2695 | } |
| 2696 | if (mSessionState.session == null || mSessionState.client == null) { |
| 2697 | return; |
| 2698 | } |
| 2699 | try { |
| 2700 | mSessionState.client.onRecordingStopped(recordedProgramUri, mSessionState.seq); |
| 2701 | } catch (RemoteException e) { |
| 2702 | Slog.e(TAG, "error in onRecordingStopped", e); |
| 2703 | } |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | // For the recording session only |
| 2708 | @Override |
| 2709 | public void onError(int error) { |
| 2710 | synchronized (mLock) { |
| 2711 | if (DEBUG) { |
Jae Seo | 4eee6a7 | 2016-02-06 11:11:35 +0900 | [diff] [blame] | 2712 | Slog.d(TAG, "onError(error=" + error + ")"); |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 2713 | } |
| 2714 | if (mSessionState.session == null || mSessionState.client == null) { |
| 2715 | return; |
| 2716 | } |
| 2717 | try { |
| 2718 | mSessionState.client.onError(error, mSessionState.seq); |
| 2719 | } catch (RemoteException e) { |
| 2720 | Slog.e(TAG, "error in onError", e); |
| 2721 | } |
| 2722 | } |
| 2723 | } |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | private static final class WatchLogHandler extends Handler { |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2727 | // There are only two kinds of watch events that can happen on the system: |
| 2728 | // 1. The current TV input session is tuned to a new channel. |
| 2729 | // 2. The session is released for some reason. |
| 2730 | // The former indicates the end of the previous log entry, if any, followed by the start of |
| 2731 | // a new entry. The latter indicates the end of the most recent entry for the given session. |
| 2732 | // Here the system supplies the database the smallest set of information only that is |
| 2733 | // sufficient to consolidate the log entries while minimizing database operations in the |
| 2734 | // system service. |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 2735 | static final int MSG_LOG_WATCH_START = 1; |
| 2736 | static final int MSG_LOG_WATCH_END = 2; |
| 2737 | static final int MSG_SWITCH_CONTENT_RESOLVER = 3; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2738 | |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 2739 | private ContentResolver mContentResolver; |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2740 | |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 2741 | WatchLogHandler(ContentResolver contentResolver, Looper looper) { |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2742 | super(looper); |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2743 | mContentResolver = contentResolver; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | @Override |
| 2747 | public void handleMessage(Message msg) { |
| 2748 | switch (msg.what) { |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2749 | case MSG_LOG_WATCH_START: { |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2750 | SomeArgs args = (SomeArgs) msg.obj; |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2751 | String packageName = (String) args.arg1; |
| 2752 | long watchStartTime = (long) args.arg2; |
| 2753 | long channelId = (long) args.arg3; |
| 2754 | Bundle tuneParams = (Bundle) args.arg4; |
| 2755 | IBinder sessionToken = (IBinder) args.arg5; |
| 2756 | |
| 2757 | ContentValues values = new ContentValues(); |
| 2758 | values.put(TvContract.WatchedPrograms.COLUMN_PACKAGE_NAME, packageName); |
| 2759 | values.put(TvContract.WatchedPrograms.COLUMN_WATCH_START_TIME_UTC_MILLIS, |
| 2760 | watchStartTime); |
| 2761 | values.put(TvContract.WatchedPrograms.COLUMN_CHANNEL_ID, channelId); |
| 2762 | if (tuneParams != null) { |
| 2763 | values.put(TvContract.WatchedPrograms.COLUMN_INTERNAL_TUNE_PARAMS, |
| 2764 | encodeTuneParams(tuneParams)); |
| 2765 | } |
| 2766 | values.put(TvContract.WatchedPrograms.COLUMN_INTERNAL_SESSION_TOKEN, |
| 2767 | sessionToken.toString()); |
| 2768 | |
| 2769 | mContentResolver.insert(TvContract.WatchedPrograms.CONTENT_URI, values); |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2770 | args.recycle(); |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 2771 | break; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2772 | } |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2773 | case MSG_LOG_WATCH_END: { |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2774 | SomeArgs args = (SomeArgs) msg.obj; |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2775 | IBinder sessionToken = (IBinder) args.arg1; |
| 2776 | long watchEndTime = (long) args.arg2; |
| 2777 | |
| 2778 | ContentValues values = new ContentValues(); |
| 2779 | values.put(TvContract.WatchedPrograms.COLUMN_WATCH_END_TIME_UTC_MILLIS, |
| 2780 | watchEndTime); |
| 2781 | values.put(TvContract.WatchedPrograms.COLUMN_INTERNAL_SESSION_TOKEN, |
| 2782 | sessionToken.toString()); |
| 2783 | |
| 2784 | mContentResolver.insert(TvContract.WatchedPrograms.CONTENT_URI, values); |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2785 | args.recycle(); |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 2786 | break; |
| 2787 | } |
| 2788 | case MSG_SWITCH_CONTENT_RESOLVER: { |
| 2789 | mContentResolver = (ContentResolver) msg.obj; |
| 2790 | break; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2791 | } |
| 2792 | default: { |
Jae Seo | 8c375fe | 2015-06-23 20:33:25 -0700 | [diff] [blame] | 2793 | Slog.w(TAG, "unhandled message code: " + msg.what); |
| 2794 | break; |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2795 | } |
| 2796 | } |
| 2797 | } |
| 2798 | |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2799 | private String encodeTuneParams(Bundle tuneParams) { |
| 2800 | StringBuilder builder = new StringBuilder(); |
| 2801 | Set<String> keySet = tuneParams.keySet(); |
| 2802 | Iterator<String> it = keySet.iterator(); |
| 2803 | while (it.hasNext()) { |
| 2804 | String key = it.next(); |
| 2805 | Object value = tuneParams.get(key); |
| 2806 | if (value == null) { |
| 2807 | continue; |
Jae Seo | 579befe | 2014-08-06 19:18:37 -0700 | [diff] [blame] | 2808 | } |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2809 | builder.append(replaceEscapeCharacters(key)); |
| 2810 | builder.append("="); |
| 2811 | builder.append(replaceEscapeCharacters(value.toString())); |
| 2812 | if (it.hasNext()) { |
| 2813 | builder.append(", "); |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2814 | } |
| 2815 | } |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2816 | return builder.toString(); |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2819 | private String replaceEscapeCharacters(String src) { |
| 2820 | final char ESCAPE_CHARACTER = '%'; |
| 2821 | final String ENCODING_TARGET_CHARACTERS = "%=,"; |
| 2822 | StringBuilder builder = new StringBuilder(); |
| 2823 | for (char ch : src.toCharArray()) { |
| 2824 | if (ENCODING_TARGET_CHARACTERS.indexOf(ch) >= 0) { |
| 2825 | builder.append(ESCAPE_CHARACTER); |
Chulwoo Lee | 8d4ded0 | 2014-07-10 03:56:39 +0900 | [diff] [blame] | 2826 | } |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2827 | builder.append(ch); |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2828 | } |
Jae Seo | 7eb75df | 2014-08-08 22:20:48 -0700 | [diff] [blame] | 2829 | return builder.toString(); |
Jae Seo | 579befe | 2014-08-06 19:18:37 -0700 | [diff] [blame] | 2830 | } |
Jae Seo | 31dc634be | 2014-04-15 17:40:23 -0700 | [diff] [blame] | 2831 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2832 | |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2833 | private final class HardwareListener implements TvInputHardwareManager.Listener { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2834 | @Override |
| 2835 | public void onStateChanged(String inputId, int state) { |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2836 | synchronized (mLock) { |
| 2837 | setStateLocked(inputId, state, mCurrentUserId); |
| 2838 | } |
| 2839 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2840 | |
| 2841 | @Override |
| 2842 | public void onHardwareDeviceAdded(TvInputHardwareInfo info) { |
| 2843 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 2844 | UserState userState = getOrCreateUserStateLocked(mCurrentUserId); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2845 | // Broadcast the event to all hardware inputs. |
| 2846 | for (ServiceState serviceState : userState.serviceStateMap.values()) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2847 | if (!serviceState.isHardware || serviceState.service == null) continue; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2848 | try { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2849 | serviceState.service.notifyHardwareAdded(info); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2850 | } catch (RemoteException e) { |
| 2851 | Slog.e(TAG, "error in notifyHardwareAdded", e); |
| 2852 | } |
| 2853 | } |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | @Override |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2858 | public void onHardwareDeviceRemoved(TvInputHardwareInfo info) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2859 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 2860 | UserState userState = getOrCreateUserStateLocked(mCurrentUserId); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2861 | // Broadcast the event to all hardware inputs. |
| 2862 | for (ServiceState serviceState : userState.serviceStateMap.values()) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2863 | if (!serviceState.isHardware || serviceState.service == null) continue; |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2864 | try { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2865 | serviceState.service.notifyHardwareRemoved(info); |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2866 | } catch (RemoteException e) { |
| 2867 | Slog.e(TAG, "error in notifyHardwareRemoved", e); |
| 2868 | } |
| 2869 | } |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | @Override |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 2874 | public void onHdmiDeviceAdded(HdmiDeviceInfo deviceInfo) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2875 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 2876 | UserState userState = getOrCreateUserStateLocked(mCurrentUserId); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2877 | // Broadcast the event to all hardware inputs. |
| 2878 | for (ServiceState serviceState : userState.serviceStateMap.values()) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2879 | if (!serviceState.isHardware || serviceState.service == null) continue; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2880 | try { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2881 | serviceState.service.notifyHdmiDeviceAdded(deviceInfo); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2882 | } catch (RemoteException e) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 2883 | Slog.e(TAG, "error in notifyHdmiDeviceAdded", e); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2884 | } |
| 2885 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | @Override |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 2890 | public void onHdmiDeviceRemoved(HdmiDeviceInfo deviceInfo) { |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2891 | synchronized (mLock) { |
Jae Seo | 4f1a6d4 | 2015-07-20 16:15:01 -0700 | [diff] [blame] | 2892 | UserState userState = getOrCreateUserStateLocked(mCurrentUserId); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2893 | // Broadcast the event to all hardware inputs. |
| 2894 | for (ServiceState serviceState : userState.serviceStateMap.values()) { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2895 | if (!serviceState.isHardware || serviceState.service == null) continue; |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2896 | try { |
Dongwon Kang | fd8aa02 | 2014-08-28 14:59:20 +0900 | [diff] [blame] | 2897 | serviceState.service.notifyHdmiDeviceRemoved(deviceInfo); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2898 | } catch (RemoteException e) { |
Jae Seo | 546c635 | 2014-08-07 11:57:01 -0700 | [diff] [blame] | 2899 | Slog.e(TAG, "error in notifyHdmiDeviceRemoved", e); |
Ji-Hwan Lee | 4f9f57c | 2014-07-19 22:20:31 +0900 | [diff] [blame] | 2900 | } |
| 2901 | } |
Wonsik Kim | 187423c | 2014-06-25 14:12:48 +0900 | [diff] [blame] | 2902 | } |
| 2903 | } |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 2904 | |
| 2905 | @Override |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 2906 | public void onHdmiDeviceUpdated(String inputId, HdmiDeviceInfo deviceInfo) { |
| 2907 | synchronized (mLock) { |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2908 | Integer state; |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 2909 | switch (deviceInfo.getDevicePowerStatus()) { |
| 2910 | case HdmiControlManager.POWER_STATUS_ON: |
| 2911 | state = INPUT_STATE_CONNECTED; |
| 2912 | break; |
| 2913 | case HdmiControlManager.POWER_STATUS_STANDBY: |
| 2914 | case HdmiControlManager.POWER_STATUS_TRANSIENT_TO_ON: |
| 2915 | case HdmiControlManager.POWER_STATUS_TRANSIENT_TO_STANDBY: |
| 2916 | state = INPUT_STATE_CONNECTED_STANDBY; |
| 2917 | break; |
| 2918 | case HdmiControlManager.POWER_STATUS_UNKNOWN: |
| 2919 | default: |
| 2920 | state = null; |
| 2921 | break; |
| 2922 | } |
| 2923 | if (state != null) { |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 2924 | setStateLocked(inputId, state, mCurrentUserId); |
Wonsik Kim | e92f857 | 2014-08-12 18:30:24 +0900 | [diff] [blame] | 2925 | } |
| 2926 | } |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 2927 | } |
Wonsik Kim | 969167d | 2014-06-24 16:33:17 +0900 | [diff] [blame] | 2928 | } |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 2929 | |
| 2930 | private static class SessionNotFoundException extends IllegalArgumentException { |
Dongwon Kang | fdce9e5 | 2014-12-04 18:08:00 +0900 | [diff] [blame] | 2931 | public SessionNotFoundException(String name) { |
| 2932 | super(name); |
| 2933 | } |
| 2934 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 2935 | } |