[Safer intents] Settings misc

To avoid implicit intents, make intents launch explicitly.

Test: build
Bug: 323061508
Change-Id: Ie19cbceb89842a75a180898abcce81b63c18d46c
This commit is contained in:
Jason Chiu
2024-03-25 12:15:56 +08:00
parent 9507bdb3ac
commit 0bd014c497
23 changed files with 54 additions and 44 deletions

View File

@@ -175,7 +175,8 @@
android:title="@string/financed_device_info" android:title="@string/financed_device_info"
android:summary="@string/summary_placeholder" android:summary="@string/summary_placeholder"
settings:controller="com.android.settings.devicelock.DeviceLockPreferenceController"> settings:controller="com.android.settings.devicelock.DeviceLockPreferenceController">
<intent android:action="com.android.devicelockcontroller.action.DEVICE_INFO_SETTINGS"/> <intent android:action="com.android.devicelockcontroller.action.DEVICE_INFO_SETTINGS"
android:targetPackage="@string/config_device_lock_controller_package_name"/>
</Preference> </Preference>
</PreferenceCategory> </PreferenceCategory>

View File

@@ -14,12 +14,14 @@
~ See the License for the specific language governing permissions and ~ See the License for the specific language governing permissions and
~ limitations under the License ~ limitations under the License
--> -->
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" > <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut <shortcut
android:shortcutId="manifest-shortcut-wifi" android:shortcutId="manifest-shortcut-wifi"
android:icon="@drawable/ic_shortcut_wireless" android:icon="@drawable/ic_shortcut_wireless"
android:shortcutShortLabel="@string/wifi_settings" > android:shortcutShortLabel="@string/wifi_settings">
<intent android:action="android.settings.WIFI_SETTINGS" /> <intent
android:action="android.settings.WIFI_SETTINGS"
android:targetPackage="${applicationId}"/>
</shortcut> </shortcut>
<shortcut <shortcut
android:shortcutId="manifest-shortcut-data-usage" android:shortcutId="manifest-shortcut-data-usage"
@@ -28,13 +30,15 @@
android:shortcutShortLabel="@string/data_usage_summary_title"> android:shortcutShortLabel="@string/data_usage_summary_title">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings" android:targetPackage="${applicationId}"
android:targetClass="com.android.settings.Settings$DataUsageSummaryActivity" /> android:targetClass="com.android.settings.Settings$DataUsageSummaryActivity"/>
</shortcut> </shortcut>
<shortcut <shortcut
android:shortcutId="manifest-shortcut-battery" android:shortcutId="manifest-shortcut-battery"
android:icon="@drawable/ic_shortcut_battery" android:icon="@drawable/ic_shortcut_battery"
android:shortcutShortLabel="@string/power_usage_summary_title" > android:shortcutShortLabel="@string/power_usage_summary_title">
<intent android:action="android.intent.action.POWER_USAGE_SUMMARY" /> <intent
android:action="android.intent.action.POWER_USAGE_SUMMARY"
android:targetPackage="${applicationId}"/>
</shortcut> </shortcut>
</shortcuts> </shortcuts>

View File

@@ -31,7 +31,8 @@ public class BrightnessPreference extends Preference {
@Override @Override
protected void onClick() { protected void onClick() {
getContext().startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), getContext().startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG)
.setPackage(Utils.SYSTEMUI_PACKAGE_NAME),
UserHandle.CURRENT_OR_SELF); UserHandle.CURRENT_OR_SELF);
} }
} }

View File

@@ -74,7 +74,8 @@ public class RingtonePreference extends Preference {
true); true);
mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent, mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent,
true); true);
setIntent(new Intent(RingtoneManager.ACTION_RINGTONE_PICKER)); setIntent(new Intent(RingtoneManager.ACTION_RINGTONE_PICKER)
.setPackage(context.getString(R.string.config_sound_picker_package_name)));
setUserId(UserHandle.myUserId()); setUserId(UserHandle.myUserId());
a.recycle(); a.recycle();
} }

View File

