[Panlingual] Improve UI can not show on at first.

- Settings take much time to get the info of app launcher entry. User
    may not see the panlingual UI at first after boot to home.
  - Does small refactor to somewhere.

Bug: 218416193
Test: local
Test: atest pass
Change-Id: Ibfb91f0bb8d8ff54cadd041250b3cff252dbe591
(cherry picked from commit cae20ce2f7)
Merged-In: Ibfb91f0bb8d8ff54cadd041250b3cff252dbe591
This commit is contained in:
tom hsu
2022-02-15 18:55:49 +08:00
committed by Tom Hsu
parent 657ad4c091
commit ea9e627c1c
5 changed files with 78 additions and 47 deletions

View File

@@ -16,26 +16,35 @@
package com.android.settings.applications;
import android.annotation.NonNull;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Log;
import com.android.settings.R;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import java.util.List;
/** This class provides methods that help dealing with per app locale. */
public class AppLocaleUtil {
private static final String TAG = AppLocaleUtil.class.getSimpleName();
public static final Intent LAUNCHER_ENTRY_INTENT =
new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
/**
* Decides the UI display of per app locale.
*/
public static boolean canDisplayLocaleUi(Context context, AppEntry app) {
return !isDisallowedPackage(context, app.info.packageName)
&& !isSignedWithPlatformKey(context, app.info.packageName)
&& app.hasLauncherEntry;
public static boolean canDisplayLocaleUi(
@NonNull Context context,
@NonNull String packageName,
@NonNull List<ResolveInfo> infos) {
return !isDisallowedPackage(context, packageName)
&& !isSignedWithPlatformKey(context, packageName)
&& hasLauncherEntry(packageName, infos);
}
private static boolean isDisallowedPackage(Context context, String packageName) {
@@ -65,4 +74,9 @@ public class AppLocaleUtil {
}
return packageInfo.applicationInfo.isSignedWithPlatformKey();
}
private static boolean hasLauncherEntry(String packageName, List<ResolveInfo> infos) {
return infos.stream()
.anyMatch(info -> info.activityInfo.packageName.equals(packageName));
}
}