Skip to content

Commit a5fe0d8

Browse files
author
shubhisaxena
committed
Make CtsPhotoPickerTests backward compatible
In PhotoPicker, a change was made to require certain security permissions for the GET_CLOUD_PROVIDER_CALL and SET_CLOUD_PROVIDER_CALL ag/23298042 The SET_CLOUD_PROVIDER_CALL was restricted to only the following calling user IDS: + Media Provider itself + Shell - Rest all callers will be blocked from setting the cloud provider Shell's calling UID was allowlisted for the GET_CLOUD_PROVIDER_CALL. This change makes sure that if run against the older MediaProvider versions, it handles the case where shell is not allowlisted for the GET_CLOUD_PROVIDER_CALL. Bug: 308194648 Test: atest ActionUserSelectImagesForAppTest Test: atest PhotoPickerBannersTest Test: atest RemoteVideoPreviewTest Test: atest CloudPhotoPickerTest (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3e8a05de157c33f75b56d0e6de4a08117cc87e58) Merged-In: Ia41f9aed2036f1444810eebf5c6ef0f1ae542701 Change-Id: Ia41f9aed2036f1444810eebf5c6ef0f1ae542701 NOTE FOR REVIEWERS - errors occurred while applying the patch. PLEASE REVIEW CAREFULLY. Errors: Error applying patch in tests/PhotoPicker/src/android/photopicker/cts/ActionUserSelectImagesForAppTest.java, hunk HunkHeader[83,7->84,13]: Hunk cannot be applied Error applying patch in tests/PhotoPicker/src/android/photopicker/cts/CloudPhotoPickerTest.java, hunk HunkHeader[46,6->46,7]: Hunk cannot be applied Error applying patch in tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerBannersTest.java, hunk HunkHeader[42,6->42,7]: Hunk cannot be applied Error applying patch in tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerBaseTest.java, hunk HunkHeader[23,6->23,7]: Hunk cannot be applied Error applying patch in tests/PhotoPicker/src/android/photopicker/cts/RemoteVideoPreviewTest.java, hunk HunkHeader[47,6->47,7]: Hunk cannot be applied Original patch: From 3e8a05de157c33f75b56d0e6de4a08117cc87e58 Mon Sep 17 00:00:00 2001 From: shubhisaxena <shubhisaxena@google.com> Date: Thu, 02 Nov 2023 12:10:16 +0000 Subject: [PATCH] Make CtsPhotoPickerTests backward compatible In PhotoPicker, a change was made to require certain security permissions for the GET_CLOUD_PROVIDER_CALL and SET_CLOUD_PROVIDER_CALL ag/23298042 The SET_CLOUD_PROVIDER_CALL was restricted to only the following calling user IDS: + Media Provider itself + Shell - Rest all callers will be blocked from setting the cloud provider Shell's calling UID was allowlisted for the GET_CLOUD_PROVIDER_CALL. This change makes sure that if run against the older MediaProvider versions, it handles the case where shell is not allowlisted for the GET_CLOUD_PROVIDER_CALL. Bug: 308194648 Test: atest ActionUserSelectImagesForAppTest Test: atest PhotoPickerBannersTest Test: atest RemoteVideoPreviewTest Test: atest CloudPhotoPickerTest Change-Id: Ia41f9aed2036f1444810eebf5c6ef0f1ae542701 ---
1 parent 60c9fcc commit a5fe0d8

5 files changed

Lines changed: 47 additions & 10 deletions

File tree

tests/PhotoPicker/src/android/photopicker/cts/ActionUserSelectImagesForAppTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import android.photopicker.cts.util.PhotoPickerFilesUtils;
4949
import android.photopicker.cts.util.UiAssertionUtils;
5050
import android.provider.MediaStore;
51+
import android.util.Log;
5152
import android.util.Pair;
5253

