summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/ecm/EnhancedConfirmationCallTrackerService.java13
-rw-r--r--service/java/com/android/ecm/EnhancedConfirmationManagerLocal.java6
-rw-r--r--service/java/com/android/ecm/EnhancedConfirmationService.java21
3 files changed, 34 insertions, 6 deletions
diff --git a/service/java/com/android/ecm/EnhancedConfirmationCallTrackerService.java b/service/java/com/android/ecm/EnhancedConfirmationCallTrackerService.java
index 9117d6558..038c28383 100644
--- a/service/java/com/android/ecm/EnhancedConfirmationCallTrackerService.java
+++ b/service/java/com/android/ecm/EnhancedConfirmationCallTrackerService.java
@@ -28,6 +28,9 @@ import android.telecom.InCallService;
import com.android.server.LocalManagerRegistry;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
/**
* @hide
*
@@ -41,6 +44,8 @@ import com.android.server.LocalManagerRegistry;
public class EnhancedConfirmationCallTrackerService extends InCallService {
private EnhancedConfirmationManagerLocal mEnhancedConfirmationManagerLocal;
+ private final ExecutorService mBackgroundExecutor = Executors.newSingleThreadExecutor();
+
@Override
public void onCreate() {
super.onCreate();
@@ -56,7 +61,7 @@ public class EnhancedConfirmationCallTrackerService extends InCallService {
return;
}
- mEnhancedConfirmationManagerLocal.addOngoingCall(call);
+ mBackgroundExecutor.submit(() -> mEnhancedConfirmationManagerLocal.addOngoingCall(call));
}
@Override
@@ -65,7 +70,8 @@ public class EnhancedConfirmationCallTrackerService extends InCallService {
return;
}
- mEnhancedConfirmationManagerLocal.removeOngoingCall(call.getDetails().getId());
+ mBackgroundExecutor.submit(() ->
+ mEnhancedConfirmationManagerLocal.removeOngoingCall(call.getDetails().getId()));
}
/**
@@ -73,7 +79,8 @@ public class EnhancedConfirmationCallTrackerService extends InCallService {
*/
public boolean onUnbind(@Nullable Intent intent) {
if (mEnhancedConfirmationManagerLocal != null) {
- mEnhancedConfirmationManagerLocal.clearOngoingCalls();
+ mBackgroundExecutor.submit(() ->
+ mEnhancedConfirmationManagerLocal.clearOngoingCalls());
}
return super.onUnbind(intent);
}
diff --git a/service/java/com/android/ecm/EnhancedConfirmationManagerLocal.java b/service/java/com/android/ecm/EnhancedConfirmationManagerLocal.java
index 483071716..984a6783c 100644
--- a/service/java/com/android/ecm/EnhancedConfirmationManagerLocal.java
+++ b/service/java/com/android/ecm/EnhancedConfirmationManagerLocal.java
@@ -34,10 +34,10 @@ import android.telecom.Call;
@TargetApi(Build.VERSION_CODES.BAKLAVA)
public interface EnhancedConfirmationManagerLocal {
/**
- * Inform the enhanced confirmation service of an ongoing call
+ * Inform the enhanced confirmation service of an ongoing call.
*
* @param call The call to potentially track
- *
+ * @throws IllegalStateException if called on the main thread
*/
void addOngoingCall(@NonNull Call call);
@@ -45,12 +45,14 @@ public interface EnhancedConfirmationManagerLocal {
* Inform the enhanced confirmation service that a call has ended
*
* @param callId The ID of the call to stop tracking
+ * @throws IllegalStateException if called on the main thread
*
*/
void removeOngoingCall(@NonNull String callId);
/**
* Informs the enhanced confirmation service it should clear out any ongoing calls
+ * @throws IllegalStateException if called on the main thread
*/
void clearOngoingCalls();
}
diff --git a/service/java/com/android/ecm/EnhancedConfirmationService.java b/service/java/com/android/ecm/EnhancedConfirmationService.java
index fc0ed20d0..55db07e30 100644
--- a/service/java/com/android/ecm/EnhancedConfirmationService.java
+++ b/service/java/com/android/ecm/EnhancedConfirmationService.java
@@ -27,6 +27,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.UserIdInt;
+import android.annotation.WorkerThread;
import android.app.AppOpsManager;
import android.app.ecm.EnhancedConfirmationManager;
import android.app.ecm.IEnhancedConfirmationManager;
@@ -43,6 +44,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
+import android.os.Looper;
import android.os.SystemConfigManager;
import android.os.UserHandle;
import android.permission.flags.Flags;
@@ -90,7 +92,7 @@ public class EnhancedConfirmationService extends SystemService {
private Map<String, List<byte[]>> mTrustedPackageCertDigests;
private Map<String, List<byte[]>> mTrustedInstallerCertDigests;
- // A map of call ID to call type
+ // A map of call ID to call type. Not thread safe
private final Map<String, Integer> mOngoingCalls = new ArrayMap<>();
private static final int CALL_TYPE_UNTRUSTED = 0;
@@ -143,6 +145,7 @@ public class EnhancedConfirmationService extends SystemService {
}
void addOngoingCall(Call call) {
+ assertNotMainThread();
if (!Flags.unknownCallPackageInstallBlockingEnabled()) {
return;
}
@@ -152,7 +155,9 @@ public class EnhancedConfirmationService extends SystemService {
mOngoingCalls.put(call.getDetails().getId(), getCallType(call));
}
+ @WorkerThread
void removeOngoingCall(String callId) {
+ assertNotMainThread();
if (!Flags.unknownCallPackageInstallBlockingEnabled()) {
return;
}
@@ -162,11 +167,15 @@ public class EnhancedConfirmationService extends SystemService {
}
}
+ @WorkerThread
void clearOngoingCalls() {
+ assertNotMainThread();
mOngoingCalls.clear();
}
+ @WorkerThread
private @CallType int getCallType(Call call) {
+ assertNotMainThread();
String number = getPhoneNumber(call);
try {
if (number != null && mTelephonyManager.isEmergencyNumber(number)) {
@@ -196,7 +205,9 @@ public class EnhancedConfirmationService extends SystemService {
return handle.getSchemeSpecificPart();
}
+ @WorkerThread
private boolean hasContactWithPhoneNumber(String phoneNumber) {
+ assertNotMainThread();
if (phoneNumber == null) {
return false;
}
@@ -211,7 +222,9 @@ public class EnhancedConfirmationService extends SystemService {
}
}
+ @WorkerThread
private boolean hasContactWithDisplayName(String displayName) {
+ assertNotMainThread();
if (displayName == null) {
return false;
}
@@ -233,6 +246,12 @@ public class EnhancedConfirmationService extends SystemService {
return false;
}
+ private void assertNotMainThread() throws IllegalStateException {
+ if (Looper.myLooper() == Looper.getMainLooper()) {
+ throw new IllegalStateException("Ecm WorkerThread method called on main thread");
+ }
+ }
+
private class Stub extends IEnhancedConfirmationManager.Stub {
/** A map of ECM states to their corresponding app op states */