Merge "[Safer intents] Permission controller" into main

This commit is contained in:
Jason Chiu
2024-03-29 09:20:28 +00:00
committed by Android (Google) Code Review
22 changed files with 182 additions and 49 deletions

View File

@@ -140,7 +140,8 @@ public class Settings extends SettingsActivity {
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 @@ public class Settings extends SettingsActivity {
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);

View File

@@ -18,11 +18,16 @@ package com.android.settings.applications;
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;
@@ -47,6 +52,17 @@ public class DefaultAppsPreferenceController extends BasePreferenceController {
return AVAILABLE;
}
@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<>();

View File

@@ -21,6 +21,7 @@ import static android.provider.DeviceConfig.NAMESPACE_APP_HIBERNATION;
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 final class HibernatedAppsPreferenceController extends BasePreferenceCont
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()));
}
}
/**

View File

@@ -132,6 +132,7 @@ public class AppPermissionPreferenceController extends AppInfoPreferenceControll
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();

View File

@@ -105,6 +105,7 @@ public abstract class DefaultAppShortcutPreferenceControllerBase extends BasePre
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;

View File

@@ -921,7 +921,9 @@ public class ManageApplications extends InstrumentedFragment
.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;

View File

@@ -71,7 +71,8 @@ public class DefaultPaymentSettingsPreferenceController extends BasePreferenceCo
&& 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;
}

View File

@@ -4,14 +4,18 @@ import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
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 @@ public class AppLocationPermissionPreferenceController extends
}
}
@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;

View File

@@ -67,6 +67,7 @@ public class RecentLocationAccessPreferenceController extends LocationBasePrefer
@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);

View File

@@ -18,10 +18,12 @@ package com.android.settings.privacy;
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 @@ public class AccessibilityUsagePreferenceController extends BasePreferenceContro
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()));
}
}
}

View File

@@ -19,9 +19,14 @@ package com.android.settings.privacy;
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;
/**
@@ -34,6 +39,17 @@ public class AppDataSharingUpdatesPreferenceController extends BasePreferenceCon
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_REVIEW_APP_DATA_SHARING_UPDATES)
.setPackage(mContext.getPackageManager().getPermissionControllerPackageName()));
}
}
@Override
public int getAvailabilityStatus() {
return isPrivacySafetyLabelChangeNotificationsEnabled(mContext)

View File

@@ -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;
}
}

View File

@@ -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 @@ public final class PrivacyHubPreferenceController extends BasePreferenceControll
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()));
}
}
}

View File

@@ -50,7 +50,8 @@ public class TopLevelSafetyCenterEntryPreferenceController extends BasePreferenc
}
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;