summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-21 10:15:48 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-21 10:15:48 +0000
commit331734faa0ae2802e9c2a2976f39809ec4c85147 (patch)
tree6147862976a91d97b4f846ab1c8f34e4ae06cd6e
parentd9b68a9f5b630d57a37a789034a6f5ca78e0d8fb (diff)
parente70e4b67aa32a8e8cf9f07467903f1fcbb3ae5f4 (diff)
Snap for 8748053 from e70e4b67aa32a8e8cf9f07467903f1fcbb3ae5f4 to s-keystone-qcom-release
Change-Id: Iae0e9c248171548fb95bcd97c1e7d02a4055fcc0
-rw-r--r--services/core/java/com/android/server/BluetoothManagerService.java26
-rw-r--r--services/core/jni/com_android_server_am_CachedAppOptimizer.cpp79
2 files changed, 73 insertions, 32 deletions
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index 806ea95424a7..1ed5840c4ab4 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -2031,9 +2031,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
case MESSAGE_ENABLE:
int quietEnable = msg.arg1;
int isBle = msg.arg2;
+ Slog.d(TAG, "MESSAGE_ENABLE: isBle: " + isBle + " msg.obj : " + msg.obj);
if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
|| mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
- if (msg.arg2 == 0) {
+ if (msg.obj == null) {
int delay = ENABLE_DISABLE_DELAY_MS;
if (mHandler.hasMessages(MESSAGE_DISABLE)) {
@@ -2044,11 +2045,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mHandler.removeMessages(MESSAGE_ENABLE);
// We are handling enable or disable right now, wait for it.
mHandler.sendMessageDelayed(mHandler.obtainMessage(
- MESSAGE_ENABLE, quietEnable, 1), delay);
+ MESSAGE_ENABLE, quietEnable, isBle, 1), delay);
Slog.d(TAG, "Queue new MESSAGE_ENABLE");
} else {
mHandler.sendMessageDelayed(mHandler.obtainMessage(
- MESSAGE_ENABLE, quietEnable, 1), ENABLE_DISABLE_DELAY_MS);
+ MESSAGE_ENABLE, quietEnable, isBle, 1), ENABLE_DISABLE_DELAY_MS);
Slog.d(TAG, "Re-Queue previous MESSAGE_ENABLE");
if (mHandler.hasMessages(MESSAGE_DISABLE)) {
// Ensure the original order of just entering the queue
@@ -2060,10 +2061,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
}
break;
- } else if(msg.arg2 == 0 && mHandler.hasMessages(MESSAGE_DISABLE)) {
+ } else if(msg.obj == null && mHandler.hasMessages(MESSAGE_DISABLE)) {
mHandler.removeMessages(MESSAGE_ENABLE);
mHandler.sendMessageDelayed(mHandler.obtainMessage(
- MESSAGE_ENABLE, quietEnable, 1), ENABLE_DISABLE_DELAY_MS * 2);
+ MESSAGE_ENABLE, quietEnable, isBle, 1), ENABLE_DISABLE_DELAY_MS * 2);
Slog.d(TAG, "MESSAGE_DISABLE exist. Queue new MESSAGE_ENABLE");
break;
}
@@ -2088,11 +2089,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
int state = mBluetooth.getState();
switch (state) {
case BluetoothAdapter.STATE_BLE_ON:
- if (isBle == 1) {
- Slog.i(TAG, "Already at BLE_ON State");
- } else {
- Slog.w(TAG, "BT Enable in BLE_ON State, going to ON");
+ if (isBluetoothPersistedStateOnBluetooth() ||
+ mEnableExternal) {
+ Slog.w(TAG, "BLE_ON State:Enable from Settings or" +
+ "BT on persisted, going to ON");
mBluetooth.onLeServiceUp(mContext.getAttributionSource());
+ } else if (isBle == 1) {
+ Slog.w(TAG, "BLE_ON State:Queued enable from ble app," +
+ " stay in ble on");
}
break;
case BluetoothAdapter.STATE_BLE_TURNING_ON:
@@ -2165,8 +2169,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
// if MESSAGE_DISABLE present
mHandler.removeMessages(MESSAGE_ENABLE);
mHandler.sendMessageDelayed(mHandler.obtainMessage(
- MESSAGE_ENABLE, mQuietEnableExternal ? 1: 0, 1),
- ENABLE_DISABLE_DELAY_MS * 2);
+ MESSAGE_ENABLE, mQuietEnableExternal ? 1: 0,
+ mEnableExternal ? 0:1, 1), ENABLE_DISABLE_DELAY_MS * 2);
Slog.d(TAG, "Re-Queue previous MESSAGE_ENABLE");
}
}
diff --git a/services/core/jni/com_android_server_am_CachedAppOptimizer.cpp b/services/core/jni/com_android_server_am_CachedAppOptimizer.cpp
index 619b612b0374..636ca4143a33 100644
--- a/services/core/jni/com_android_server_am_CachedAppOptimizer.cpp
+++ b/services/core/jni/com_android_server_am_CachedAppOptimizer.cpp
@@ -88,9 +88,7 @@ static inline void compactProcessProcfs(int pid, const std::string& compactionTy
// If any VMA fails compaction due to -EINVAL it will be skipped and continue.
// However, if it fails for any other reason, it will bail out and forward the error
static int64_t compactMemory(const std::vector<Vma>& vmas, int pid, int madviseType) {
- // UIO_MAXIOV is currently a small value and we might have more addresses
- // we do multiple syscalls if we exceed its maximum
- static struct iovec vmasToKernel[UIO_MAXIOV];
+ static struct iovec vmasToKernel[MAX_VMAS_PER_COMPACTION];
if (vmas.empty()) {
return 0;
@@ -104,33 +102,72 @@ static int64_t compactMemory(const std::vector<Vma>& vmas, int pid, int madviseT
compactionInProgress = true;
cancelRunningCompaction = false;
- int64_t totalBytesCompacted = 0;
- for (int iBase = 0; iBase < vmas.size(); iBase += UIO_MAXIOV) {
- if (CC_UNLIKELY(cancelRunningCompaction)) {
- // There could be a significant delay betweenwhen a compaction
- // is requested and when it is handled during this time
- // our OOM adjust could have improved.
+ int64_t totalBytesProcessed = 0;
+
+ int64_t vmaOffset = 0;
+ for (int iVma = 0; iVma < vmas.size();) {
+ uint64_t bytesSentToCompact = 0;
+ int iVec = 0;
+ while (iVec < MAX_VMAS_PER_COMPACTION && iVma < vmas.size()) {
+ if (CC_UNLIKELY(cancelRunningCompaction)) {
+ // There could be a significant delay between when a compaction
+ // is requested and when it is handled during this time our
+ // OOM adjust could have improved.
+ LOG(DEBUG) << "Cancelled running compaction for " << pid;
+ break;
+ }
+
+ uint64_t vmaStart = vmas[iVma].start + vmaOffset;
+ uint64_t vmaSize = vmas[iVma].end - vmaStart;
+ if (vmaSize == 0) {
+ goto next_vma;
+ }
+ vmasToKernel[iVec].iov_base = (void*)vmaStart;
+ if (vmaSize > MAX_BYTES_PER_COMPACTION - bytesSentToCompact) {
+ // Exceeded the max bytes that could be sent, so clamp
+ // the end to avoid exceeding limit and issue compaction
+ vmaSize = MAX_BYTES_PER_COMPACTION - bytesSentToCompact;
+ }
+
+ vmasToKernel[iVec].iov_len = vmaSize;
+ bytesSentToCompact += vmaSize;
+ ++iVec;
+ if (bytesSentToCompact >= MAX_BYTES_PER_COMPACTION) {
+ // Ran out of bytes within iovec, dispatch compaction.
+ vmaOffset += vmaSize;
+ break;
+ }
+
+ next_vma:
+ // Finished current VMA, and have more bytes remaining
+ vmaOffset = 0;
+ ++iVma;
+ }
+
+ if (cancelRunningCompaction) {
cancelRunningCompaction = false;
break;
}
- int totalVmasToKernel = std::min(UIO_MAXIOV, (int)(vmas.size() - iBase));
- for (int iVec = 0, iVma = iBase; iVec < totalVmasToKernel; ++iVec, ++iVma) {
- vmasToKernel[iVec].iov_base = (void*)vmas[iVma].start;
- vmasToKernel[iVec].iov_len = vmas[iVma].end - vmas[iVma].start;
- }
- auto bytesCompacted =
- process_madvise(pidfd, vmasToKernel, totalVmasToKernel, madviseType, 0);
- if (CC_UNLIKELY(bytesCompacted == -1)) {
- compactionInProgress = false;
- return -errno;
+ auto bytesProcessed = process_madvise(pidfd, vmasToKernel, iVec, madviseType, 0);
+
+ if (CC_UNLIKELY(bytesProcessed == -1)) {
+ if (errno == EINVAL) {
+ // This error is somewhat common due to an unevictable VMA if this is
+ // the case silently skip the bad VMA and continue compacting the rest.
+ continue;
+ } else {
+ // Forward irrecoverable errors and bail out compaction
+ compactionInProgress = false;
+ return -errno;
+ }
}
- totalBytesCompacted += bytesCompacted;
+ totalBytesProcessed += bytesProcessed;
}
compactionInProgress = false;
- return totalBytesCompacted;
+ return totalBytesProcessed;
}
static int getFilePageAdvice(const Vma& vma) {