DivestOS/Patches/LineageOS-16.0/android_packages_apps_Settings/316891059-16.patch
Tavi 0dcdeb029a
Import Q_asb_2024-04 and R_asb_2024-05 + fixups
Signed-off-by: Tavi <tavi@divested.dev>
2024-05-11 11:14:58 -04:00

118 lines
5.9 KiB
Diff

diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java
index cbe49f8c799..9bfd5460efa 100644
--- a/src/com/android/settings/search/SearchFeatureProvider.java
+++ b/src/com/android/settings/search/SearchFeatureProvider.java
@@ -38,7 +38,7 @@ public interface SearchFeatureProvider {
* @throws IllegalArgumentException when caller is null
* @throws SecurityException when caller is not allowed to launch search result page
*/
- void verifyLaunchSearchResultPageCaller(Context context, @NonNull ComponentName caller)
+ void verifyLaunchSearchResultPageCaller(@NonNull Context context, @NonNull String callerPackage)
throws SecurityException, IllegalArgumentException;
/**
diff --git a/src/com/android/settings/search/SearchFeatureProviderImpl.java b/src/com/android/settings/search/SearchFeatureProviderImpl.java
index 78c47edf046..262f220f8ab 100644
--- a/src/com/android/settings/search/SearchFeatureProviderImpl.java
+++ b/src/com/android/settings/search/SearchFeatureProviderImpl.java
@@ -17,10 +17,11 @@
package com.android.settings.search;
-import android.content.ComponentName;
import android.content.Context;
import android.text.TextUtils;
+import android.annotation.NonNull;
+
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.indexing.IndexData;
@@ -32,24 +33,21 @@ import java.util.Locale;
*/
public class SearchFeatureProviderImpl implements SearchFeatureProvider {
- private static final String TAG = "SearchFeatureProvider";
-
private static final String METRICS_ACTION_SETTINGS_INDEX = "search_synchronous_indexing";
private DatabaseIndexingManager mDatabaseIndexingManager;
private SearchIndexableResources mSearchIndexableResources;
@Override
- public void verifyLaunchSearchResultPageCaller(Context context, ComponentName caller) {
- if (caller == null) {
+ public void verifyLaunchSearchResultPageCaller(@NonNull Context context,
+ @NonNull String callerPackage) {
+ if (TextUtils.isEmpty(callerPackage)) {
throw new IllegalArgumentException("ExternalSettingsTrampoline intents "
+ "must be called with startActivityForResult");
}
- final String packageName = caller.getPackageName();
- final boolean isSettingsPackage = TextUtils.equals(packageName, context.getPackageName())
- || TextUtils.equals(getSettingsIntelligencePkgName(), packageName);
- final boolean isWhitelistedPackage =
- isSignatureWhitelisted(context, caller.getPackageName());
- if (isSettingsPackage || isWhitelistedPackage) {
+ final boolean isSettingsPackage = TextUtils.equals(callerPackage, context.getPackageName())
+ || TextUtils.equals(getSettingsIntelligencePkgName(), callerPackage);
+ final boolean isAllowlistedPackage = isSignatureWhitelisted(context, callerPackage);
+ if (isSettingsPackage || isAllowlistedPackage) {
return;
}
throw new SecurityException("Search result intents must be called with from a "
diff --git a/src/com/android/settings/search/SearchResultTrampoline.java b/src/com/android/settings/search/SearchResultTrampoline.java
index 3bbe6bd58a7..70387b021d4 100644
--- a/src/com/android/settings/search/SearchResultTrampoline.java
+++ b/src/com/android/settings/search/SearchResultTrampoline.java
@@ -38,7 +38,7 @@ public class SearchResultTrampoline extends Activity {
// First make sure caller has privilege to launch a search result page.
FeatureFactory.getFactory(this)
.getSearchFeatureProvider()
- .verifyLaunchSearchResultPageCaller(this, getCallingActivity());
+ .verifyLaunchSearchResultPageCaller(this, getCallingPackage());
// Didn't crash, proceed and launch the result as a subsetting.
final Intent intent = getIntent();
diff --git a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
index eeebdee96e3..7945c05a293 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.app.Activity;
-import android.content.ComponentName;
import android.content.Intent;
import android.widget.Toolbar;
@@ -70,21 +69,23 @@ public class SearchFeatureProviderImplTest {
@Test(expected = SecurityException.class)
public void verifyLaunchSearchResultPageCaller_badCaller_shouldCrash() {
- final ComponentName cn = new ComponentName("pkg", "class");
- mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn);
+ final String packageName = "pkg";
+
+ mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName);
}
@Test
public void verifyLaunchSearchResultPageCaller_settingsCaller_shouldNotCrash() {
- final ComponentName cn = new ComponentName(mActivity.getPackageName(), "class");
- mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn);
+ final String packageName = mActivity.getPackageName();
+
+ mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName);
}
@Test
public void verifyLaunchSearchResultPageCaller_settingsIntelligenceCaller_shouldNotCrash() {
final String packageName = mProvider.getSettingsIntelligencePkgName();
- final ComponentName cn = new ComponentName(packageName, "class");
- mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn);
+
+ mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName);
}
@Test