Files
lawnchair/tests/src/com/android/launcher3/util/TestUtil.java
Vadim Tryshev 1b4560cf2a Adding dummy app apk for tests
Bug: 117888000
Test: In Nexus code
Change-Id: Ibf0b803c9db6b344ffbe5b7761efb2a2d86867c6
2018-11-05 10:36:21 -08:00

52 lines
1.8 KiB
Java

/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.util;
import static androidx.test.InstrumentationRegistry.getContext;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import android.content.res.Resources;
import androidx.test.uiautomator.UiDevice;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class TestUtil {
public static void installDummyApp() throws IOException {
// Copy apk from resources to a local file and install from there.
final Resources resources = getContext().getResources();
final InputStream in = resources.openRawResource(
resources.getIdentifier("aardwolf_dummy_app",
"raw", getContext().getPackageName()));
final String apkFilename = getInstrumentation().getTargetContext().
getFilesDir().getPath() + "/dummy_app.apk";
final FileOutputStream out = new FileOutputStream(apkFilename);
byte[] buff = new byte[1024];
int read;
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
in.close();
out.close();
UiDevice.getInstance(getInstrumentation()).executeShellCommand("pm install " + apkFilename);
}
}