blob: 516e1c00918a69ecabb758a89fe358d6df805640 [file] [log] [blame]
/*
* Copyright (C) 2021 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.photopicker.cts;
import android.Manifest;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.provider.DeviceConfig;
import androidx.test.InstrumentationRegistry;
import androidx.test.uiautomator.UiDevice;
import com.android.modules.utils.build.SdkLevel;
import org.junit.Before;
/**
* Photo Picker Base class for Photo Picker tests. This includes common setup methods
* required for all Photo Picker tests.
*/
public class PhotoPickerBaseTest {
public static int REQUEST_CODE = 42;
protected GetResultActivity mActivity;
protected Context mContext;
protected UiDevice mDevice;
@Before
public void setUp() throws Exception {
final Instrumentation inst = InstrumentationRegistry.getInstrumentation();
mDevice = UiDevice.getInstance(inst);
enablePhotoPickerFlag(inst);
mContext = inst.getContext();
final Intent intent = new Intent(mContext, GetResultActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Wake up the device and dismiss the keyguard before the test starts
mDevice.executeShellCommand("input keyevent KEYCODE_WAKEUP");
mDevice.executeShellCommand("wm dismiss-keyguard");
mActivity = (GetResultActivity) inst.startActivitySync(intent);
// Wait for the UI Thread to become idle.
inst.waitForIdleSync();
mActivity.clearResult();
mDevice.waitForIdle();
}
private void enablePhotoPickerFlag(Instrumentation inst) throws Exception {
if (SdkLevel.isAtLeastS()) {
inst.getUiAutomation().adoptShellPermissionIdentity(
Manifest.permission.WRITE_DEVICE_CONFIG);
DeviceConfig.setProperty(
DeviceConfig.NAMESPACE_STORAGE_NATIVE_BOOT,
"picker_intent_enabled" /* name */,
"true" /* value */,
false /* makeDefault */);
} else {
mDevice.executeShellCommand("setprop persist.sys.storage_picker_enabled true");
}
}
}