blob: 2c70ba8bcc5f895a8e2073e2886aae121abe2034 [file] [log] [blame]
/*
* Copyright (C) 2020 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 android.security.cts.CVE_2021_0327;
import static org.junit.Assert.assertTrue;
import android.test.AndroidTestCase;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.platform.test.annotations.SecurityTest;
import android.os.SystemClock;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.InstrumentationRegistry;
import android.util.Log;
import android.os.Bundle;
import org.junit.Test;
import org.junit.runner.RunWith;
import android.app.admin.DevicePolicyManager;
import android.content.ClipData;
import android.net.Uri;
import android.content.ComponentName;
import android.app.AlertDialog;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.ParcelFileDescriptor;
import java.io.File;
import java.io.FileDescriptor;
import android.os.IBinder;
import android.os.Handler;
import android.os.ResultReceiver;
import android.annotation.SuppressLint;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import java.io.*;
import java.util.stream.Collectors;
import android.security.cts.CVE_2021_0327.workprofilesetup.AdminReceiver;
import static org.junit.Assert.assertFalse;
@SecurityTest
@RunWith(AndroidJUnit4.class)
public class CVE_2021_0327 {
private static final String SECURITY_CTS_PACKAGE_NAME = "android.security.cts";
private static final String TAG = "CVE_2021_0327";
public static boolean testActivityRequested;
public static boolean testActivityCreated;
public static String errorMessage = null;
private void launchActivity(Class<? extends Activity> clazz) {
final Context context = InstrumentationRegistry.getInstrumentation().getContext();
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(SECURITY_CTS_PACKAGE_NAME, clazz.getName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
/**
* b/175817081
*/
@Test
@SecurityTest
public void testPocCVE_2021_0327() throws Exception {
Log.d(TAG, "test start");
testActivityCreated=false;
testActivityRequested=false;
launchActivity(IntroActivity.class);
synchronized(CVE_2021_0327.class){
if(!testActivityRequested) {
Log.d(TAG, "test is waiting for TestActivity to be requested to run");
CVE_2021_0327.class.wait();
Log.d(TAG, "got signal");
}
}
synchronized(CVE_2021_0327.class){
if(!testActivityCreated) {
Log.d(TAG, "test is waiting for TestActivity to run");
CVE_2021_0327.class.wait(10000);
Log.d(TAG, "got signal");
}
}
Log.d(TAG, "test completed. testActivityCreated=" + testActivityCreated);
if(errorMessage != null){
Log.d(TAG, "errorMessage=" + errorMessage);
}
assertTrue(errorMessage==null);
assertFalse(testActivityCreated);
}
}