@@ -39,6 +39,7 @@ public class LiveCaptionPreferenceController extends BasePreferenceController {
public LiveCaptionPreferenceController(Context context, String preferenceKey) { public LiveCaptionPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey); super(context, preferenceKey);
mPackageManager = context.getPackageManager(); mPackageManager = context.getPackageManager();
LIVE_CAPTION_INTENT.setPackage(mPackageManager.getSystemCaptionsServicePackageName());
} }
@Override @Override

View File

@@ -256,6 +256,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
if (preference == profileData.addAccountPreference) { if (preference == profileData.addAccountPreference) {
mMetricsFeatureProvider.logClickedPreference(preference, metricsCategory); mMetricsFeatureProvider.logClickedPreference(preference, metricsCategory);
Intent intent = new Intent(ACTION_ADD_ACCOUNT); Intent intent = new Intent(ACTION_ADD_ACCOUNT);
intent.setClass(mContext, AddAccountSettings.class);
intent.putExtra(EXTRA_USER, profileData.userInfo.getUserHandle()); intent.putExtra(EXTRA_USER, profileData.userInfo.getUserHandle());
intent.putExtra(EXTRA_AUTHORITIES, mAuthorities); intent.putExtra(EXTRA_AUTHORITIES, mAuthorities);
mContext.startActivity(intent); mContext.startActivity(intent);

View File

@@ -66,7 +66,8 @@ public class EnterpriseDisclosurePreferenceController extends BasePreferenceCont
final FooterPreference footerPreference = screen.findPreference(getPreferenceKey()); final FooterPreference footerPreference = screen.findPreference(getPreferenceKey());
footerPreference.setTitle(disclosure); footerPreference.setTitle(disclosure);
footerPreference.setLearnMoreAction(view -> { footerPreference.setLearnMoreAction(view -> {
mContext.startActivity(new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)); mContext.startActivity(new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)
.setPackage(mContext.getPackageName()));
}); });
final String learnMoreText = mContext.getString( final String learnMoreText = mContext.getString(
R.string.footer_learn_more_content_description, getLabelName()); R.string.footer_learn_more_content_description, getLabelName());

View File

@@ -223,8 +223,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
@Override @Override
public void openTileIntent(FragmentActivity activity, Tile tile) { public void openTileIntent(FragmentActivity activity, Tile tile) {
if (tile == null) { if (tile == null) {
Intent intent = new Intent(Settings.ACTION_SETTINGS).addFlags( Intent intent = new Intent(Settings.ACTION_SETTINGS)
Intent.FLAG_ACTIVITY_CLEAR_TASK); .setPackage(mContext.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
mContext.startActivity(intent); mContext.startActivity(intent);
return; return;
} }

View File

@@ -42,7 +42,8 @@ public class LocationToggleDisabledDialogFragment extends InstrumentedDialogFrag
.setPositiveButton( .setPositiveButton(
R.string.location_time_zone_detection_location_is_off_dialog_ok_button, R.string.location_time_zone_detection_location_is_off_dialog_ok_button,
(dialog, which) -> { (dialog, which) -> {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
.setPackage(getContext().getPackageName());
getContext().startActivity(intent); getContext().startActivity(intent);
}) })
.setNegativeButton( .setNegativeButton(

View File

@@ -68,6 +68,7 @@ public class AdaptiveSleepPermissionPreferenceController {
mContext.getPackageManager().getAttentionServicePackageName(); mContext.getPackageManager().getAttentionServicePackageName();
final Intent intent = new Intent( final Intent intent = new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setPackage(mContext.getPackageName());
intent.setData(Uri.parse("package:" + packageName)); intent.setData(Uri.parse("package:" + packageName));
mPreference = new BannerMessagePreference(mContext); mPreference = new BannerMessagePreference(mContext);
mPreference.setTitle(R.string.adaptive_sleep_title_no_permission); mPreference.setTitle(R.string.adaptive_sleep_title_no_permission);

View File

@@ -39,6 +39,7 @@ import android.text.TextUtils;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SettingsBaseActivity; import com.android.settings.core.SettingsBaseActivity;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
@@ -145,6 +146,7 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
return false; return false;
} }
final Intent intent = new Intent(ACTION_SHOW_BRIGHTNESS_DIALOG); final Intent intent = new Intent(ACTION_SHOW_BRIGHTNESS_DIALOG);
intent.setPackage(Utils.SYSTEMUI_PACKAGE_NAME);
intent.putExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE, intent.putExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE,
SettingsTransitionHelper.TransitionType.TRANSITION_NONE); SettingsTransitionHelper.TransitionType.TRANSITION_NONE);
intent.putExtra(EXTRA_BRIGHTNESS_DIALOG_IS_FULL_WIDTH, true); intent.putExtra(EXTRA_BRIGHTNESS_DIALOG_IS_FULL_WIDTH, true);

View File

@@ -47,6 +47,7 @@ public class SmartAutoRotatePermissionController extends BasePreferenceControlle
final String packageName = context.getPackageManager().getRotationResolverPackageName(); final String packageName = context.getPackageManager().getRotationResolverPackageName();
mIntent = new Intent( mIntent = new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
mIntent.setPackage(context.getPackageName());
mIntent.setData(Uri.parse("package:" + packageName)); mIntent.setData(Uri.parse("package:" + packageName));
} }

View File

@@ -34,8 +34,6 @@ import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.style.ClickableSpan;
import android.view.View;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.vpn2.VpnUtils; import com.android.settings.vpn2.VpnUtils;
@@ -303,24 +301,4 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
} }
return UserHandle.USER_NULL; return UserHandle.USER_NULL;
} }
protected static class EnterprisePrivacySpan extends ClickableSpan {
private final Context mContext;
public EnterprisePrivacySpan(Context context) {
mContext = context;
}
@Override
public void onClick(View widget) {
mContext.startActivity(new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
@Override
public boolean equals(Object object) {
return object instanceof EnterprisePrivacySpan
&& ((EnterprisePrivacySpan) object).mContext == mContext;
}
}
} }

