Fix policy for platform compat UI
Only show debuggable apps on user builds. Also, only enable changes that are overrideable. Bug: 138280620 Bug: 144552011 Test: Settings->Developer Options->App Compatibility Changes on user build Test: atest PlatformCompatDashboardTest Exempt-From-Owner-Approval: Previously approved Change-Id: Ibf9611d1809492ebe979fc55f9331daf78ca9b27
This commit is contained in:
@@ -16,7 +16,9 @@
|
||||
|
||||
package com.android.settings.development.compat;
|
||||
|
||||
import static com.android.settings.development.AppPicker.EXTRA_DEBUGGABLE;
|
||||
import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_COMPAT_CHANGE_APP;
|
||||
import static com.android.internal.compat.OverrideAllowedState.ALLOWED;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
@@ -25,7 +27,9 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
@@ -37,9 +41,12 @@ import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.compat.AndroidBuildClassifier;
|
||||
import com.android.internal.compat.CompatibilityChangeConfig;
|
||||
import com.android.internal.compat.CompatibilityChangeInfo;
|
||||
import com.android.internal.compat.IPlatformCompat;
|
||||
import com.android.internal.compat.IOverrideValidator;
|
||||
import com.android.internal.compat.OverrideAllowedState;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.development.AppPicker;
|
||||
@@ -61,6 +68,8 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
||||
|
||||
private CompatibilityChangeInfo[] mChanges;
|
||||
|
||||
private AndroidBuildClassifier mAndroidBuildClassifier = new AndroidBuildClassifier();
|
||||
|
||||
@VisibleForTesting
|
||||
String mSelectedApp;
|
||||
|
||||
@@ -114,17 +123,21 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
||||
if (requestCode == REQUEST_COMPAT_CHANGE_APP) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
mSelectedApp = data.getAction();
|
||||
addPreferences();
|
||||
try {
|
||||
final ApplicationInfo applicationInfo = getApplicationInfo();
|
||||
addPreferences(applicationInfo);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
startAppPicker();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void addPreferences() {
|
||||
private void addPreferences(ApplicationInfo applicationInfo) {
|
||||
getPreferenceScreen().removeAll();
|
||||
getPreferenceScreen().addPreference(
|
||||
createAppPreference(getApplicationInfo().loadIcon(getPackageManager())));
|
||||
getPreferenceScreen().addPreference(createAppPreference(applicationInfo));
|
||||
// Differentiate compatibility changes into default enabled, default disabled and enabled
|
||||
// after target sdk.
|
||||
final CompatibilityChangeConfig configMappings = getAppChangeMappings();
|
||||
@@ -161,7 +174,7 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
||||
try {
|
||||
final ApplicationInfo applicationInfo = getApplicationInfo();
|
||||
return getPlatformCompat().getAppConfig(applicationInfo);
|
||||
} catch (RemoteException e) {
|
||||
} catch (RemoteException | PackageManager.NameNotFoundException e) {
|
||||
throw new RuntimeException("Could not get app config!", e);
|
||||
}
|
||||
}
|
||||
@@ -180,7 +193,15 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
||||
change.getName() != null ? change.getName() : "Change_" + change.getId();
|
||||
item.setSummary(changeName);
|
||||
item.setKey(changeName);
|
||||
item.setEnabled(true);
|
||||
boolean shouldEnable = true;
|
||||
try {
|
||||
shouldEnable = getPlatformCompat().getOverrideValidator()
|
||||
.getOverrideAllowedState(change.getId(), mSelectedApp)
|
||||
.state == ALLOWED;
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException("Could not check if change can be overridden for app.", e);
|
||||
}
|
||||
item.setEnabled(shouldEnable);
|
||||
item.setChecked(currentValue);
|
||||
item.setOnPreferenceChangeListener(
|
||||
new CompatChangePreferenceChangeListener(change.getId()));
|
||||
@@ -192,12 +213,8 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
||||
*
|
||||
* @return an {@link ApplicationInfo} instance.
|
||||
*/
|
||||
ApplicationInfo getApplicationInfo() {
|
||||
try {
|
||||
return getPackageManager().getApplicationInfo(mSelectedApp, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
throw new RuntimeException("Could not get ApplicationInfo for selected app!", e);
|
||||
}
|
||||
ApplicationInfo getApplicationInfo() throws PackageManager.NameNotFoundException {
|
||||
return getPackageManager().getApplicationInfo(mSelectedApp, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,9 +223,10 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
||||
* <p>The {@link Preference} contains the icon, package name and target SDK for the selected
|
||||
* app. Selecting this preference will also re-trigger the app selection dialog.</p>
|
||||
*/
|
||||
Preference createAppPreference(Drawable icon) {
|
||||
final ApplicationInfo applicationInfo = getApplicationInfo();
|
||||
final Preference appPreference = new Preference(getPreferenceScreen().getContext());
|
||||
Preference createAppPreference(ApplicationInfo applicationInfo) {
|
||||
final Context context = getPreferenceScreen().getContext();
|
||||
final Drawable icon = applicationInfo.loadIcon(context.getPackageManager());
|
||||
final Preference appPreference = new Preference(context);
|
||||
appPreference.setIcon(icon);
|
||||
appPreference.setSummary(mSelectedApp
|
||||
+ " SDK "
|
||||
@@ -243,6 +261,11 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
||||
|
||||
private void startAppPicker() {
|
||||
final Intent intent = new Intent(getContext(), AppPicker.class);
|
||||
// If build is neither userdebug nor eng, only include debuggable apps
|
||||
final boolean debuggableBuild = mAndroidBuildClassifier.isDebuggableBuild();
|
||||
if (!debuggableBuild) {
|
||||
intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true /* value */);
|
||||
}
|
||||
startActivityForResult(intent, REQUEST_COMPAT_CHANGE_APP);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user