Check user unlocked before write to /data/system_ce/0/snapshots
When reboot device. TaskSnapshotPersister create directory
"/data/system_ce/0/snapshots" before FBE decrypt.
Then WTF occur.
Bug: 154787951
Bug: 224585613
Test: Device boots without WTF error
Change-Id: Ie9d4a28008adc93e27bc8ab015a3a6507428c3e4
(cherry picked from commit 2f9987f507)
Merged-In: Ie9d4a28008adc93e27bc8ab015a3a6507428c3e4
This commit is contained in:
@@ -28,12 +28,14 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.Bitmap.Config;
|
import android.graphics.Bitmap.Config;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.os.UserManagerInternal;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.os.AtomicFile;
|
import com.android.internal.os.AtomicFile;
|
||||||
|
import com.android.server.LocalServices;
|
||||||
import com.android.server.wm.nano.WindowManagerProtos.TaskSnapshotProto;
|
import com.android.server.wm.nano.WindowManagerProtos.TaskSnapshotProto;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -74,6 +76,7 @@ class TaskSnapshotPersister {
|
|||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private final DirectoryResolver mDirectoryResolver;
|
private final DirectoryResolver mDirectoryResolver;
|
||||||
private final float mReducedScale;
|
private final float mReducedScale;
|
||||||
|
private final UserManagerInternal mUserManagerInternal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of ids of the tasks that have been persisted since {@link #removeObsoleteFiles} was
|
* The list of ids of the tasks that have been persisted since {@link #removeObsoleteFiles} was
|
||||||
@@ -84,6 +87,9 @@ class TaskSnapshotPersister {
|
|||||||
|
|
||||||
TaskSnapshotPersister(WindowManagerService service, DirectoryResolver resolver) {
|
TaskSnapshotPersister(WindowManagerService service, DirectoryResolver resolver) {
|
||||||
mDirectoryResolver = resolver;
|
mDirectoryResolver = resolver;
|
||||||
|
|
||||||
|
mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
|
||||||
|
|
||||||
if (service.mLowRamTaskSnapshotsAndRecents) {
|
if (service.mLowRamTaskSnapshotsAndRecents) {
|
||||||
// Use very low res snapshots if we are using Go version of recents.
|
// Use very low res snapshots if we are using Go version of recents.
|
||||||
mReducedScale = LOW_RAM_RECENTS_REDUCED_SCALE;
|
mReducedScale = LOW_RAM_RECENTS_REDUCED_SCALE;
|
||||||
@@ -172,7 +178,7 @@ class TaskSnapshotPersister {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SystemClock.sleep(100);
|
SystemClock.sleep(DELAY_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +224,7 @@ class TaskSnapshotPersister {
|
|||||||
|
|
||||||
private boolean createDirectory(int userId) {
|
private boolean createDirectory(int userId) {
|
||||||
final File dir = getDirectory(userId);
|
final File dir = getDirectory(userId);
|
||||||
return dir.exists() || dir.mkdirs();
|
return dir.exists() || dir.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteSnapshot(int taskId, int userId) {
|
private void deleteSnapshot(int taskId, int userId) {
|
||||||
@@ -243,18 +249,26 @@ class TaskSnapshotPersister {
|
|||||||
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
while (true) {
|
while (true) {
|
||||||
WriteQueueItem next;
|
WriteQueueItem next;
|
||||||
|
boolean isReadyToWrite = false;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mPaused) {
|
if (mPaused) {
|
||||||
next = null;
|
next = null;
|
||||||
} else {
|
} else {
|
||||||
next = mWriteQueue.poll();
|
next = mWriteQueue.poll();
|
||||||
if (next != null) {
|
if (next != null) {
|
||||||
next.onDequeuedLocked();
|
if (next.isReady()) {
|
||||||
|
isReadyToWrite = true;
|
||||||
|
next.onDequeuedLocked();
|
||||||
|
} else {
|
||||||
|
mWriteQueue.addLast(next);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (next != null) {
|
if (next != null) {
|
||||||
next.write();
|
if (isReadyToWrite) {
|
||||||
|
next.write();
|
||||||
|
}
|
||||||
SystemClock.sleep(DELAY_MS);
|
SystemClock.sleep(DELAY_MS);
|
||||||
}
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
@@ -274,6 +288,13 @@ class TaskSnapshotPersister {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private abstract class WriteQueueItem {
|
private abstract class WriteQueueItem {
|
||||||
|
/**
|
||||||
|
* @return {@code true} if item is ready to have {@link WriteQueueItem#write} called
|
||||||
|
*/
|
||||||
|
boolean isReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
abstract void write();
|
abstract void write();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -312,6 +333,11 @@ class TaskSnapshotPersister {
|
|||||||
mStoreQueueItems.remove(this);
|
mStoreQueueItems.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isReady() {
|
||||||
|
return mUserManagerInternal.isUserUnlocked(mUserId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void write() {
|
void write() {
|
||||||
if (!createDirectory(mUserId)) {
|
if (!createDirectory(mUserId)) {
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ import static android.graphics.GraphicBuffer.USAGE_SW_READ_RARELY;
|
|||||||
|
|
||||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.ActivityManager.TaskSnapshot;
|
import android.app.ActivityManager.TaskSnapshot;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@@ -32,9 +35,14 @@ import android.graphics.GraphicBuffer;
|
|||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.os.UserManagerInternal;
|
||||||
|
|
||||||
|
import com.android.server.LocalServices;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -50,10 +58,26 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
|
|||||||
TaskSnapshotLoader mLoader;
|
TaskSnapshotLoader mLoader;
|
||||||
int mTestUserId;
|
int mTestUserId;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpOnce() {
|
||||||
|
final UserManagerInternal userManager = mock(UserManagerInternal.class);
|
||||||
|
LocalServices.addService(UserManagerInternal.class, userManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void tearDownOnce() {
|
||||||
|
LocalServices.removeServiceForTest(UserManagerInternal.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
final UserManager um = UserManager.get(getInstrumentation().getTargetContext());
|
final UserManager um = UserManager.get(getInstrumentation().getTargetContext());
|
||||||
mTestUserId = um.getUserHandle();
|
mTestUserId = um.getUserHandle();
|
||||||
|
|
||||||
|
final UserManagerInternal userManagerInternal =
|
||||||
|
LocalServices.getService(UserManagerInternal.class);
|
||||||
|
when(userManagerInternal.isUserUnlocked(mTestUserId)).thenReturn(true);
|
||||||
|
|
||||||
mPersister = new TaskSnapshotPersister(mWm, userId -> FILES_DIR);
|
mPersister = new TaskSnapshotPersister(mWm, userId -> FILES_DIR);
|
||||||
mLoader = new TaskSnapshotLoader(mPersister);
|
mLoader = new TaskSnapshotLoader(mPersister);
|
||||||
mPersister.start();
|
mPersister.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user