2 * Copyright (C) 2017 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 package com.android.server.wm;
19 import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
20 import static android.graphics.GraphicBuffer.USAGE_HW_TEXTURE;
21 import static android.graphics.GraphicBuffer.USAGE_SW_READ_RARELY;
23 import android.app.ActivityManager.TaskSnapshot;
24 import android.graphics.Canvas;
25 import android.graphics.Color;
26 import android.graphics.GraphicBuffer;
27 import android.graphics.PixelFormat;
28 import android.graphics.Rect;
29 import android.os.UserManager;
30 import android.support.test.InstrumentationRegistry;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
39 * Base class for tests that use a {@link TaskSnapshotPersister}.
41 class TaskSnapshotPersisterTestBase extends WindowTestsBase {
43 private static final Rect TEST_INSETS = new Rect(10, 20, 30, 40);
45 TaskSnapshotPersister mPersister;
46 TaskSnapshotLoader mLoader;
48 static File sFilesDir;
51 public static void setUpUser() {
52 sFilesDir = InstrumentationRegistry.getContext().getFilesDir();
56 public void setUp() throws Exception {
58 final UserManager um = UserManager.get(InstrumentationRegistry.getContext());
59 mTestUserId = um.getUserHandle();
60 mPersister = new TaskSnapshotPersister(userId -> sFilesDir);
61 mLoader = new TaskSnapshotLoader(mPersister);
66 public void tearDown() throws Exception {
70 private void cleanDirectory() {
71 for (File file : new File(sFilesDir, "snapshots").listFiles()) {
72 if (!file.isDirectory()) {
78 TaskSnapshot createSnapshot() {
79 final GraphicBuffer buffer = GraphicBuffer.create(100, 100, PixelFormat.RGBA_8888,
80 USAGE_HW_TEXTURE | USAGE_SW_READ_RARELY | USAGE_SW_READ_RARELY);
81 Canvas c = buffer.lockCanvas();
82 c.drawColor(Color.RED);
83 buffer.unlockCanvasAndPost(c);
84 return new TaskSnapshot(buffer, ORIENTATION_PORTRAIT, TEST_INSETS,
85 false /* reducedResolution */, 1f /* scale */);