Merge "Fix NPE when loading recently opened apps on the Apps page" into udc-dev am: 9ea6429756
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23493102 Change-Id: I038f026adeb1a32550cdbadb446268b325b695d1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -484,8 +484,9 @@ public class ApplicationsState {
|
|||||||
if (DEBUG_LOCKING) Log.v(TAG, "getEntry about to acquire lock...");
|
if (DEBUG_LOCKING) Log.v(TAG, "getEntry about to acquire lock...");
|
||||||
synchronized (mEntriesMap) {
|
synchronized (mEntriesMap) {
|
||||||
AppEntry entry = null;
|
AppEntry entry = null;
|
||||||
if (mEntriesMap.contains(userId)) {
|
HashMap<String, AppEntry> userEntriesMap = mEntriesMap.get(userId);
|
||||||
entry = mEntriesMap.get(userId).get(packageName);
|
if (userEntriesMap != null) {
|
||||||
|
entry = userEntriesMap.get(packageName);
|
||||||
}
|
}
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
ApplicationInfo info = getAppInfoLocked(packageName, userId);
|
ApplicationInfo info = getAppInfoLocked(packageName, userId);
|
||||||
@@ -735,8 +736,9 @@ public class ApplicationsState {
|
|||||||
private AppEntry getEntryLocked(ApplicationInfo info) {
|
private AppEntry getEntryLocked(ApplicationInfo info) {
|
||||||
int userId = UserHandle.getUserId(info.uid);
|
int userId = UserHandle.getUserId(info.uid);
|
||||||
AppEntry entry = null;
|
AppEntry entry = null;
|
||||||
if (mEntriesMap.contains(userId)) {
|
HashMap<String, AppEntry> userEntriesMap = mEntriesMap.get(userId);
|
||||||
entry = mEntriesMap.get(userId).get(info.packageName);
|
if (userEntriesMap != null) {
|
||||||
|
entry = userEntriesMap.get(info.packageName);
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.i(TAG, "Looking up entry of pkg " + info.packageName + ": " + entry);
|
Log.i(TAG, "Looking up entry of pkg " + info.packageName + ": " + entry);
|
||||||
@@ -752,8 +754,11 @@ public class ApplicationsState {
|
|||||||
Log.i(TAG, "Creating AppEntry for " + info.packageName);
|
Log.i(TAG, "Creating AppEntry for " + info.packageName);
|
||||||
}
|
}
|
||||||
entry = new AppEntry(mContext, info, mCurId++);
|
entry = new AppEntry(mContext, info, mCurId++);
|
||||||
mEntriesMap.get(userId).put(info.packageName, entry);
|
userEntriesMap = mEntriesMap.get(userId);
|
||||||
|
if (userEntriesMap != null) {
|
||||||
|
userEntriesMap.put(info.packageName, entry);
|
||||||
mAppEntries.add(entry);
|
mAppEntries.add(entry);
|
||||||
|
}
|
||||||
} else if (entry.info != info) {
|
} else if (entry.info != info) {
|
||||||
entry.info = info;
|
entry.info = info;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -804,7 +804,7 @@ public class ApplicationsStateRoboTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEntry_validUserId_shouldReturnEntry() {
|
public void getEntry_hasCache_shouldReturnCacheEntry() {
|
||||||
mApplicationsState.mEntriesMap.put(/* userId= */ 0, new HashMap<>());
|
mApplicationsState.mEntriesMap.put(/* userId= */ 0, new HashMap<>());
|
||||||
addApp(PKG_1, /* id= */ 1);
|
addApp(PKG_1, /* id= */ 1);
|
||||||
|
|
||||||
@@ -813,10 +813,13 @@ public class ApplicationsStateRoboTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEntry_invalidUserId_shouldReturnNull() {
|
public void getEntry_hasNoCache_shouldReturnEntry() {
|
||||||
mApplicationsState.mEntriesMap.put(/* userId= */ 0, new HashMap<>());
|
mApplicationsState.mEntriesMap.clear();
|
||||||
addApp(PKG_1, /* id= */ 1);
|
ApplicationInfo appInfo = createApplicationInfo(PKG_1, /* uid= */ 0);
|
||||||
|
mApplicationsState.mApplications.add(appInfo);
|
||||||
|
mApplicationsState.mSystemModules.put(PKG_1, /* value= */ false);
|
||||||
|
|
||||||
assertThat(mApplicationsState.getEntry(PKG_1, /* userId= */ -1)).isNull();
|
assertThat(mApplicationsState.getEntry(PKG_1, /* userId= */ 0).info.packageName)
|
||||||
|
.isEqualTo(PKG_1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user