View File

@@ -52,7 +52,7 @@ public class FlashlightHandleActivity extends Activity implements Indexable {
// Caller's choice: fallback to homepage, or just exit? // Caller's choice: fallback to homepage, or just exit?
if (getIntent().getBooleanExtra(EXTRA_FALLBACK_TO_HOMEPAGE, false)) { if (getIntent().getBooleanExtra(EXTRA_FALLBACK_TO_HOMEPAGE, false)) {
startActivity(new Intent(Settings.ACTION_SETTINGS)); startActivity(new Intent(Settings.ACTION_SETTINGS).setPackage(getPackageName()));
} }
finish(); finish();
} }

View File

@@ -208,6 +208,8 @@ public class SettingsHomepageActivity extends FragmentActivity implements
if (TextUtils.equals(intent.getAction(), ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY) if (TextUtils.equals(intent.getAction(), ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY)
&& this instanceof DeepLinkHomepageActivity) { && this instanceof DeepLinkHomepageActivity) {
intent.setClass(this, DeepLinkHomepageActivityInternal.class); intent.setClass(this, DeepLinkHomepageActivityInternal.class);
} else {
intent.setPackage(getPackageName());
} }
intent.removeFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.removeFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityAsUser(intent, um.getProfileParent(userInfo.id).getUserHandle()); startActivityAsUser(intent, um.getProfileParent(userInfo.id).getUserHandle());

View File

@@ -113,8 +113,8 @@ public class FaceReEnrollDialog extends AlertActivity implements
return; return;
} }
// Send user to the enroll flow. // Send user to the enroll flow.
final Intent reEnroll = new Intent(BIOMETRIC_ENROLL_ACTION); final Intent reEnroll = new Intent(BIOMETRIC_ENROLL_ACTION)
final Context context = getApplicationContext(); .setPackage(getPackageName());
try { try {
startActivity(reEnroll); startActivity(reEnroll);

View File

@@ -42,7 +42,8 @@ public abstract class AbnormalRingerConditionController implements ConditionalCa
@Override @Override
public void onPrimaryClick(Context context) { public void onPrimaryClick(Context context) {
context.startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS)); context.startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS)
.setPackage(context.getPackageName()));
} }
@Override @Override