5354
import androidx.annotation.Nullable;
@@ -68,7 +69,7 @@
6869
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE, codeName = "UpsideDownCake")
6970
@RunWith(AndroidJUnit4.class)
7071
public class ActionUserSelectImagesForAppTest extends PhotoPickerBaseTest {
71-
72+
private static final String TAG = ActionUserSelectImagesForAppTest.class.getSimpleName();
7273
private static boolean sCloudMediaPreviouslyEnabled;
7374
@Nullable
7475
private static String sPreviouslyAllowedCloudProviders;
@@ -85,6 +86,13 @@ public static void setUpClass() throws IOException {
8586
}
8687
sPreviouslySetCloudProvider = getCurrentCloudProvider();
8788

89+
try {
90+
sPreviouslySetCloudProvider = getCurrentCloudProvider();
91+
} catch (RuntimeException e) {
92+
Log.e(TAG, "Could not get previously set cloud provider", e);
93+
sPreviouslySetCloudProvider = INVALID_CLOUD_PROVIDER;
94+
}
95+
8896
// Override the allowed cloud providers config to enable the banners
8997
// (this is a self-instrumenting test, so "target" package name and "own" package name are
9098
// same: android.photopicker.cts).

tests/PhotoPicker/src/android/photopicker/cts/CloudPhotoPickerTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import android.photopicker.cts.cloudproviders.CloudProviderPrimary;
4747
import android.photopicker.cts.cloudproviders.CloudProviderSecondary;
4848
import android.provider.MediaStore;
49+
import android.util.Log;
4950
import android.util.Pair;
5051

5152
import androidx.annotation.Nullable;
@@ -72,6 +73,7 @@
7273
@RunWith(AndroidJUnit4.class)
7374
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
7475
public class CloudPhotoPickerTest extends PhotoPickerBaseTest {
76+
private static final String TAG = CloudPhotoPickerTest.class.getSimpleName();
7577
private final List<Uri> mUriList = new ArrayList<>();
7678
private MediaGenerator mCloudPrimaryMediaGenerator;
7779
private MediaGenerator mCloudSecondaryMediaGenerator;
@@ -95,7 +97,13 @@ public static void setUpBeforeClass() throws IOException {
9597
if (sCloudMediaPreviouslyEnabled) {
9698
sPreviouslyAllowedCloudProviders = getAllowedProvidersDeviceConfig();
9799
}
98-
sPreviouslySetCloudProvider = getCurrentCloudProvider();
100+
101+
try {
102+
sPreviouslySetCloudProvider = getCurrentCloudProvider();
103+
} catch (RuntimeException e) {
104+
Log.e(TAG, "Could not get previously set cloud provider", e);
105+
sPreviouslySetCloudProvider = INVALID_CLOUD_PROVIDER;
106+
}
99107

100108
// This is a self-instrumentation test, so both "target" package name and "own" package name
101109
// should be the same (android.photopicker.cts).

tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerBannersTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import android.net.Uri;
4343
import android.os.Build;
4444
import android.photopicker.cts.cloudproviders.CloudProviderPrimary;
45+
import android.util.Log;
4546

4647

4748
import androidx.annotation.Nullable;
@@ -64,7 +65,7 @@
6465
// We currently can't do this in R.
6566
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
6667
public class PhotoPickerBannersTest extends PhotoPickerBaseTest {
67-
68+
private static final String TAG = PhotoPickerBannersTest.class.getSimpleName();
6869
private static boolean sCloudMediaPreviouslyEnabled;
6970
private static String sPreviouslyAllowedCloudProviders;
7071
@Nullable
@@ -78,7 +79,13 @@ public static void setUpBeforeClass() throws IOException {
7879
if (sCloudMediaPreviouslyEnabled) {
7980
sPreviouslyAllowedCloudProviders = getAllowedProvidersDeviceConfig();
8081
}
81-
sPreviouslySetCloudProvider = getCurrentCloudProvider();
82+
83+
try {
84+
sPreviouslySetCloudProvider = getCurrentCloudProvider();
85+
} catch (RuntimeException e) {
86+
Log.e(TAG, "Could not get previously set cloud provider", e);
87+
sPreviouslySetCloudProvider = INVALID_CLOUD_PROVIDER;
88+
}
8289

8390
// Override the allowed cloud providers config to enable the banners.
8491
enableCloudMediaAndSetAllowedCloudProviders(sTargetPackageName);

tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerBaseTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.content.Context;
2121
import android.content.Intent;
2222
import android.content.pm.PackageManager;
23+
import android.text.TextUtils;
2324
import android.os.UserHandle;
2425
import android.util.Log;
2526

@@ -42,6 +43,7 @@
4243
public class PhotoPickerBaseTest {
4344
private static final String TAG = "PhotoPickerBaseTest";
4445
public static int REQUEST_CODE = 42;
46+
protected static final String INVALID_CLOUD_PROVIDER = "Invalid";
4547
private static final Instrumentation sInstrumentation =
4648
InstrumentationRegistry.getInstrumentation();
4749
protected static final String sTargetPackageName =
@@ -85,6 +87,11 @@ static boolean isHardwareSupported() {
8587
}
8688

8789
protected static void setCloudProvider(@Nullable String authority) throws Exception {
90+
if (INVALID_CLOUD_PROVIDER.equals(authority)) {
91+
Log.w(TAG, "Cloud provider is invalid. "
92+
+ "Ignoring the request to set the cloud provider to invalid");
93+
return;
94+
}
8895
if (authority == null) {
8996
sDevice.executeShellCommand(
9097
"content call"
@@ -111,11 +118,11 @@ protected static String getCurrentCloudProvider() throws IOException {
111118
}
112119

113120
private static String extractCloudProvider(String out) {
114-
if (out == null) {
115-
Log.d(TAG, "Failed request to get current cloud provider");
116-
return null;
121+
String[] splitOutput;
122+
if (TextUtils.isEmpty(out) || ((splitOutput = out.split("=")).length < 2)) {
123+
throw new RuntimeException("Could not get current cloud provider. Output: " + out);
117124
}
118-
String cloudprovider = (out.split("=")[1]);
125+
String cloudprovider = splitOutput[1];
119126
cloudprovider = cloudprovider.substring(0, cloudprovider.length() - 3);
120127
if (cloudprovider.equals("null")) {
121128
return null;

tests/PhotoPicker/src/android/photopicker/cts/RemoteVideoPreviewTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import android.photopicker.cts.cloudproviders.CloudProviderPrimary;
4848
import android.photopicker.cts.cloudproviders.CloudProviderPrimary.CloudMediaSurfaceControllerImpl;
4949
import android.provider.MediaStore;
50+
import android.util.Log;
5051
import android.util.Pair;
5152

5253
import androidx.annotation.Nullable;
@@ -77,7 +78,7 @@
7778
@RunWith(AndroidJUnit4.class)
7879
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
7980
public class RemoteVideoPreviewTest extends PhotoPickerBaseTest {
80-
81+
private static final String TAG = RemoteVideoPreviewTest.class.getSimpleName();
8182
private MediaGenerator mCloudPrimaryMediaGenerator;
8283
private final List<Uri> mUriList = new ArrayList<>();
8384

@@ -104,7 +105,13 @@ public static void setUpBeforeClass() throws IOException {
104105
if (sCloudMediaPreviouslyEnabled) {
105106
sPreviouslyAllowedCloudProviders = getAllowedProvidersDeviceConfig();
106107
}
107-
sPreviouslySetCloudProvider = getCurrentCloudProvider();
108+
109+
try {
110+
sPreviouslySetCloudProvider = getCurrentCloudProvider();
111+
} catch (RuntimeException e) {
112+
Log.e(TAG, "Could not get previously set cloud provider", e);
113+
sPreviouslySetCloudProvider = INVALID_CLOUD_PROVIDER;
114+
}
108115

109116
// This is a self-instrumentation test, so both "target" package name and "own" package name
110117
// should be the same (android.photopicker.cts).

0 commit comments

Comments
 (0)