Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.privacy |
| 18 | |
| 19 | import android.app.ActivityManager |
| 20 | import android.app.AppOpsManager |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 21 | import android.content.BroadcastReceiver |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 22 | import android.content.Context |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 23 | import android.content.Intent |
| 24 | import android.content.IntentFilter |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 25 | import android.os.Handler |
| 26 | import android.os.Looper |
| 27 | import android.os.Message |
| 28 | import android.os.UserHandle |
| 29 | import android.os.UserManager |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 30 | import android.provider.DeviceConfig |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 31 | import com.android.internal.annotations.VisibleForTesting |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 32 | import com.android.internal.config.sysui.SystemUiDeviceConfigFlags |
Dave Mankoff | f473681 | 2019-10-18 17:25:50 -0400 | [diff] [blame] | 33 | import com.android.systemui.Dumpable |
Fabian Kozynski | 8176539 | 2019-02-11 12:38:26 -0500 | [diff] [blame] | 34 | import com.android.systemui.R |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 35 | import com.android.systemui.appops.AppOpItem |
| 36 | import com.android.systemui.appops.AppOpsController |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 37 | import com.android.systemui.broadcast.BroadcastDispatcher |
Dave Mankoff | f473681 | 2019-10-18 17:25:50 -0400 | [diff] [blame] | 38 | import com.android.systemui.dagger.qualifiers.BgHandler |
| 39 | import com.android.systemui.dagger.qualifiers.MainHandler |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 40 | import java.io.FileDescriptor |
| 41 | import java.io.PrintWriter |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 42 | import java.lang.ref.WeakReference |
| 43 | import javax.inject.Inject |
| 44 | import javax.inject.Singleton |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 45 | |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 46 | fun isPermissionsHubEnabled() = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, |
| 47 | SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED, false) |
| 48 | |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 49 | @Singleton |
Fabian Kozynski | 8176539 | 2019-02-11 12:38:26 -0500 | [diff] [blame] | 50 | class PrivacyItemController @Inject constructor( |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 51 | private val context: Context, |
Matt Pape | cb88879 | 2019-05-22 15:32:32 -0700 | [diff] [blame] | 52 | private val appOpsController: AppOpsController, |
Dave Mankoff | f473681 | 2019-10-18 17:25:50 -0400 | [diff] [blame] | 53 | @MainHandler private val uiHandler: Handler, |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 54 | @BgHandler private val bgHandler: Handler, |
| 55 | private val broadcastDispatcher: BroadcastDispatcher |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 56 | ) : Dumpable { |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 57 | |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 58 | @VisibleForTesting |
| 59 | internal companion object { |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 60 | val OPS = intArrayOf(AppOpsManager.OP_CAMERA, |
| 61 | AppOpsManager.OP_RECORD_AUDIO, |
| 62 | AppOpsManager.OP_COARSE_LOCATION, |
| 63 | AppOpsManager.OP_FINE_LOCATION) |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 64 | val intents = listOf(Intent.ACTION_USER_FOREGROUND, |
| 65 | Intent.ACTION_MANAGED_PROFILE_ADDED, |
| 66 | Intent.ACTION_MANAGED_PROFILE_REMOVED) |
| 67 | const val TAG = "PrivacyItemController" |
Fabian Kozynski | 508422b | 2018-12-20 10:58:17 -0500 | [diff] [blame] | 68 | const val SYSTEM_UID = 1000 |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 69 | const val MSG_ADD_CALLBACK = 0 |
| 70 | const val MSG_REMOVE_CALLBACK = 1 |
| 71 | const val MSG_UPDATE_LISTENING_STATE = 2 |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 72 | } |
Fabian Kozynski | 508422b | 2018-12-20 10:58:17 -0500 | [diff] [blame] | 73 | |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 74 | @VisibleForTesting |
| 75 | internal var privacyList = emptyList<PrivacyItem>() |
Fabian Kozynski | 7209010 | 2019-03-04 10:55:55 -0500 | [diff] [blame] | 76 | @Synchronized get() = field.toList() // Returns a shallow copy of the list |
| 77 | @Synchronized set |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 78 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 79 | private val userManager = context.getSystemService(UserManager::class.java) |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 80 | private var currentUserIds = emptyList<Int>() |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 81 | private var listening = false |
Fabian Kozynski | 0d03da3 | 2019-01-28 10:35:28 -0500 | [diff] [blame] | 82 | val systemApp = |
| 83 | PrivacyApplication(context.getString(R.string.device_services), SYSTEM_UID, context) |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 84 | private val callbacks = mutableListOf<WeakReference<Callback>>() |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 85 | private val messageHandler = H(WeakReference(this), uiHandler.looper) |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 86 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 87 | private val notifyChanges = Runnable { |
Fabian Kozynski | 7209010 | 2019-03-04 10:55:55 -0500 | [diff] [blame] | 88 | val list = privacyList |
| 89 | callbacks.forEach { it.get()?.privacyChanged(list) } |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 90 | } |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 91 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 92 | private val updateListAndNotifyChanges = Runnable { |
| 93 | updatePrivacyList() |
| 94 | uiHandler.post(notifyChanges) |
| 95 | } |
| 96 | |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 97 | private var indicatorsAvailable = isPermissionsHubEnabled() |
| 98 | @VisibleForTesting |
Matt Pape | cb88879 | 2019-05-22 15:32:32 -0700 | [diff] [blame] | 99 | internal val devicePropertiesChangedListener = |
| 100 | object : DeviceConfig.OnPropertiesChangedListener { |
| 101 | override fun onPropertiesChanged(properties: DeviceConfig.Properties) { |
| 102 | if (DeviceConfig.NAMESPACE_PRIVACY.equals(properties.getNamespace()) && |
| 103 | properties.getKeyset().contains( |
| 104 | SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED)) { |
| 105 | indicatorsAvailable = properties.getBoolean( |
| 106 | SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED, false) |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 107 | messageHandler.removeMessages(MSG_UPDATE_LISTENING_STATE) |
| 108 | messageHandler.sendEmptyMessage(MSG_UPDATE_LISTENING_STATE) |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 113 | private val cb = object : AppOpsController.Callback { |
| 114 | override fun onActiveStateChanged( |
| 115 | code: Int, |
| 116 | uid: Int, |
| 117 | packageName: String, |
| 118 | active: Boolean |
| 119 | ) { |
| 120 | val userId = UserHandle.getUserId(uid) |
| 121 | if (userId in currentUserIds) { |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 122 | update(false) |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 127 | @VisibleForTesting |
| 128 | internal var userSwitcherReceiver = Receiver() |
| 129 | set(value) { |
| 130 | context.unregisterReceiver(field) |
| 131 | field = value |
| 132 | registerReceiver() |
| 133 | } |
| 134 | |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 135 | init { |
Matt Pape | cb88879 | 2019-05-22 15:32:32 -0700 | [diff] [blame] | 136 | DeviceConfig.addOnPropertiesChangedListener( |
| 137 | DeviceConfig.NAMESPACE_PRIVACY, |
| 138 | context.mainExecutor, |
| 139 | devicePropertiesChangedListener) |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 140 | } |
| 141 | |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 142 | private fun unregisterReceiver() { |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 143 | broadcastDispatcher.unregisterReceiver(userSwitcherReceiver) |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | private fun registerReceiver() { |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 147 | broadcastDispatcher.registerReceiver(userSwitcherReceiver, IntentFilter().apply { |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 148 | intents.forEach { |
| 149 | addAction(it) |
| 150 | } |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 151 | }, null /* handler */, UserHandle.ALL) |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | private fun update(updateUsers: Boolean) { |
| 155 | if (updateUsers) { |
| 156 | val currentUser = ActivityManager.getCurrentUser() |
| 157 | currentUserIds = userManager.getProfiles(currentUser).map { it.id } |
| 158 | } |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 159 | bgHandler.post(updateListAndNotifyChanges) |
| 160 | } |
| 161 | |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 162 | /** |
| 163 | * Updates listening status based on whether there are callbacks and the indicators are enabled |
| 164 | * |
| 165 | * This is only called from private (add/remove)Callback and from the config listener, all in |
| 166 | * main thread. |
| 167 | */ |
| 168 | private fun setListeningState() { |
| 169 | val listen = !callbacks.isEmpty() and indicatorsAvailable |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 170 | if (listening == listen) return |
| 171 | listening = listen |
| 172 | if (listening) { |
| 173 | appOpsController.addCallback(OPS, cb) |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 174 | registerReceiver() |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 175 | update(true) |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 176 | } else { |
| 177 | appOpsController.removeCallback(OPS, cb) |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 178 | unregisterReceiver() |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 179 | // Make sure that we remove all indicators and notify listeners if we are not |
| 180 | // listening anymore due to indicators being disabled |
| 181 | update(false) |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 185 | private fun addCallback(callback: WeakReference<Callback>) { |
| 186 | callbacks.add(callback) |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 187 | if (callbacks.isNotEmpty() && !listening) { |
| 188 | messageHandler.removeMessages(MSG_UPDATE_LISTENING_STATE) |
| 189 | messageHandler.sendEmptyMessage(MSG_UPDATE_LISTENING_STATE) |
| 190 | } |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 191 | // Notify this callback if we didn't set to listening |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 192 | else if (listening) uiHandler.post(NotifyChangesToCallback(callback.get(), privacyList)) |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | private fun removeCallback(callback: WeakReference<Callback>) { |
| 196 | // Removes also if the callback is null |
| 197 | callbacks.removeIf { it.get()?.equals(callback.get()) ?: true } |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 198 | if (callbacks.isEmpty()) { |
| 199 | messageHandler.removeMessages(MSG_UPDATE_LISTENING_STATE) |
| 200 | messageHandler.sendEmptyMessage(MSG_UPDATE_LISTENING_STATE) |
| 201 | } |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | fun addCallback(callback: Callback) { |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 205 | messageHandler.obtainMessage(MSG_ADD_CALLBACK, callback).sendToTarget() |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | fun removeCallback(callback: Callback) { |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 209 | messageHandler.obtainMessage(MSG_REMOVE_CALLBACK, callback).sendToTarget() |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 210 | } |
| 211 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 212 | private fun updatePrivacyList() { |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 213 | if (!listening) { |
| 214 | privacyList = emptyList() |
| 215 | return |
| 216 | } |
Fabian Kozynski | 7209010 | 2019-03-04 10:55:55 -0500 | [diff] [blame] | 217 | val list = currentUserIds.flatMap { appOpsController.getActiveAppOpsForUser(it) } |
Fabian Kozynski | 510585d | 2018-12-19 13:59:17 -0500 | [diff] [blame] | 218 | .mapNotNull { toPrivacyItem(it) }.distinct() |
Fabian Kozynski | 7209010 | 2019-03-04 10:55:55 -0500 | [diff] [blame] | 219 | privacyList = list |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | private fun toPrivacyItem(appOpItem: AppOpItem): PrivacyItem? { |
| 223 | val type: PrivacyType = when (appOpItem.code) { |
| 224 | AppOpsManager.OP_CAMERA -> PrivacyType.TYPE_CAMERA |
| 225 | AppOpsManager.OP_COARSE_LOCATION -> PrivacyType.TYPE_LOCATION |
| 226 | AppOpsManager.OP_FINE_LOCATION -> PrivacyType.TYPE_LOCATION |
| 227 | AppOpsManager.OP_RECORD_AUDIO -> PrivacyType.TYPE_MICROPHONE |
| 228 | else -> return null |
| 229 | } |
Fabian Kozynski | 508422b | 2018-12-20 10:58:17 -0500 | [diff] [blame] | 230 | if (appOpItem.uid == SYSTEM_UID) return PrivacyItem(type, systemApp) |
Fabian Kozynski | 0d03da3 | 2019-01-28 10:35:28 -0500 | [diff] [blame] | 231 | val app = PrivacyApplication(appOpItem.packageName, appOpItem.uid, context) |
Fabian Kozynski | ef12449 | 2018-11-02 11:02:11 -0400 | [diff] [blame] | 232 | return PrivacyItem(type, app) |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | // Used by containing class to get notified of changes |
| 236 | interface Callback { |
| 237 | fun privacyChanged(privacyItems: List<PrivacyItem>) |
| 238 | } |
Fabian Kozynski | b5625ac | 2018-11-21 08:56:55 -0500 | [diff] [blame] | 239 | |
| 240 | internal inner class Receiver : BroadcastReceiver() { |
| 241 | override fun onReceive(context: Context?, intent: Intent?) { |
| 242 | if (intent?.action in intents) { |
| 243 | update(true) |
| 244 | } |
| 245 | } |
| 246 | } |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 247 | |
| 248 | private class NotifyChangesToCallback( |
| 249 | private val callback: Callback?, |
| 250 | private val list: List<PrivacyItem> |
| 251 | ) : Runnable { |
| 252 | override fun run() { |
| 253 | callback?.privacyChanged(list) |
| 254 | } |
| 255 | } |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 256 | |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 257 | override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) { |
| 258 | pw.println("PrivacyItemController state:") |
| 259 | pw.println(" Listening: $listening") |
| 260 | pw.println(" Current user ids: $currentUserIds") |
| 261 | pw.println(" Privacy Items:") |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 262 | privacyList.forEach { |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 263 | pw.print(" ") |
| 264 | pw.println(it.toString()) |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 265 | } |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 266 | pw.println(" Callbacks:") |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 267 | callbacks.forEach { |
| 268 | it.get()?.let { |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 269 | pw.print(" ") |
| 270 | pw.println(it.toString()) |
Fabian Kozynski | a6ff80b | 2019-02-12 11:32:44 -0500 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 274 | |
| 275 | private class H( |
Matt Pape | cb88879 | 2019-05-22 15:32:32 -0700 | [diff] [blame] | 276 | private val outerClass: WeakReference<PrivacyItemController>, |
| 277 | looper: Looper |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 278 | ) : Handler(looper) { |
| 279 | override fun handleMessage(msg: Message) { |
| 280 | super.handleMessage(msg) |
| 281 | when (msg.what) { |
| 282 | MSG_UPDATE_LISTENING_STATE -> outerClass.get()?.setListeningState() |
| 283 | |
| 284 | MSG_ADD_CALLBACK -> { |
| 285 | if (msg.obj !is PrivacyItemController.Callback) return |
| 286 | outerClass.get()?.addCallback( |
| 287 | WeakReference(msg.obj as PrivacyItemController.Callback)) |
| 288 | } |
| 289 | |
| 290 | MSG_REMOVE_CALLBACK -> { |
| 291 | if (msg.obj !is PrivacyItemController.Callback) return |
| 292 | outerClass.get()?.removeCallback( |
| 293 | WeakReference(msg.obj as PrivacyItemController.Callback)) |
| 294 | } |
| 295 | else -> {} |
| 296 | } |
| 297 | } |
| 298 | } |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 299 | } |