[RESTRICT AUTOMERGE] Replace getCallingActivity() with getLaunchedFromPackage()
getLaunchedFromPackage() reports who launched this Activity or built
PendingIntent used to launch it, whereas getCallingActivity() reports
who will get result of Activity.
Bug: 316891059
Bug: 333364513
Test: robotest, manual
Change-Id: If97018c2741caef622f0596bbfeaa42ef1788b78
(cherry picked from commit ddc11bc03a
)
This commit is contained in:
@@ -51,7 +51,7 @@ public interface SearchFeatureProvider {
|
|||||||
* @throws IllegalArgumentException when caller is null
|
* @throws IllegalArgumentException when caller is null
|
||||||
* @throws SecurityException when caller is not allowed to launch search result page
|
* @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;
|
throws SecurityException, IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
|
|
||||||
package com.android.settings.search;
|
package com.android.settings.search;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.settingslib.search.SearchIndexableResources;
|
import com.android.settingslib.search.SearchIndexableResources;
|
||||||
import com.android.settingslib.search.SearchIndexableResourcesMobile;
|
import com.android.settingslib.search.SearchIndexableResourcesMobile;
|
||||||
|
|
||||||
@@ -32,21 +33,18 @@ import com.android.settingslib.search.SearchIndexableResourcesMobile;
|
|||||||
*/
|
*/
|
||||||
public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
||||||
|
|
||||||
private static final String TAG = "SearchFeatureProvider";
|
|
||||||
|
|
||||||
private SearchIndexableResources mSearchIndexableResources;
|
private SearchIndexableResources mSearchIndexableResources;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verifyLaunchSearchResultPageCaller(Context context, ComponentName caller) {
|
public void verifyLaunchSearchResultPageCaller(@NonNull Context context,
|
||||||
if (caller == null) {
|
@NonNull String callerPackage) {
|
||||||
|
if (TextUtils.isEmpty(callerPackage)) {
|
||||||
throw new IllegalArgumentException("ExternalSettingsTrampoline intents "
|
throw new IllegalArgumentException("ExternalSettingsTrampoline intents "
|
||||||
+ "must be called with startActivityForResult");
|
+ "must be called with startActivityForResult");
|
||||||
}
|
}
|
||||||
final String packageName = caller.getPackageName();
|
final boolean isSettingsPackage = TextUtils.equals(callerPackage, context.getPackageName())
|
||||||
final boolean isSettingsPackage = TextUtils.equals(packageName, context.getPackageName())
|
|| TextUtils.equals(getSettingsIntelligencePkgName(context), callerPackage);
|
||||||
|| TextUtils.equals(getSettingsIntelligencePkgName(context), packageName);
|
final boolean isAllowlistedPackage = isSignatureAllowlisted(context, callerPackage);
|
||||||
final boolean isAllowlistedPackage =
|
|
||||||
isSignatureAllowlisted(context, caller.getPackageName());
|
|
||||||
if (isSettingsPackage || isAllowlistedPackage) {
|
if (isSettingsPackage || isAllowlistedPackage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,7 @@ public class SearchResultTrampoline extends Activity {
|
|||||||
// First make sure caller has privilege to launch a search result page.
|
// First make sure caller has privilege to launch a search result page.
|
||||||
FeatureFactory.getFactory(this)
|
FeatureFactory.getFactory(this)
|
||||||
.getSearchFeatureProvider()
|
.getSearchFeatureProvider()
|
||||||
.verifyLaunchSearchResultPageCaller(this, getCallingActivity());
|
.verifyLaunchSearchResultPageCaller(this, getLaunchedFromPackage());
|
||||||
// Didn't crash, proceed and launch the result as a subsetting.
|
// Didn't crash, proceed and launch the result as a subsetting.
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
|
|
||||||
|
@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
@@ -126,20 +125,22 @@ public class SearchFeatureProviderImplTest {
|
|||||||
|
|
||||||
@Test(expected = SecurityException.class)
|
@Test(expected = SecurityException.class)
|
||||||
public void verifyLaunchSearchResultPageCaller_badCaller_shouldCrash() {
|
public void verifyLaunchSearchResultPageCaller_badCaller_shouldCrash() {
|
||||||
final ComponentName cn = new ComponentName("pkg", "class");
|
final String packageName = "pkg";
|
||||||
mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn);
|
|
||||||
|
mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void verifyLaunchSearchResultPageCaller_settingsCaller_shouldNotCrash() {
|
public void verifyLaunchSearchResultPageCaller_settingsCaller_shouldNotCrash() {
|
||||||
final ComponentName cn = new ComponentName(mActivity.getPackageName(), "class");
|
final String packageName = mActivity.getPackageName();
|
||||||
mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn);
|
|
||||||
|
mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void verifyLaunchSearchResultPageCaller_settingsIntelligenceCaller_shouldNotCrash() {
|
public void verifyLaunchSearchResultPageCaller_settingsIntelligenceCaller_shouldNotCrash() {
|
||||||
final String packageName = mProvider.getSettingsIntelligencePkgName(mActivity);
|
final String packageName = mProvider.getSettingsIntelligencePkgName(mActivity);
|
||||||
final ComponentName cn = new ComponentName(packageName, "class");
|
|
||||||
mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn);
|
mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user