Return false if can't find package info

Change-Id: Iaf667e0977f60abcbf3eb76c46c46f591c00123e
Fixes: 66981347
Test: robotests
This commit is contained in:
Fan Zhang
2017-10-02 15:21:33 -07:00
parent feaa82ce8f
commit 883d8e7ed1
2 changed files with 17 additions and 7 deletions

View File

@@ -137,9 +137,13 @@ public class UsageAccessDetails extends AppInfoWithHeader implements OnPreferenc
@Override
protected boolean refreshUi() {
if (mPackageInfo == null) {
retrieveAppEntry();
if (mAppEntry == null) {
return false;
}
if (mPackageInfo == null) {
return false; // onCreate must have failed, make sure to exit
}
mUsageState = mUsageBridge.getUsageInfo(mPackageName,
mPackageInfo.applicationInfo.uid);

View File

@@ -16,17 +16,20 @@
package com.android.settings.applications;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.os.RemoteException;
import android.os.Bundle;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.applications.ApplicationsState;
import org.junit.Before;
import org.junit.Test;
@@ -68,9 +71,12 @@ public class UsageAccessDetailsTest {
}
@Test
public void refreshUi_nullPackageInfo_shouldNotCrash() throws RemoteException {
mFragment.mPackageInfo = null;
mFragment.refreshUi();
// should not crash
public void refreshUi_hasNoAppEntry_shouldReturnFalse() {
mFragment.mState = mock(ApplicationsState.class);
mFragment.setArguments(new Bundle());
assertThat(mFragment.refreshUi()).isFalse();
assertThat(mFragment.mAppEntry).isNull();
assertThat(mFragment.mPackageInfo).isNull();
}
}