New SystemUpdateRepository
Extract getSystemUpdateIntent, and add unit test. Bug: 311110616 Test: manual - on "Software updates" page Test: unit test Change-Id: Ic7c06490d1d324705f547b2394794605e85485a4
This commit is contained in:
@@ -42,7 +42,6 @@ import android.content.pm.IPackageManager;
|
||||
import android.content.pm.IntentFilterVerificationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.pm.UserProperties;
|
||||
import android.content.res.Configuration;
|
||||
@@ -107,8 +106,6 @@ import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
|
||||
import com.android.internal.app.UnlaunchableAppActivity;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
@@ -179,61 +176,6 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
public static final String PROPERTY_DELETE_ALL_APP_CLONES_ENABLED =
|
||||
"delete_all_app_clones_enabled";
|
||||
|
||||
/**
|
||||
* Finds a matching activity for a preference's intent. If a matching
|
||||
* activity is not found, it will remove the preference.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param parentPreferenceGroup The preference group that contains the
|
||||
* preference whose intent is being resolved.
|
||||
* @param preferenceKey The key of the preference whose intent is being
|
||||
* resolved.
|
||||
* @param flags 0 or one or more of
|
||||
* {@link #UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY}
|
||||
* .
|
||||
* @return Whether an activity was found. If false, the preference was
|
||||
* removed.
|
||||
*/
|
||||
public static boolean updatePreferenceToSpecificActivityOrRemove(Context context,
|
||||
PreferenceGroup parentPreferenceGroup, String preferenceKey, int flags) {
|
||||
|
||||
final Preference preference = parentPreferenceGroup.findPreference(preferenceKey);
|
||||
if (preference == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Intent intent = preference.getIntent();
|
||||
if (intent != null) {
|
||||
// Find the activity that is in the system image
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
|
||||
final int listSize = list.size();
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
final ResolveInfo resolveInfo = list.get(i);
|
||||
if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)
|
||||
!= 0) {
|
||||
|
||||
// Replace the intent with this specific activity
|
||||
preference.setIntent(new Intent().setClassName(
|
||||
resolveInfo.activityInfo.packageName,
|
||||
resolveInfo.activityInfo.name));
|
||||
|
||||
if ((flags & UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY) != 0) {
|
||||
// Set the preference title to the activity's label
|
||||
preference.setTitle(resolveInfo.loadLabel(pm));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Did not find a matching activity, so remove the preference
|
||||
parentPreferenceGroup.removePreference(preference);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Monkey is running.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user