Don't show an app icon for uninitalized user
System apps running can post toasts before the app packages have been initialized by ApplicationsState. If this happens, don't check for the appEntry, instead automatically hide its icon from the toast. Test: manual Fixes: 182605816 Change-Id: I7e764341d049095da19f391ba9c944871584b921
This commit is contained in:
@@ -1496,6 +1496,13 @@ public class ApplicationsState {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the packages for the user have been initialized.
|
||||
*/
|
||||
public boolean isUserAdded(int userId) {
|
||||
return mEntriesMap.contains(userId);
|
||||
}
|
||||
|
||||
public interface Callbacks {
|
||||
void onRunningStateChanged(boolean running);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -43,6 +44,7 @@ import com.android.systemui.plugins.ToastPlugin;
|
||||
* directly. Instead, use {@link ToastFactory#createToast}.
|
||||
*/
|
||||
public class SystemUIToast implements ToastPlugin.Toast {
|
||||
static final String TAG = "SystemUIToast";
|
||||
final Context mContext;
|
||||
final CharSequence mText;
|
||||
final ToastPlugin.Toast mPluginToast;
|
||||
@@ -225,8 +227,12 @@ public class SystemUIToast implements ToastPlugin.Toast {
|
||||
int userId) {
|
||||
final ApplicationsState appState =
|
||||
ApplicationsState.getInstance((Application) context.getApplicationContext());
|
||||
if (!appState.isUserAdded(userId)) {
|
||||
Log.d(TAG, "user hasn't been fully initialized, not showing an app icon for "
|
||||
+ "packageName=" + packageName);
|
||||
return null;
|
||||
}
|
||||
final AppEntry appEntry = appState.getEntry(packageName, userId);
|
||||
|
||||
if (!ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(appEntry)) {
|
||||
return null;
|
||||
}
|
||||
@@ -237,6 +243,5 @@ public class SystemUIToast implements ToastPlugin.Toast {
|
||||
Bitmap iconBmp = iconFactory.createBadgedIconBitmap(
|
||||
appInfo.loadUnbadgedIcon(context.getPackageManager()), user, true).icon;
|
||||
return new BitmapDrawable(context.getResources(), iconBmp);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user