Remove only selected messages for vold reset

- Resetting all pending messages can lead into secondary user
  losing unlocking event in automotive devices.
- Only remove selected messages like RESET, VOLUME_MOUNT/UNMOUNT/BROADCAST.

Bug: 151457974
Test: try reboot in auto devices where this race can happen.
      run cts: atest android.appsecurity.cts.AdoptableHostTest

Change-Id: Iee52b4ee76f07e0c7aaaa6f0dfa480aeef1df2e9
This commit is contained in:
Keun young Park
2020-06-17 14:27:37 -07:00
committed by Keun-young Park
parent d82080094e
commit 0c00e5236e
2 changed files with 8 additions and 4 deletions

View File

@@ -1083,7 +1083,12 @@ class StorageManagerService extends IStorageManager.Stub
final List<UserInfo> users = mContext.getSystemService(UserManager.class).getUsers();
if (mIsFuseEnabled) {
mStorageSessionController.onReset(mVold, mHandler);
mStorageSessionController.onReset(mVold, () -> {
mHandler.removeMessages(H_RESET);
mHandler.removeMessages(H_VOLUME_BROADCAST);
mHandler.removeMessages(H_VOLUME_MOUNT);
mHandler.removeMessages(H_VOLUME_UNMOUNT);
});
} else {
killMediaProvider(users);
}

View File

@@ -27,7 +27,6 @@ import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Handler;
import android.os.IVold;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
@@ -238,7 +237,7 @@ public final class StorageSessionController {
*
* Does nothing if {@link #shouldHandle} is {@code false}
**/
public void onReset(IVold vold, Handler handler) {
public void onReset(IVold vold, Runnable resetHandlerRunnable) {
if (!shouldHandle(null)) {
return;
}
@@ -280,7 +279,7 @@ public final class StorageSessionController {
connection.close();
}
handler.removeCallbacksAndMessages(null);
resetHandlerRunnable.run();
synchronized (mLock) {
mConnections.clear();
mIsResetting = false;