[Safer intents] Permission controller
To avoid implicit intents, make intents launch explicitly.
Test: build, manual
Bug: 323061508
Change-Id: Ib95b417fc8682f690890fc55f321b4fece2c0369
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 2f6f04a..00ffc26 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -140,7 +140,8 @@
if (SafetyCenterManagerWrapper.get().isEnabled(this)) {
try {
- startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
+ startActivity(new Intent(Intent.ACTION_SAFETY_CENTER)
+ .setPackage(getPackageManager().getPermissionControllerPackageName()));
finish();
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Unable to open safety center", e);
@@ -235,7 +236,8 @@
if (ACTION_PRIVACY_SETTINGS.equals(getIntent().getAction())
&& SafetyCenterManagerWrapper.get().isEnabled(this)) {
try {
- startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
+ startActivity(new Intent(Intent.ACTION_SAFETY_CENTER)
+ .setPackage(getPackageManager().getPermissionControllerPackageName()));
finish();
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Unable to open safety center", e);
diff --git a/src/com/android/settings/applications/DefaultAppsPreferenceController.java b/src/com/android/settings/applications/DefaultAppsPreferenceController.java
index c5b849d..6320db6 100644
--- a/src/com/android/settings/applications/DefaultAppsPreferenceController.java
+++ b/src/com/android/settings/applications/DefaultAppsPreferenceController.java
@@ -18,11 +18,16 @@
import android.app.role.RoleManager;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.icu.text.ListFormatter;
+import android.provider.Settings;
import android.text.TextUtils;
+import androidx.annotation.NonNull;
import androidx.core.text.BidiFormatter;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.applications.AppUtils;
@@ -48,6 +53,17 @@
}
@Override
+ public void displayPreference(@NonNull PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ Preference pref = screen.findPreference(getPreferenceKey());
+ if (pref != null) {
+ pref.setIntent(new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS)
+ .setPackage(mPackageManager.getPermissionControllerPackageName()));
+ }
+ }
+
+ @Override
public CharSequence getSummary() {
final List<CharSequence> defaultAppLabels = new ArrayList<>();
final CharSequence defaultBrowserLabel = getDefaultAppLabel(RoleManager.ROLE_BROWSER);
diff --git a/src/com/android/settings/applications/HibernatedAppsPreferenceController.java b/src/com/android/settings/applications/HibernatedAppsPreferenceController.java
index eb6edb2..d85f8aa 100644
--- a/src/com/android/settings/applications/HibernatedAppsPreferenceController.java
+++ b/src/com/android/settings/applications/HibernatedAppsPreferenceController.java
@@ -21,6 +21,7 @@
import static com.android.settings.Utils.PROPERTY_APP_HIBERNATION_ENABLED;
import android.content.Context;
+import android.content.Intent;
import android.icu.text.MessageFormat;
import android.permission.PermissionControllerManager;
import android.provider.DeviceConfig;
@@ -85,6 +86,12 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mScreen = screen;
+
+ Preference pref = screen.findPreference(getPreferenceKey());
+ if (pref != null) {
+ pref.setIntent(new Intent(Intent.ACTION_MANAGE_UNUSED_APPS)
+ .setPackage(mContext.getPackageManager().getPermissionControllerPackageName()));
+ }
}
/**
diff --git a/src/com/android/settings/applications/appinfo/AppPermissionPreferenceController.java b/src/com/android/settings/applications/appinfo/AppPermissionPreferenceController.java
index b7069d9..6ba4e46 100644
--- a/src/com/android/settings/applications/appinfo/AppPermissionPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppPermissionPreferenceController.java
@@ -132,6 +132,7 @@
private void startManagePermissionsActivity() {
// start new activity to manage app permissions
final Intent permIntent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
+ permIntent.setPackage(mPackageManager.getPermissionControllerPackageName());
permIntent.putExtra(Intent.EXTRA_PACKAGE_NAME, mParent.getAppEntry().info.packageName);
permIntent.putExtra(EXTRA_HIDE_INFO_BUTTON, true);
Activity activity = mParent.getActivity();
diff --git a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
index 5a1883b..184f907 100644
--- a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
+++ b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
@@ -105,6 +105,7 @@
return false;
}
final Intent intent = new Intent(Intent.ACTION_MANAGE_DEFAULT_APP)
+ .setPackage(mContext.getPackageManager().getPermissionControllerPackageName())
.putExtra(Intent.EXTRA_ROLE_NAME, mRoleName);
mContext.startActivity(intent);
return true;
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index c2fabff..b392d9a 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -921,7 +921,9 @@
.setResultListener(this, ADVANCED_SETTINGS)
.launch();
} else {
- Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
+ Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS)
+ .setPackage(getContext()
+ .getPackageManager().getPermissionControllerPackageName());
startActivityForResult(intent, ADVANCED_SETTINGS);
}
return true;
diff --git a/src/com/android/settings/applications/specialaccess/DefaultPaymentSettingsPreferenceController.java b/src/com/android/settings/applications/specialaccess/DefaultPaymentSettingsPreferenceController.java
index c66c97e..c76e448 100644
--- a/src/com/android/settings/applications/specialaccess/DefaultPaymentSettingsPreferenceController.java
+++ b/src/com/android/settings/applications/specialaccess/DefaultPaymentSettingsPreferenceController.java
@@ -71,7 +71,8 @@
&& mPreferenceKey.equals(preference.getKey())) {
RoleManager roleManager = mContext.getSystemService(RoleManager.class);
if (roleManager.isRoleAvailable(RoleManager.ROLE_WALLET)) {
- Intent intent = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
+ Intent intent = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT)
+ .setPackage(mPackageManager.getPermissionControllerPackageName());
mContext.startActivity(intent);
return true;
}
diff --git a/src/com/android/settings/location/AppLocationPermissionPreferenceController.java b/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
index 37bbd08..6a61e1a 100644
--- a/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
+++ b/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
@@ -4,14 +4,18 @@
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import android.content.Context;
+import android.content.Intent;
import android.location.LocationManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.permission.PermissionControllerManager;
import android.provider.Settings;
+import android.text.TextUtils;
+import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.Utils;
@@ -69,6 +73,21 @@
}
}
+ @Override
+ public void displayPreference(@NonNull PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ Preference pref = screen.findPreference(getPreferenceKey());
+ if (pref != null) {
+ pref.setIntent(new Intent(Intent.ACTION_MANAGE_PERMISSION_APPS)
+ .setPackage(mContext.getPackageManager().getPermissionControllerPackageName())
+ .putExtra(TextUtils.equals(pref.getKey(), "app_level_permissions")
+ ? Intent.EXTRA_PERMISSION_NAME
+ : Intent.EXTRA_PERMISSION_GROUP_NAME,
+ "android.permission-group.LOCATION"));
+ }
+ }
+
private void setAppCounts(int numTotal, int numHasLocation) {
mNumTotal = numTotal;
mNumHasLocation = numHasLocation;
diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
index 61682d0..a5c0e55 100644
--- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
@@ -67,6 +67,7 @@
@Override
public boolean onPreferenceClick(Preference preference) {
final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION);
+ intent.setPackage(mContext.getPackageManager().getPermissionControllerPackageName());
intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, LOCATION);
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mPackage);
intent.putExtra(Intent.EXTRA_USER, mUserHandle);
diff --git a/src/com/android/settings/privacy/AccessibilityUsagePreferenceController.java b/src/com/android/settings/privacy/AccessibilityUsagePreferenceController.java
index a78ccee..6a46a98 100644
--- a/src/com/android/settings/privacy/AccessibilityUsagePreferenceController.java
+++ b/src/com/android/settings/privacy/AccessibilityUsagePreferenceController.java
@@ -18,10 +18,12 @@
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
+import android.content.Intent;
import android.view.accessibility.AccessibilityManager;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@@ -64,4 +66,15 @@
return StringUtil.getIcuPluralsString(mContext, mEnabledServiceInfos.size(),
R.string.accessibility_usage_summary);
}
+
+ @Override
+ public void displayPreference(@NonNull PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ Preference pref = screen.findPreference(getPreferenceKey());
+ if (pref != null) {
+ pref.setIntent(new Intent(Intent.ACTION_REVIEW_ACCESSIBILITY_SERVICES)
+ .setPackage(mContext.getPackageManager().getPermissionControllerPackageName()));
+ }
+ }
}
diff --git a/src/com/android/settings/privacy/AppDataSharingUpdatesPreferenceController.java b/src/com/android/settings/privacy/AppDataSharingUpdatesPreferenceController.java
index 5372a16..5d634eb 100644
--- a/src/com/android/settings/privacy/AppDataSharingUpdatesPreferenceController.java
+++ b/src/com/android/settings/privacy/AppDataSharingUpdatesPreferenceController.java
@@ -19,9 +19,14 @@
import static android.safetylabel.SafetyLabelConstants.SAFETY_LABEL_CHANGE_NOTIFICATIONS_ENABLED;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.provider.DeviceConfig;
+import androidx.annotation.NonNull;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.core.BasePreferenceController;
/**
@@ -35,6 +40,17 @@
}
@Override
+ public void displayPreference(@NonNull PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ Preference pref = screen.findPreference(getPreferenceKey());
+ if (pref != null) {
+ pref.setIntent(new Intent(Intent.ACTION_REVIEW_APP_DATA_SHARING_UPDATES)
+ .setPackage(mContext.getPackageManager().getPermissionControllerPackageName()));
+ }
+ }
+
+ @Override
public int getAvailabilityStatus() {
return isPrivacySafetyLabelChangeNotificationsEnabled(mContext)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
diff --git a/src/com/android/settings/privacy/ManagePermissionsPreferenceController.java b/src/com/android/settings/privacy/ManagePermissionsPreferenceController.java
new file mode 100644
index 0000000..441c5c9
--- /dev/null
+++ b/src/com/android/settings/privacy/ManagePermissionsPreferenceController.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2024 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 com.android.settings.privacy;
+
+import android.content.Context;
+import android.content.Intent;
+
+import androidx.annotation.NonNull;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * The preference controller for managing permissions
+ */
+public class ManagePermissionsPreferenceController extends BasePreferenceController {
+
+ public ManagePermissionsPreferenceController(@NonNull Context context,
+ @NonNull String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public void displayPreference(@NonNull PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ Preference pref = screen.findPreference(getPreferenceKey());
+ if (pref != null) {
+ pref.setIntent(new Intent(Intent.ACTION_MANAGE_PERMISSIONS)
+ .setPackage(mContext.getPackageManager().getPermissionControllerPackageName()));
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+}
diff --git a/src/com/android/settings/privacy/PrivacyHubPreferenceController.java b/src/com/android/settings/privacy/PrivacyHubPreferenceController.java
index b68b5ec..20e5290 100644
--- a/src/com/android/settings/privacy/PrivacyHubPreferenceController.java
+++ b/src/com/android/settings/privacy/PrivacyHubPreferenceController.java
@@ -17,9 +17,12 @@
package com.android.settings.privacy;
import android.content.Context;
+import android.content.Intent;
import android.provider.DeviceConfig;
import androidx.annotation.NonNull;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
@@ -38,4 +41,15 @@
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
PROPERTY_PRIVACY_HUB_ENABLED, true) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
+
+ @Override
+ public void displayPreference(@NonNull PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ Preference pref = screen.findPreference(getPreferenceKey());
+ if (pref != null) {
+ pref.setIntent(new Intent(Intent.ACTION_REVIEW_PERMISSION_USAGE)
+ .setPackage(mContext.getPackageManager().getPermissionControllerPackageName()));
+ }
+ }
}
diff --git a/src/com/android/settings/safetycenter/TopLevelSafetyCenterEntryPreferenceController.java b/src/com/android/settings/safetycenter/TopLevelSafetyCenterEntryPreferenceController.java
index af9509b..64d78b8 100644
--- a/src/com/android/settings/safetycenter/TopLevelSafetyCenterEntryPreferenceController.java
+++ b/src/com/android/settings/safetycenter/TopLevelSafetyCenterEntryPreferenceController.java
@@ -50,7 +50,8 @@
}
try {
- mContext.startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
+ mContext.startActivity(new Intent(Intent.ACTION_SAFETY_CENTER)
+ .setPackage(mContext.getPackageManager().getPermissionControllerPackageName()));
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Unable to open safety center", e);
return false;