Sort widgets list based on intent-filter priority.
- Sort based on priority, also group them in PreferenceCategory. So category is divided by horizontal lines. - Also removed a bunch of intent-filter for VOICE_LAUNCH. I don't think we support them any more. If we see bugs, can easily put them back. Change-Id: I286a6bdf8b3c2eb716a36c6a061fc54a8010d8f6 Fixes: 74806595 Test: manual
This commit is contained in:
@@ -244,10 +244,8 @@
|
||||
<action android:name="android.settings.WIFI_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="1">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
@@ -391,9 +389,8 @@
|
||||
android:label="@string/devices_title"
|
||||
android:targetActivity=".Settings$ConnectedDeviceDashboardActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="10">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
@@ -470,9 +467,8 @@
|
||||
<action android:name="com.android.settings.WIFI_TETHER_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="4">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
@@ -513,10 +509,8 @@
|
||||
<action android:name="android.net.vpn.SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="5">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
@@ -729,9 +723,8 @@
|
||||
<action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="41">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
@@ -885,10 +878,8 @@
|
||||
<action android:name="android.settings.DISPLAY_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="30">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="7">
|
||||
@@ -904,15 +895,6 @@
|
||||
android:resource="@string/display_dashboard_summary"/>
|
||||
</activity>
|
||||
|
||||
<!-- Keep compatibility with old shortcuts. -->
|
||||
<activity-alias android:name="DisplaySettings"
|
||||
android:label="@string/display_settings"
|
||||
android:exported="true"
|
||||
android:targetActivity="Settings$DisplaySettingsActivity">
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.DisplaySettings" />
|
||||
</activity-alias>
|
||||
|
||||
<activity
|
||||
android:name="Settings$NightDisplaySettingsActivity"
|
||||
android:label="@string/night_display_title"
|
||||
@@ -920,9 +902,8 @@
|
||||
android:icon="@drawable/ic_settings_night_display"
|
||||
android:taskAffinity="com.android.settings"
|
||||
android:parentActivityName="Settings">
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="32">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="1">
|
||||
@@ -965,10 +946,8 @@
|
||||
<action android:name="android.settings.DEVICE_NAME" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="71">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="270">
|
||||
@@ -1009,10 +988,8 @@
|
||||
<action android:name="android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="20">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
@@ -1197,9 +1174,8 @@
|
||||
android:label="@string/notification_log_title"
|
||||
android:taskAffinity="com.android.settings"
|
||||
android:parentActivityName="Settings">
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="22">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
@@ -1227,10 +1203,8 @@
|
||||
<action android:name="android.settings.LOCATION_SOURCE_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="52">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
@@ -1421,10 +1395,8 @@
|
||||
<action android:name="android.settings.ACCESSIBILITY_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="60">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="2">
|
||||
@@ -1752,11 +1724,9 @@
|
||||
<action android:name="android.settings.MEMORY_CARD_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="50">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="5">
|
||||
<action android:name="com.android.settings.action.SETTINGS" />
|
||||
@@ -2156,9 +2126,8 @@
|
||||
<action android:name="android.intent.action.POWER_USAGE_SUMMARY" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="51">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="8">
|
||||
@@ -2310,9 +2279,8 @@
|
||||
<action android:name="android.settings.DATA_USAGE_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="3">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="10">
|
||||
@@ -2500,9 +2468,8 @@
|
||||
<action android:name="android.settings.NOTIFICATION_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="21">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="160">
|
||||
@@ -2518,7 +2485,6 @@
|
||||
android:value="true" />
|
||||
</activity>
|
||||
|
||||
<!-- Keep compatibility with old shortcuts. -->
|
||||
<activity
|
||||
android:name="Settings$SoundSettingsActivity"
|
||||
android:label="@string/sound_settings"
|
||||
@@ -2532,10 +2498,8 @@
|
||||
<action android:name="android.settings.ACTION_OTHER_SOUND_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="40">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="6">
|
||||
@@ -2986,7 +2950,7 @@
|
||||
<action android:name="android.settings.SYNC_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="53">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
@@ -3007,7 +2971,7 @@
|
||||
<intent-filter android:priority="-1">
|
||||
<action android:name="com.android.settings.action.SETTINGS"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<intent-filter android:priority="70">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
|
@@ -45,10 +45,13 @@ import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
|
||||
/**
|
||||
@@ -97,9 +100,26 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
|
||||
group.removeAll();
|
||||
final List<ResolveInfo> shortcuts = queryShortcuts();
|
||||
final Context uiContext = preference.getContext();
|
||||
if (shortcuts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PreferenceCategory category = new PreferenceCategory(uiContext);
|
||||
group.addPreference(category);
|
||||
int bucket = 0;
|
||||
for (ResolveInfo info : shortcuts) {
|
||||
// Priority is not consecutive (aka, jumped), add a divider between prefs.
|
||||
final int currentBucket = info.priority / 10;
|
||||
boolean needDivider = currentBucket != bucket;
|
||||
bucket = currentBucket;
|
||||
if (needDivider) {
|
||||
// add a new Category
|
||||
category = new PreferenceCategory(uiContext);
|
||||
group.addPreference(category);
|
||||
}
|
||||
|
||||
final Preference pref = new Preference(uiContext);
|
||||
pref.setTitle(info.loadLabel(mPackageManager));
|
||||
pref.setKey(info.activityInfo.getComponentName().flattenToString());
|
||||
pref.setOnPreferenceClickListener(clickTarget -> {
|
||||
if (mHost == null) {
|
||||
return false;
|
||||
@@ -112,7 +132,7 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
|
||||
mHost.finish();
|
||||
return true;
|
||||
});
|
||||
group.addPreference(pref);
|
||||
category.addPreference(pref);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +204,7 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
|
||||
}
|
||||
shortcuts.add(info);
|
||||
}
|
||||
Collections.sort(shortcuts, SHORTCUT_COMPARATOR);
|
||||
return shortcuts;
|
||||
}
|
||||
|
||||
@@ -228,4 +249,13 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
|
||||
view.draw(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private static final Comparator<ResolveInfo> SHORTCUT_COMPARATOR =
|
||||
new Comparator<ResolveInfo>() {
|
||||
|
||||
@Override
|
||||
public int compare(ResolveInfo i1, ResolveInfo i2) {
|
||||
return i1.priority - i2.priority;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -104,7 +104,7 @@ public class CreateShortcutPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryActivities_shouldOnlyIncludeSystemApp() {
|
||||
public void queryShortcuts_shouldOnlyIncludeSystemApp() {
|
||||
final ResolveInfo ri1 = new ResolveInfo();
|
||||
ri1.activityInfo = new ActivityInfo();
|
||||
ri1.activityInfo.name = "activity1";
|
||||
@@ -124,4 +124,30 @@ public class CreateShortcutPreferenceControllerTest {
|
||||
assertThat(info).hasSize(1);
|
||||
assertThat(info.get(0)).isEqualTo(ri2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryShortcuts_shouldSortBasedOnPriority() {
|
||||
final ResolveInfo ri1 = new ResolveInfo();
|
||||
ri1.priority = 100;
|
||||
ri1.activityInfo = new ActivityInfo();
|
||||
ri1.activityInfo.name = "activity1";
|
||||
ri1.activityInfo.applicationInfo = new ApplicationInfo();
|
||||
ri1.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
||||
|
||||
final ResolveInfo ri2 = new ResolveInfo();
|
||||
ri1.priority = 50;
|
||||
ri2.activityInfo = new ActivityInfo();
|
||||
ri2.activityInfo.name = "activity2";
|
||||
ri2.activityInfo.applicationInfo = new ApplicationInfo();
|
||||
ri2.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
||||
|
||||
mPackageManager.addResolveInfoForIntent(
|
||||
new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE),
|
||||
Arrays.asList(ri1, ri2));
|
||||
|
||||
final List<ResolveInfo> info = mController.queryShortcuts();
|
||||
assertThat(info).hasSize(2);
|
||||
assertThat(info.get(0)).isEqualTo(ri2);
|
||||
assertThat(info.get(1)).isEqualTo(ri1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user