View File

@@ -151,7 +151,9 @@ public class VolumePanel implements PanelContent, LifecycleObserver {
@Override @Override
public Intent getSeeMoreIntent() { public Intent getSeeMoreIntent() {
return new Intent(Settings.ACTION_SOUND_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return new Intent(Settings.ACTION_SOUND_SETTINGS)
.setPackage(mContext.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} }
@Override @Override

View File

@@ -142,6 +142,7 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment
if (isEnabled) { if (isEnabled) {
if (passwordQuality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { if (passwordQuality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
Intent chooseLockIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD); Intent chooseLockIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
chooseLockIntent.setPackage(getContext().getPackageName());
chooseLockIntent.putExtra( chooseLockIntent.putExtra(
ChooseLockGeneric.ChooseLockGenericFragment.HIDE_INSECURE_OPTIONS, ChooseLockGeneric.ChooseLockGenericFragment.HIDE_INSECURE_OPTIONS,
true); true);

View File

@@ -67,7 +67,7 @@ public class SliceDeepLinkSpringBoard extends Activity {
finish(); finish();
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Couldn't launch Slice intent", e); Log.w(TAG, "Couldn't launch Slice intent", e);
startActivity(new Intent(Settings.ACTION_SETTINGS)); startActivity(new Intent(Settings.ACTION_SETTINGS).setPackage(getPackageName()));
finish(); finish();
} }
} }

View File

@@ -26,6 +26,7 @@ import android.text.TextUtils
import androidx.preference.Preference import androidx.preference.Preference
import com.android.internal.annotations.VisibleForTesting import com.android.internal.annotations.VisibleForTesting
import com.android.settings.R import com.android.settings.R
import com.android.settings.Utils
import com.android.settings.core.BasePreferenceController import com.android.settings.core.BasePreferenceController
/** /**
@@ -47,6 +48,7 @@ class ContrastPreferenceController(
override fun handlePreferenceTreeClick(preference: Preference): Boolean { override fun handlePreferenceTreeClick(preference: Preference): Boolean {
if (TextUtils.equals(preference.key, preferenceKey)) { if (TextUtils.equals(preference.key, preferenceKey)) {
val intent = Intent(Intent.ACTION_SHOW_CONTRAST_DIALOG) val intent = Intent(Intent.ACTION_SHOW_CONTRAST_DIALOG)
intent.setPackage(Utils.SYSTEMUI_PACKAGE_NAME)
context.startActivityAsUser(intent, UserHandle(UserHandle.USER_CURRENT)) context.startActivityAsUser(intent, UserHandle(UserHandle.USER_CURRENT))
return true return true
} }

View File

@@ -555,7 +555,8 @@ public class UserSettings extends SettingsPreferenceFragment
} }
private void launchChooseLockscreen() { private void launchChooseLockscreen() {
Intent chooseLockIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD); Intent chooseLockIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD)
.setPackage(getContext().getPackageName());
chooseLockIntent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_INSECURE_OPTIONS, chooseLockIntent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_INSECURE_OPTIONS,
true); true);
startActivityForResult(chooseLockIntent, REQUEST_CHOOSE_LOCK); startActivityForResult(chooseLockIntent, REQUEST_CHOOSE_LOCK);

View File

@@ -21,7 +21,11 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.provider.Settings; import android.provider.Settings;
@@ -48,7 +52,10 @@ public class LiveCaptionPreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
mContext = ApplicationProvider.getApplicationContext(); mContext = spy(ApplicationProvider.getApplicationContext());
PackageManager pm = spy(mContext.getPackageManager());
doReturn(pm).when(mContext).getPackageManager();
doReturn("com.caption").when(pm).getSystemCaptionsServicePackageName();
mController = new LiveCaptionPreferenceController(mContext, "test_key"); mController = new LiveCaptionPreferenceController(mContext, "test_key");
mLiveCaptionPreference = new Preference(mContext); mLiveCaptionPreference = new Preference(mContext);
mLiveCaptionPreference.setSummary(R.string.live_caption_summary); mLiveCaptionPreference.setSummary(R.string.live_caption_summary);