Merge "Load icon from correct package for Accessibility slices" into main
This commit is contained in:
@@ -24,6 +24,7 @@ import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
|
|||||||
|
|
||||||
import android.annotation.ColorInt;
|
import android.annotation.ColorInt;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
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;
|
||||||
@@ -47,6 +48,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SubSettings;
|
import com.android.settings.SubSettings;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settings.accessibility.AccessibilitySlicePreferenceController;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.SliderPreferenceController;
|
import com.android.settings.core.SliderPreferenceController;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
@@ -448,7 +450,17 @@ public class SliceBuilderUtils {
|
|||||||
iconResource = R.drawable.ic_settings_accent;
|
iconResource = R.drawable.ic_settings_accent;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
// LINT.IfChange(createA11yIcon)
|
||||||
|
if (AccessibilitySlicePreferenceController.class.getName().equals(
|
||||||
|
data.getPreferenceController())) {
|
||||||
|
ComponentName serviceComponent = ComponentName.unflattenFromString(data.getKey());
|
||||||
|
return IconCompat.createWithResource(
|
||||||
|
context.createPackageContext(serviceComponent.getPackageName(), 0),
|
||||||
|
iconResource);
|
||||||
|
// LINT.ThenChange()
|
||||||
|
} else {
|
||||||
return IconCompat.createWithResource(context, iconResource);
|
return IconCompat.createWithResource(context, iconResource);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(TAG, "Falling back to settings icon because there is an error getting slice icon "
|
Log.w(TAG, "Falling back to settings icon because there is an error getting slice icon "
|
||||||
+ data.getUri(), e);
|
+ data.getUri(), e);
|
||||||
|
@@ -274,6 +274,12 @@ class SliceDataConverter {
|
|||||||
final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
|
final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
|
||||||
final String packageName = serviceInfo.packageName;
|
final String packageName = serviceInfo.packageName;
|
||||||
final ComponentName componentName = new ComponentName(packageName, serviceInfo.name);
|
final ComponentName componentName = new ComponentName(packageName, serviceInfo.name);
|
||||||
|
|
||||||
|
// If we change the flattenedName that is used to be set as a key of the Slice, we
|
||||||
|
// need to make corresponding change in SliceBuilderUtils, since we rely on the
|
||||||
|
// the A11y Service Slice's key to be a ComponentName to get the correct package name
|
||||||
|
// to grab the icon belongs to that package.
|
||||||
|
// LINT.IfChange
|
||||||
final String flattenedName = componentName.flattenToString();
|
final String flattenedName = componentName.flattenToString();
|
||||||
|
|
||||||
if (!a11yServiceNames.contains(flattenedName)) {
|
if (!a11yServiceNames.contains(flattenedName)) {
|
||||||
@@ -287,6 +293,7 @@ class SliceDataConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sliceDataBuilder.setKey(flattenedName)
|
sliceDataBuilder.setKey(flattenedName)
|
||||||
|
// LINT.ThenChange(SliceBuilderUtils.java:createA11yIcon)
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setUri(new Uri.Builder()
|
.setUri(new Uri.Builder()
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||||
|
Reference in New Issue
Block a user