diff options
16 files changed, 297 insertions, 319 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index d5be20f326ba..77cc03c0cb39 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -11596,7 +11596,6 @@ package android.telephony { } public class TelephonyManager { - method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void addCarrierPrivilegesListener(int, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CarrierPrivilegesListener); method @RequiresPermission(anyOf={android.Manifest.permission.MODIFY_PHONE_STATE, android.Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION}) @WorkerThread public void bootstrapAuthenticationRequest(int, @NonNull android.net.Uri, @NonNull android.telephony.gba.UaSecurityProtocolIdentifier, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.BootstrapAuthenticationCallback); method @Deprecated @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void call(String, String); method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult changeIccLockPin(@NonNull String, @NonNull String); @@ -11697,7 +11696,6 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.REBOOT) public int prepareForUnattendedReboot(); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean rebootRadio(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void registerCarrierPrivilegesCallback(int, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CarrierPrivilegesCallback); - method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void removeCarrierPrivilegesListener(@NonNull android.telephony.TelephonyManager.CarrierPrivilegesListener); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void reportDefaultNetworkStatus(boolean); method @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.MODIFY_PHONE_STATE}) public void requestCellInfoUpdate(@NonNull android.os.WorkSource, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CellInfoCallback); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void requestModemActivityInfo(@NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.telephony.ModemActivityInfo,android.telephony.TelephonyManager.ModemActivityInfoException>); @@ -11857,10 +11855,6 @@ package android.telephony { method public default void onCarrierServiceChanged(@Nullable String, int); } - @Deprecated public static interface TelephonyManager.CarrierPrivilegesListener { - method @Deprecated public void onCarrierPrivilegesChanged(@NonNull java.util.List<java.lang.String>, @NonNull int[]); - } - public static class TelephonyManager.ModemActivityInfoException extends java.lang.Exception { ctor public TelephonyManager.ModemActivityInfoException(int); method public int getErrorCode(); diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java index 7be4c3e1465b..4c30f56e40d6 100644 --- a/core/java/android/app/ActivityManagerInternal.java +++ b/core/java/android/app/ActivityManagerInternal.java @@ -586,8 +586,9 @@ public abstract class ActivityManagerInternal { /** * Delete uid from the ActivityManagerService PendingStartActivityUids list. * @param uid uid + * @param nowElapsed starting time of updateOomAdj */ - public abstract void deletePendingTopUid(int uid); + public abstract void deletePendingTopUid(int uid, long nowElapsed); /** * Is the uid in ActivityManagerService PendingStartActivityUids list? diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java index 2d402199e196..0919e5b96be6 100644 --- a/core/java/android/provider/DeviceConfig.java +++ b/core/java/android/provider/DeviceConfig.java @@ -538,6 +538,13 @@ public final class DeviceConfig { public static final String NAMESPACE_WINDOW_MANAGER_NATIVE_BOOT = "window_manager_native_boot"; /** + * Definitions for voice interaction related functions. + * + * @hide + */ + public static final String NAMESPACE_VOICE_INTERACTION = "voice_interaction"; + + /** * List of namespaces which can be read without READ_DEVICE_CONFIG permission * * @hide diff --git a/core/java/android/security/keystore/recovery/WrappedApplicationKey.java b/core/java/android/security/keystore/recovery/WrappedApplicationKey.java index 0cb69a4da50f..61fd0416e3b2 100644 --- a/core/java/android/security/keystore/recovery/WrappedApplicationKey.java +++ b/core/java/android/security/keystore/recovery/WrappedApplicationKey.java @@ -167,10 +167,7 @@ public final class WrappedApplicationKey implements Parcelable { protected WrappedApplicationKey(Parcel in) { mAlias = in.readString(); mEncryptedKeyMaterial = in.createByteArray(); - // Check if there is still data to be read. - if (in.dataAvail() > 0) { - mMetadata = in.createByteArray(); - } + mMetadata = in.createByteArray(); } @Override diff --git a/core/java/android/service/gatekeeper/GateKeeperResponse.java b/core/java/android/service/gatekeeper/GateKeeperResponse.java index 7ed733cb4f4c..9d648a6995fb 100644 --- a/core/java/android/service/gatekeeper/GateKeeperResponse.java +++ b/core/java/android/service/gatekeeper/GateKeeperResponse.java @@ -105,7 +105,7 @@ public final class GateKeeperResponse implements Parcelable { dest.writeInt(mTimeout); } else if (mResponseCode == RESPONSE_OK) { dest.writeInt(mShouldReEnroll ? 1 : 0); - if (mPayload != null) { + if (mPayload != null && mPayload.length > 0) { dest.writeInt(mPayload.length); dest.writeByteArray(mPayload); } else { diff --git a/core/java/android/telephony/TelephonyRegistryManager.java b/core/java/android/telephony/TelephonyRegistryManager.java index 0d8b1f83b7fe..9c7f23e56617 100644 --- a/core/java/android/telephony/TelephonyRegistryManager.java +++ b/core/java/android/telephony/TelephonyRegistryManager.java @@ -38,7 +38,6 @@ import android.telephony.Annotation.RadioPowerState; import android.telephony.Annotation.SimActivationState; import android.telephony.Annotation.SrvccState; import android.telephony.TelephonyManager.CarrierPrivilegesCallback; -import android.telephony.TelephonyManager.CarrierPrivilegesListener; import android.telephony.emergency.EmergencyNumber; import android.telephony.ims.ImsReasonInfo; import android.util.ArraySet; @@ -1262,149 +1261,52 @@ public class TelephonyRegistryManager { pkgName, attributionTag, callback, new int[0], notifyNow); } - // TODO(b/216549778): Remove listener logic once all clients switch to CarrierPrivilegesCallback private static class CarrierPrivilegesCallbackWrapper extends ICarrierPrivilegesCallback.Stub implements ListenerExecutor { - // Either mListener or mCallback may be null, never both - @Nullable private final WeakReference<CarrierPrivilegesListener> mListener; - @Nullable private final WeakReference<CarrierPrivilegesCallback> mCallback; + @NonNull private final WeakReference<CarrierPrivilegesCallback> mCallback; @NonNull private final Executor mExecutor; CarrierPrivilegesCallbackWrapper( @NonNull CarrierPrivilegesCallback callback, @NonNull Executor executor) { - mListener = null; mCallback = new WeakReference<>(callback); mExecutor = executor; } - CarrierPrivilegesCallbackWrapper( - @NonNull CarrierPrivilegesListener listener, @NonNull Executor executor) { - mListener = new WeakReference<>(listener); - mCallback = null; - mExecutor = executor; - } - @Override public void onCarrierPrivilegesChanged( @NonNull List<String> privilegedPackageNames, @NonNull int[] privilegedUids) { - if (mListener != null) { - Binder.withCleanCallingIdentity( - () -> - executeSafely( - mExecutor, - mListener::get, - cpl -> - cpl.onCarrierPrivilegesChanged( - privilegedPackageNames, privilegedUids))); - } - - if (mCallback != null) { - // AIDL interface does not support Set, keep the List/Array and translate them here - Set<String> privilegedPkgNamesSet = Set.copyOf(privilegedPackageNames); - Set<Integer> privilegedUidsSet = Arrays.stream(privilegedUids).boxed().collect( - Collectors.toSet()); - Binder.withCleanCallingIdentity( - () -> - executeSafely( - mExecutor, - mCallback::get, - cpc -> - cpc.onCarrierPrivilegesChanged( - privilegedPkgNamesSet, privilegedUidsSet))); - } + // AIDL interface does not support Set, keep the List/Array and translate them here + Set<String> privilegedPkgNamesSet = Set.copyOf(privilegedPackageNames); + Set<Integer> privilegedUidsSet = Arrays.stream(privilegedUids).boxed().collect( + Collectors.toSet()); + Binder.withCleanCallingIdentity( + () -> + executeSafely( + mExecutor, + mCallback::get, + cpc -> + cpc.onCarrierPrivilegesChanged( + privilegedPkgNamesSet, privilegedUidsSet))); } @Override public void onCarrierServiceChanged(@Nullable String packageName, int uid) { - if (mCallback != null) { - Binder.withCleanCallingIdentity( - () -> - executeSafely( - mExecutor, - mCallback::get, - cpc -> cpc.onCarrierServiceChanged(packageName, uid))); - } + Binder.withCleanCallingIdentity( + () -> + executeSafely( + mExecutor, + mCallback::get, + cpc -> cpc.onCarrierServiceChanged(packageName, uid))); } } - // TODO(b/216549778): Change the map key to CarrierPrivilegesCallback once all clients switch to - // CarrierPrivilegesCallback. Before that, the key is either CarrierPrivilegesCallback or - // CarrierPrivilegesListener, no logic actually depends on the type. @NonNull @GuardedBy("sCarrierPrivilegeCallbacks") - private static final WeakHashMap<Object, WeakReference<CarrierPrivilegesCallbackWrapper>> + private static final WeakHashMap<CarrierPrivilegesCallback, + WeakReference<CarrierPrivilegesCallbackWrapper>> sCarrierPrivilegeCallbacks = new WeakHashMap<>(); /** - * Registers a {@link CarrierPrivilegesListener} on the given {@code logicalSlotIndex} to - * receive callbacks when the set of packages with carrier privileges changes. The callback will - * immediately be called with the latest state. - * - * @param logicalSlotIndex The SIM slot to listen on - * @param executor The executor where {@code listener} will be invoked - * @param listener The callback to register - * - * @deprecated Use {@link #addCarrierPrivilegesCallback} instead. This API will be removed - * prior to API finalization. - */ - @Deprecated - public void addCarrierPrivilegesListener( - int logicalSlotIndex, - @NonNull @CallbackExecutor Executor executor, - @NonNull CarrierPrivilegesListener listener) { - if (listener == null || executor == null) { - throw new IllegalArgumentException("listener and executor must be non-null"); - } - synchronized (sCarrierPrivilegeCallbacks) { - WeakReference<CarrierPrivilegesCallbackWrapper> existing = - sCarrierPrivilegeCallbacks.get(listener); - if (existing != null && existing.get() != null) { - Log.d(TAG, "addCarrierPrivilegesListener: listener already registered"); - return; - } - CarrierPrivilegesCallbackWrapper wrapper = - new CarrierPrivilegesCallbackWrapper(listener, executor); - sCarrierPrivilegeCallbacks.put(listener, new WeakReference<>(wrapper)); - try { - sRegistry.addCarrierPrivilegesCallback( - logicalSlotIndex, - wrapper, - mContext.getOpPackageName(), - mContext.getAttributionTag()); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - } - - /** - * Unregisters a {@link CarrierPrivilegesListener}. - * - * @param listener The callback to unregister - * - * @deprecated Use {@link #removeCarrierPrivilegesCallback} instead. The callback will prior - * to API finalization. - */ - @Deprecated - public void removeCarrierPrivilegesListener(@NonNull CarrierPrivilegesListener listener) { - if (listener == null) { - throw new IllegalArgumentException("listener must be non-null"); - } - synchronized (sCarrierPrivilegeCallbacks) { - WeakReference<CarrierPrivilegesCallbackWrapper> ref = - sCarrierPrivilegeCallbacks.remove(listener); - if (ref == null) return; - CarrierPrivilegesCallbackWrapper wrapper = ref.get(); - if (wrapper == null) return; - try { - sRegistry.removeCarrierPrivilegesCallback(wrapper, mContext.getOpPackageName()); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - } - - /** * Registers a {@link CarrierPrivilegesCallback} on the given {@code logicalSlotIndex} to * receive callbacks when the set of packages with carrier privileges changes. The callback will * immediately be called with the latest state. diff --git a/core/java/android/view/ViewRootInsetsControllerHost.java b/core/java/android/view/ViewRootInsetsControllerHost.java index efffa2b05a1e..aba79d5b87c3 100644 --- a/core/java/android/view/ViewRootInsetsControllerHost.java +++ b/core/java/android/view/ViewRootInsetsControllerHost.java @@ -171,8 +171,9 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host { public void setSystemBarsAppearance(int appearance, int mask) { mViewRoot.mWindowAttributes.privateFlags |= PRIVATE_FLAG_APPEARANCE_CONTROLLED; final InsetsFlags insetsFlags = mViewRoot.mWindowAttributes.insetsFlags; - if (insetsFlags.appearance != appearance) { - insetsFlags.appearance = (insetsFlags.appearance & ~mask) | (appearance & mask); + final int newAppearance = (insetsFlags.appearance & ~mask) | (appearance & mask); + if (insetsFlags.appearance != newAppearance) { + insetsFlags.appearance = newAppearance; mViewRoot.mWindowAttributesChanged = true; mViewRoot.scheduleTraversals(); } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 8e72f0f8da5d..dc393b674679 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -16318,8 +16318,8 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public void deletePendingTopUid(int uid) { - mPendingStartActivityUids.delete(uid); + public void deletePendingTopUid(int uid, long nowElapsed) { + mPendingStartActivityUids.delete(uid, nowElapsed); } @Override diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java index 96ea6db0c3f5..9e0441004568 100644 --- a/services/core/java/com/android/server/am/OomAdjuster.java +++ b/services/core/java/com/android/server/am/OomAdjuster.java @@ -1378,7 +1378,7 @@ public class OomAdjuster { mService.mServices.foregroundServiceProcStateChangedLocked(uidRec); } } - mService.mInternal.deletePendingTopUid(uidRec.getUid()); + mService.mInternal.deletePendingTopUid(uidRec.getUid(), nowElapsed); } if (mLocalPowerManager != null) { mLocalPowerManager.finishUidChanges(); diff --git a/services/core/java/com/android/server/am/PendingStartActivityUids.java b/services/core/java/com/android/server/am/PendingStartActivityUids.java index 6bf9d4e5c3f0..20f6bb205dc4 100644 --- a/services/core/java/com/android/server/am/PendingStartActivityUids.java +++ b/services/core/java/com/android/server/am/PendingStartActivityUids.java @@ -50,9 +50,15 @@ final class PendingStartActivityUids { } } - synchronized void delete(int uid) { + synchronized void delete(int uid, long nowElapsed) { final Pair<Integer, Long> pendingPid = mPendingUids.get(uid); if (pendingPid != null) { + if (nowElapsed < pendingPid.second) { + Slog.i(TAG, + "updateOomAdj start time is before than pendingPid added," + + " don't delete it"); + return; + } final long delay = SystemClock.elapsedRealtime() - pendingPid.second; if (delay >= 1000 /*ms*/) { Slog.i(TAG, @@ -75,4 +81,4 @@ final class PendingStartActivityUids { synchronized boolean isPendingTopUid(int uid) { return mPendingUids.get(uid) != null; } -}
\ No newline at end of file +} diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java index 406ff9b00686..f42d2742858d 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java +++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java @@ -251,8 +251,8 @@ import java.util.concurrent.atomic.AtomicBoolean; return; } } - setCommunicationRouteForClient( - cb, pid, device, BtHelper.SCO_MODE_UNDEFINED, eventSource); + postSetCommunicationRouteForClient(new CommunicationClientInfo( + cb, pid, device, BtHelper.SCO_MODE_UNDEFINED, eventSource)); } } } @@ -282,8 +282,8 @@ import java.util.concurrent.atomic.AtomicBoolean; return false; } } - setCommunicationRouteForClient( - cb, pid, deviceAttr, BtHelper.SCO_MODE_UNDEFINED, eventSource); + postSetCommunicationRouteForClient(new CommunicationClientInfo( + cb, pid, deviceAttr, BtHelper.SCO_MODE_UNDEFINED, eventSource)); } } return true; @@ -347,26 +347,35 @@ import java.util.concurrent.atomic.AtomicBoolean; } /** - * Returns the device currently requested for communication use case. - * If the current audio mode owner is in the communication route client list, - * use this preference. - * Otherwise use first client's preference (first client corresponds to latest request). - * null is returned if no client is in the list. - * @return AudioDeviceAttributes the requested device for communication. + * Returns the communication client with the highest priority: + * - 1) the client which is currently also controlling the audio mode + * - 2) the first client in the stack if there is no audio mode owner + * - 3) no client otherwise + * @return CommunicationRouteClient the client driving the communication use case routing. */ - @GuardedBy("mDeviceStateLock") - private AudioDeviceAttributes requestedCommunicationDevice() { - AudioDeviceAttributes device = null; - for (CommunicationRouteClient cl : mCommunicationRouteClients) { - if (cl.getPid() == mModeOwnerPid) { - device = cl.getDevice(); + private CommunicationRouteClient topCommunicationRouteClient() { + for (CommunicationRouteClient crc : mCommunicationRouteClients) { + if (crc.getPid() == mModeOwnerPid) { + return crc; } } if (!mCommunicationRouteClients.isEmpty() && mModeOwnerPid == 0) { - device = mCommunicationRouteClients.get(0).getDevice(); + return mCommunicationRouteClients.get(0); } + return null; + } + /** + * Returns the device currently requested for communication use case. + * Use the device requested by the communication route client selected by + * {@link #topCommunicationRouteClient()} if any or none otherwise. + * @return AudioDeviceAttributes the requested device for communication. + */ + @GuardedBy("mDeviceStateLock") + private AudioDeviceAttributes requestedCommunicationDevice() { + CommunicationRouteClient crc = topCommunicationRouteClient(); + AudioDeviceAttributes device = crc != null ? crc.getDevice() : null; if (AudioService.DEBUG_COMM_RTE) { Log.v(TAG, "requestedCommunicationDevice, device: " + device + " mode owner pid: " + mModeOwnerPid); @@ -696,7 +705,7 @@ import java.util.concurrent.atomic.AtomicBoolean; } synchronized (mDeviceStateLock) { mBluetoothScoOn = on; - sendLMsgNoDelay(MSG_L_UPDATE_COMMUNICATION_ROUTE, SENDMSG_QUEUE, eventSource); + postUpdateCommunicationRouteClient(eventSource); } } @@ -756,7 +765,9 @@ import java.util.concurrent.atomic.AtomicBoolean; synchronized (mDeviceStateLock) { AudioDeviceAttributes device = new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO, ""); - setCommunicationRouteForClient(cb, pid, device, scoAudioMode, eventSource); + + postSetCommunicationRouteForClient(new CommunicationClientInfo( + cb, pid, device, scoAudioMode, eventSource)); } } } @@ -774,8 +785,8 @@ import java.util.concurrent.atomic.AtomicBoolean; if (client == null || !client.requestsBluetoothSco()) { return; } - setCommunicationRouteForClient( - cb, pid, null, BtHelper.SCO_MODE_UNDEFINED, eventSource); + postSetCommunicationRouteForClient(new CommunicationClientInfo( + cb, pid, null, BtHelper.SCO_MODE_UNDEFINED, eventSource)); } } } @@ -976,6 +987,61 @@ import java.util.concurrent.atomic.AtomicBoolean; MSG_I_SAVE_CLEAR_PREF_DEVICES_FOR_CAPTURE_PRESET, SENDMSG_QUEUE, capturePreset); } + /*package*/ void postUpdateCommunicationRouteClient(String eventSource) { + sendLMsgNoDelay(MSG_L_UPDATE_COMMUNICATION_ROUTE_CLIENT, SENDMSG_QUEUE, eventSource); + } + + /*package*/ void postSetCommunicationRouteForClient(CommunicationClientInfo info) { + sendLMsgNoDelay(MSG_L_SET_COMMUNICATION_ROUTE_FOR_CLIENT, SENDMSG_QUEUE, info); + } + + /*package*/ void postScoAudioStateChanged(int state) { + sendIMsgNoDelay(MSG_I_SCO_AUDIO_STATE_CHANGED, SENDMSG_QUEUE, state); + } + + /*package*/ static final class CommunicationClientInfo { + final @NonNull IBinder mCb; + final int mPid; + final @NonNull AudioDeviceAttributes mDevice; + final int mScoAudioMode; + final @NonNull String mEventSource; + + CommunicationClientInfo(@NonNull IBinder cb, int pid, @NonNull AudioDeviceAttributes device, + int scoAudioMode, @NonNull String eventSource) { + mCb = cb; + mPid = pid; + mDevice = device; + mScoAudioMode = scoAudioMode; + mEventSource = eventSource; + } + + // redefine equality op so we can match messages intended for this client + @Override + public boolean equals(Object o) { + if (o == null) { + return false; + } + if (this == o) { + return true; + } + if (!(o instanceof CommunicationClientInfo)) { + return false; + } + + return mCb.equals(((CommunicationClientInfo) o).mCb) + && mPid == ((CommunicationClientInfo) o).mPid; + } + + @Override + public String toString() { + return "CommunicationClientInfo mCb=" + mCb.toString() + +"mPid=" + mPid + +"mDevice=" + mDevice.toString() + +"mScoAudioMode=" + mScoAudioMode + +"mEventSource=" + mEventSource; + } + } + //--------------------------------------------------------------------- // Method forwarding between the helper classes (BtHelper, AudioDeviceInventory) // only call from a "handle"* method or "on"* method @@ -1252,18 +1318,30 @@ import java.util.concurrent.atomic.AtomicBoolean; synchronized (mDeviceStateLock) { mModeOwnerPid = msg.arg1; if (msg.arg2 != AudioSystem.MODE_RINGTONE) { - onUpdateCommunicationRoute("setNewModeOwner"); + onUpdateCommunicationRouteClient("setNewModeOwner"); } } } break; - case MSG_L_COMMUNICATION_ROUTE_CLIENT_DIED: + + case MSG_L_SET_COMMUNICATION_ROUTE_FOR_CLIENT: synchronized (mSetModeLock) { synchronized (mDeviceStateLock) { - onCommunicationRouteClientDied((CommunicationRouteClient) msg.obj); + CommunicationClientInfo info = (CommunicationClientInfo) msg.obj; + setCommunicationRouteForClient(info.mCb, info.mPid, info.mDevice, + info.mScoAudioMode, info.mEventSource); + } + } + break; + + case MSG_L_UPDATE_COMMUNICATION_ROUTE_CLIENT: + synchronized (mSetModeLock) { + synchronized (mDeviceStateLock) { + onUpdateCommunicationRouteClient((String) msg.obj); } } break; + case MSG_L_UPDATE_COMMUNICATION_ROUTE: synchronized (mSetModeLock) { synchronized (mDeviceStateLock) { @@ -1271,6 +1349,23 @@ import java.util.concurrent.atomic.AtomicBoolean; } } break; + + case MSG_L_COMMUNICATION_ROUTE_CLIENT_DIED: + synchronized (mSetModeLock) { + synchronized (mDeviceStateLock) { + onCommunicationRouteClientDied((CommunicationRouteClient) msg.obj); + } + } + break; + + case MSG_I_SCO_AUDIO_STATE_CHANGED: + synchronized (mSetModeLock) { + synchronized (mDeviceStateLock) { + mBtHelper.onScoAudioStateChanged(msg.arg1); + } + } + break; + case MSG_TOGGLE_HDMI: synchronized (mDeviceStateLock) { mDeviceInventory.onToggleHdmi(); @@ -1424,6 +1519,9 @@ import java.util.concurrent.atomic.AtomicBoolean; private static final int MSG_L_UPDATE_COMMUNICATION_ROUTE = 39; private static final int MSG_IL_SET_PREF_DEVICES_FOR_STRATEGY = 40; private static final int MSG_I_REMOVE_PREF_DEVICES_FOR_STRATEGY = 41; + private static final int MSG_L_SET_COMMUNICATION_ROUTE_FOR_CLIENT = 42; + private static final int MSG_L_UPDATE_COMMUNICATION_ROUTE_CLIENT = 43; + private static final int MSG_I_SCO_AUDIO_STATE_CHANGED = 44; private static final int MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT = 45; // @@ -1642,9 +1740,8 @@ import java.util.concurrent.atomic.AtomicBoolean; return; } Log.w(TAG, "Communication client died"); - setCommunicationRouteForClient( - client.getBinder(), client.getPid(), null, BtHelper.SCO_MODE_UNDEFINED, - "onCommunicationRouteClientDied"); + removeCommunicationRouteClient(client.getBinder(), true); + onUpdateCommunicationRouteClient("onCommunicationRouteClientDied"); } /** @@ -1698,11 +1795,31 @@ import java.util.concurrent.atomic.AtomicBoolean; AudioSystem.setParameters("BT_SCO=on"); } if (preferredCommunicationDevice == null) { - postRemovePreferredDevicesForStrategy(mCommunicationStrategyId); + removePreferredDevicesForStrategySync(mCommunicationStrategyId); } else { - postSetPreferredDevicesForStrategy( + setPreferredDevicesForStrategySync( mCommunicationStrategyId, Arrays.asList(preferredCommunicationDevice)); } + onUpdatePhoneStrategyDevice(preferredCommunicationDevice); + } + + /** + * Select new communication device from communication route client at the top of the stack + * and restore communication route including restarting SCO audio if needed. + */ + // @GuardedBy("mSetModeLock") + @GuardedBy("mDeviceStateLock") + private void onUpdateCommunicationRouteClient(String eventSource) { + onUpdateCommunicationRoute(eventSource); + CommunicationRouteClient crc = topCommunicationRouteClient(); + if (AudioService.DEBUG_COMM_RTE) { + Log.v(TAG, "onUpdateCommunicationRouteClient, crc: " + + crc + " eventSource: " + eventSource); + } + if (crc != null) { + setCommunicationRouteForClient(crc.getBinder(), crc.getPid(), crc.getDevice(), + BtHelper.SCO_MODE_UNDEFINED, eventSource); + } } private void onUpdatePhoneStrategyDevice(AudioDeviceAttributes device) { diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index de4161163723..a3c6f0a68c78 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -1102,6 +1102,7 @@ public class AudioDeviceInventory { mConnectedDevices.put(DeviceInfo.makeDeviceListKey(device, address), new DeviceInfo(device, name, address, AudioSystem.AUDIO_FORMAT_DEFAULT)); mDeviceBroker.postAccessoryPlugMediaUnmute(device); + setCurrentAudioRouteNameIfPossible(name, /*fromA2dp=*/false); } if (streamType == AudioSystem.STREAM_DEFAULT) { diff --git a/services/core/java/com/android/server/audio/BtHelper.java b/services/core/java/com/android/server/audio/BtHelper.java index 4485c5b6d61a..7d9173d0561e 100644 --- a/services/core/java/com/android/server/audio/BtHelper.java +++ b/services/core/java/com/android/server/audio/BtHelper.java @@ -103,7 +103,7 @@ public class BtHelper { // SCO audio mode is virtual voice call (BluetoothHeadset.startScoUsingVirtualVoiceCall()) /*package*/ static final int SCO_MODE_VIRTUAL_CALL = 0; // SCO audio mode is Voice Recognition (BluetoothHeadset.startVoiceRecognition()) - private static final int SCO_MODE_VR = 2; + private static final int SCO_MODE_VR = 2; // max valid SCO audio mode values private static final int SCO_MODE_MAX = 2; @@ -304,68 +304,76 @@ public class BtHelper { BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); setBtScoActiveDevice(btDevice); } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) { - boolean broadcast = false; - int scoAudioState = AudioManager.SCO_AUDIO_STATE_ERROR; int btState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1); - Log.i(TAG, "receiveBtEvent ACTION_AUDIO_STATE_CHANGED: " + btState); - switch (btState) { - case BluetoothHeadset.STATE_AUDIO_CONNECTED: - scoAudioState = AudioManager.SCO_AUDIO_STATE_CONNECTED; - if (mScoAudioState != SCO_STATE_ACTIVE_INTERNAL - && mScoAudioState != SCO_STATE_DEACTIVATE_REQ) { - mScoAudioState = SCO_STATE_ACTIVE_EXTERNAL; - } else if (mDeviceBroker.isBluetoothScoRequested()) { - // broadcast intent if the connection was initated by AudioService - broadcast = true; - } - mDeviceBroker.setBluetoothScoOn(true, "BtHelper.receiveBtEvent"); - break; - case BluetoothHeadset.STATE_AUDIO_DISCONNECTED: - mDeviceBroker.setBluetoothScoOn(false, "BtHelper.receiveBtEvent"); - scoAudioState = AudioManager.SCO_AUDIO_STATE_DISCONNECTED; - // There are two cases where we want to immediately reconnect audio: - // 1) If a new start request was received while disconnecting: this was - // notified by requestScoState() setting state to SCO_STATE_ACTIVATE_REQ. - // 2) If audio was connected then disconnected via Bluetooth APIs and - // we still have pending activation requests by apps: this is indicated by - // state SCO_STATE_ACTIVE_EXTERNAL and BT SCO is requested. - if (mScoAudioState == SCO_STATE_ACTIVATE_REQ - || (mScoAudioState == SCO_STATE_ACTIVE_EXTERNAL - && mDeviceBroker.isBluetoothScoRequested())) { - if (mBluetoothHeadset != null && mBluetoothHeadsetDevice != null - && connectBluetoothScoAudioHelper(mBluetoothHeadset, - mBluetoothHeadsetDevice, mScoAudioMode)) { - mScoAudioState = SCO_STATE_ACTIVE_INTERNAL; - scoAudioState = AudioManager.SCO_AUDIO_STATE_CONNECTING; - broadcast = true; - break; - } - } - if (mScoAudioState != SCO_STATE_ACTIVE_EXTERNAL) { + Log.i(TAG,"receiveBtEvent ACTION_AUDIO_STATE_CHANGED: "+btState); + mDeviceBroker.postScoAudioStateChanged(btState); + } + } + + /** + * Exclusively called from AudioDeviceBroker when handling MSG_I_SCO_AUDIO_STATE_CHANGED + * as part of the serialization of the communication route selection + */ + // @GuardedBy("AudioDeviceBroker.mSetModeLock") + @GuardedBy("AudioDeviceBroker.mDeviceStateLock") + void onScoAudioStateChanged(int state) { + boolean broadcast = false; + int scoAudioState = AudioManager.SCO_AUDIO_STATE_ERROR; + switch (state) { + case BluetoothHeadset.STATE_AUDIO_CONNECTED: + scoAudioState = AudioManager.SCO_AUDIO_STATE_CONNECTED; + if (mScoAudioState != SCO_STATE_ACTIVE_INTERNAL + && mScoAudioState != SCO_STATE_DEACTIVATE_REQ) { + mScoAudioState = SCO_STATE_ACTIVE_EXTERNAL; + } else if (mDeviceBroker.isBluetoothScoRequested()) { + // broadcast intent if the connection was initated by AudioService + broadcast = true; + } + mDeviceBroker.setBluetoothScoOn(true, "BtHelper.receiveBtEvent"); + break; + case BluetoothHeadset.STATE_AUDIO_DISCONNECTED: + mDeviceBroker.setBluetoothScoOn(false, "BtHelper.receiveBtEvent"); + scoAudioState = AudioManager.SCO_AUDIO_STATE_DISCONNECTED; + // There are two cases where we want to immediately reconnect audio: + // 1) If a new start request was received while disconnecting: this was + // notified by requestScoState() setting state to SCO_STATE_ACTIVATE_REQ. + // 2) If audio was connected then disconnected via Bluetooth APIs and + // we still have pending activation requests by apps: this is indicated by + // state SCO_STATE_ACTIVE_EXTERNAL and BT SCO is requested. + if (mScoAudioState == SCO_STATE_ACTIVATE_REQ) { + if (mBluetoothHeadset != null && mBluetoothHeadsetDevice != null + && connectBluetoothScoAudioHelper(mBluetoothHeadset, + mBluetoothHeadsetDevice, mScoAudioMode)) { + mScoAudioState = SCO_STATE_ACTIVE_INTERNAL; + scoAudioState = AudioManager.SCO_AUDIO_STATE_CONNECTING; broadcast = true; + break; } - mScoAudioState = SCO_STATE_INACTIVE; - break; - case BluetoothHeadset.STATE_AUDIO_CONNECTING: - if (mScoAudioState != SCO_STATE_ACTIVE_INTERNAL - && mScoAudioState != SCO_STATE_DEACTIVATE_REQ) { - mScoAudioState = SCO_STATE_ACTIVE_EXTERNAL; - } - break; - default: - break; - } - if (broadcast) { - broadcastScoConnectionState(scoAudioState); - //FIXME: this is to maintain compatibility with deprecated intent - // AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED. Remove when appropriate. - Intent newIntent = new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED); - newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, scoAudioState); - sendStickyBroadcastToAll(newIntent); - } + } + if (mScoAudioState != SCO_STATE_ACTIVE_EXTERNAL) { + broadcast = true; + } + mScoAudioState = SCO_STATE_INACTIVE; + break; + case BluetoothHeadset.STATE_AUDIO_CONNECTING: + if (mScoAudioState != SCO_STATE_ACTIVE_INTERNAL + && mScoAudioState != SCO_STATE_DEACTIVATE_REQ) { + mScoAudioState = SCO_STATE_ACTIVE_EXTERNAL; + } + break; + default: + break; + } + if(broadcast) { + broadcastScoConnectionState(scoAudioState); + //FIXME: this is to maintain compatibility with deprecated intent + // AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED. Remove when appropriate. + Intent newIntent = new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED); + newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, scoAudioState); + sendStickyBroadcastToAll(newIntent); } - } + } /** * * @return false if SCO isn't connected @@ -744,6 +752,15 @@ public class BtHelper { case SCO_STATE_ACTIVE_INTERNAL: Log.w(TAG, "requestScoState: already in ACTIVE mode, simply return"); break; + case SCO_STATE_ACTIVE_EXTERNAL: + /* Confirm SCO Audio connection to requesting app as it is already connected + * externally (i.e. through SCO APIs by Telecom service). + * Once SCO Audio is disconnected by the external owner, we will reconnect it + * automatically on behalf of the requesting app and the state will move to + * SCO_STATE_ACTIVE_INTERNAL. + */ + broadcastScoConnectionState(AudioManager.SCO_AUDIO_STATE_CONNECTED); + break; default: Log.w(TAG, "requestScoState: failed to connect in state " + mScoAudioState + ", scoAudioMode=" + scoAudioMode); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityTaskSupervisorTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityTaskSupervisorTests.java index 66da2a631868..716612c70aef 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityTaskSupervisorTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityTaskSupervisorTests.java @@ -284,7 +284,7 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase { .setCreateActivity(true).build().getTopMostActivity(); activity2.getTask().setResumedActivity(activity2, "test"); - mAtm.mAmInternal.deletePendingTopUid(activity1.getUid()); + mAtm.mAmInternal.deletePendingTopUid(activity1.getUid(), Long.MAX_VALUE); clearInvocations(mAtm); activity1.moveFocusableActivityToTop("test"); assertTrue(mAtm.mAmInternal.isPendingTopUid(activity1.getUid())); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index d7a5f0a52ddf..fd3b18a7b6d4 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -67,6 +67,7 @@ import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SharedMemory; +import android.provider.DeviceConfig; import android.service.voice.HotwordDetectedResult; import android.service.voice.HotwordDetectionService; import android.service.voice.HotwordRejectedResult; @@ -109,12 +110,20 @@ final class HotwordDetectionConnection { private static final String TAG = "HotwordDetectionConnection"; static final boolean DEBUG = false; + private static final String KEY_RESTART_PERIOD_IN_SECONDS = "restart_period_in_seconds"; // TODO: These constants need to be refined. private static final long VALIDATION_TIMEOUT_MILLIS = 4000; private static final long MAX_UPDATE_TIMEOUT_MILLIS = 6000; private static final Duration MAX_UPDATE_TIMEOUT_DURATION = Duration.ofMillis(MAX_UPDATE_TIMEOUT_MILLIS); private static final long RESET_DEBUG_HOTWORD_LOGGING_TIMEOUT_MILLIS = 60 * 60 * 1000; // 1 hour + /** + * Time after which each HotwordDetectionService process is stopped and replaced by a new one. + * 0 indicates no restarts. + */ + private static final int RESTART_PERIOD_SECONDS = + DeviceConfig.getInt(DeviceConfig.NAMESPACE_VOICE_INTERACTION, + KEY_RESTART_PERIOD_IN_SECONDS, 3600); // 60 minutes by default private static final int MAX_ISOLATED_PROCESS_NUMBER = 10; // Hotword metrics @@ -133,6 +142,7 @@ final class HotwordDetectionConnection { // TODO: This may need to be a Handler(looper) private final ScheduledExecutorService mScheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); + @Nullable private final ScheduledFuture<?> mCancellationTaskFuture; private final AtomicBoolean mUpdateStateAfterStartFinished = new AtomicBoolean(false); private final IBinder.DeathRecipient mAudioServerDeathRecipient = this::audioServerDied; private final @NonNull ServiceConnectionFactory mServiceConnectionFactory; @@ -148,7 +158,6 @@ final class HotwordDetectionConnection { private IMicrophoneHotwordDetectionVoiceInteractionCallback mSoftwareCallback; private Instant mLastRestartInstant; - private ScheduledFuture<?> mCancellationTaskFuture; private ScheduledFuture<?> mCancellationKeyPhraseDetectionFuture; private ScheduledFuture<?> mDebugHotwordLoggingTimeoutFuture = null; @@ -194,16 +203,20 @@ final class HotwordDetectionConnection { mLastRestartInstant = Instant.now(); updateStateAfterProcessStart(options, sharedMemory); - // TODO(volnov): we need to be smarter here, e.g. schedule it a bit more often, but wait - // until the current session is closed. - mCancellationTaskFuture = mScheduledExecutorService.scheduleAtFixedRate(() -> { - Slog.v(TAG, "Time to restart the process, TTL has passed"); - synchronized (mLock) { - restartProcessLocked(); - HotwordMetricsLogger.writeServiceRestartEvent(mDetectorType, - HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__SCHEDULE); - } - }, 30, 30, TimeUnit.MINUTES); + if (RESTART_PERIOD_SECONDS <= 0) { + mCancellationTaskFuture = null; + } else { + // TODO(volnov): we need to be smarter here, e.g. schedule it a bit more often, but wait + // until the current session is closed. + mCancellationTaskFuture = mScheduledExecutorService.scheduleAtFixedRate(() -> { + Slog.v(TAG, "Time to restart the process, TTL has passed"); + synchronized (mLock) { + restartProcessLocked(); + HotwordMetricsLogger.writeServiceRestartEvent(mDetectorType, + HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__SCHEDULE); + } + }, RESTART_PERIOD_SECONDS, RESTART_PERIOD_SECONDS, TimeUnit.SECONDS); + } } private void initAudioFlingerLocked() { @@ -341,7 +354,9 @@ final class HotwordDetectionConnection { .setHotwordDetectionServiceProvider(null); mIdentity = null; updateServiceUidForAudioPolicy(Process.INVALID_UID); - mCancellationTaskFuture.cancel(/* may interrupt */ true); + if (mCancellationTaskFuture != null) { + mCancellationTaskFuture.cancel(/* may interrupt */ true); + } if (mAudioFlinger != null) { mAudioFlinger.unlinkToDeath(mAudioServerDeathRecipient, /* flags= */ 0); } @@ -759,6 +774,7 @@ final class HotwordDetectionConnection { } public void dump(String prefix, PrintWriter pw) { + pw.print(prefix); pw.print("RESTART_PERIOD_SECONDS="); pw.println(RESTART_PERIOD_SECONDS); pw.print(prefix); pw.print("mBound=" + mRemoteHotwordDetectionService.isBound()); pw.print(", mValidatingDspTrigger=" + mValidatingDspTrigger); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index cdba6355e798..db1f49760865 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -16426,32 +16426,6 @@ public class TelephonyManager { } /** - * Callback to listen for when the set of packages with carrier privileges for a SIM changes. - * - * @hide - * @deprecated Use {@link CarrierPrivilegesCallback} instead. This API will be removed soon - * prior to API finalization. - */ - @Deprecated - @SystemApi - public interface CarrierPrivilegesListener { - /** - * Called when the set of packages with carrier privileges has changed. - * - * <p>Of note, this callback will <b>not</b> be fired if a carrier triggers a SIM profile - * switch and the same set of packages remains privileged after the switch. - * - * <p>At registration, the callback will receive the current set of privileged packages. - * - * @param privilegedPackageNames The updated set of package names that have carrier - * privileges - * @param privilegedUids The updated set of UIDs that have carrier privileges - */ - void onCarrierPrivilegesChanged( - @NonNull List<String> privilegedPackageNames, @NonNull int[] privilegedUids); - } - - /** * Callbacks to listen for when the set of packages with carrier privileges for a SIM changes. * * <p>Of note, when multiple callbacks are registered, they may be triggered one after another. @@ -16500,61 +16474,6 @@ public class TelephonyManager { } /** - * Registers a {@link CarrierPrivilegesListener} on the given {@code logicalSlotIndex} to - * receive callbacks when the set of packages with carrier privileges changes. The callback will - * immediately be called with the latest state. - * - * @param logicalSlotIndex The SIM slot to listen on - * @param executor The executor where {@code listener} will be invoked - * @param listener The callback to register - * @hide - * @deprecated Use {@link #registerCarrierPrivilegesCallback} instead. This API will be - * removed prior to API finalization. - */ - @Deprecated - @SystemApi - @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public void addCarrierPrivilegesListener( - int logicalSlotIndex, - @NonNull @CallbackExecutor Executor executor, - @NonNull CarrierPrivilegesListener listener) { - if (mContext == null) { - throw new IllegalStateException("Telephony service is null"); - } else if (executor == null || listener == null) { - throw new IllegalArgumentException( - "CarrierPrivilegesListener and executor must be non-null"); - } - mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class); - if (mTelephonyRegistryMgr == null) { - throw new IllegalStateException("Telephony registry service is null"); - } - mTelephonyRegistryMgr.addCarrierPrivilegesListener(logicalSlotIndex, executor, listener); - } - - /** - * Unregisters an existing {@link CarrierPrivilegesListener}. - * - * @hide - * @deprecated Use {@link #unregisterCarrierPrivilegesCallback} instead. This API will be - * removed prior to API finalization. - */ - @Deprecated - @SystemApi - @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public void removeCarrierPrivilegesListener(@NonNull CarrierPrivilegesListener listener) { - if (mContext == null) { - throw new IllegalStateException("Telephony service is null"); - } else if (listener == null) { - throw new IllegalArgumentException("CarrierPrivilegesListener must be non-null"); - } - mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class); - if (mTelephonyRegistryMgr == null) { - throw new IllegalStateException("Telephony registry service is null"); - } - mTelephonyRegistryMgr.removeCarrierPrivilegesListener(listener); - } - - /** * Registers a {@link CarrierPrivilegesCallback} on the given {@code logicalSlotIndex} to * receive callbacks when the set of packages with carrier privileges changes. The callback will * immediately be called with the latest state. |