Merge "Adds tests for Install Scenarios to DexManagerTests" am: 98432e96b0 am: 719599d844
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1634484 Change-Id: I33b77eb9e3601e2744e4e354d34a743e845bb773
This commit is contained in:
@@ -986,7 +986,7 @@ public class DexManager {
|
|||||||
* Fetches the battery manager object and caches it if it hasn't been fetched already.
|
* Fetches the battery manager object and caches it if it hasn't been fetched already.
|
||||||
*/
|
*/
|
||||||
private BatteryManager getBatteryManager() {
|
private BatteryManager getBatteryManager() {
|
||||||
if (mBatteryManager == null) {
|
if (mBatteryManager == null && mContext != null) {
|
||||||
mBatteryManager = mContext.getSystemService(BatteryManager.class);
|
mBatteryManager = mContext.getSystemService(BatteryManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1008,10 +1008,6 @@ public class DexManager {
|
|||||||
&& mPowerManager.getCurrentThermalStatus()
|
&& mPowerManager.getCurrentThermalStatus()
|
||||||
>= PowerManager.THERMAL_STATUS_SEVERE);
|
>= PowerManager.THERMAL_STATUS_SEVERE);
|
||||||
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "Battery, thermal, or memory are critical: " + isBtmCritical);
|
|
||||||
}
|
|
||||||
|
|
||||||
return isBtmCritical;
|
return isBtmCritical;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.pm.dex;
|
package com.android.server.pm.dex;
|
||||||
@@ -28,28 +28,34 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.IPackageManager;
|
import android.content.pm.IPackageManager;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.dx.mockito.inline.extended.ExtendedMockito;
|
||||||
|
import com.android.dx.mockito.inline.extended.StaticMockitoSession;
|
||||||
import com.android.server.pm.Installer;
|
import com.android.server.pm.Installer;
|
||||||
|
import com.android.server.pm.PackageManagerService;
|
||||||
|
|
||||||
import dalvik.system.DelegateLastClassLoader;
|
import dalvik.system.DelegateLastClassLoader;
|
||||||
import dalvik.system.PathClassLoader;
|
import dalvik.system.PathClassLoader;
|
||||||
import dalvik.system.VMRuntime;
|
import dalvik.system.VMRuntime;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
|
||||||
import org.mockito.junit.MockitoRule;
|
|
||||||
import org.mockito.quality.Strictness;
|
import org.mockito.quality.Strictness;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -69,9 +75,15 @@ public class DexManagerTests {
|
|||||||
DelegateLastClassLoader.class.getName();
|
DelegateLastClassLoader.class.getName();
|
||||||
private static final String UNSUPPORTED_CLASS_LOADER_NAME = "unsupported.class_loader";
|
private static final String UNSUPPORTED_CLASS_LOADER_NAME = "unsupported.class_loader";
|
||||||
|
|
||||||
@Rule public MockitoRule mockito = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);
|
private static final int TEST_BATTERY_LEVEL_CRITICAL = 10;
|
||||||
|
private static final int TEST_BATTERY_LEVEL_DEFAULT = 80;
|
||||||
|
|
||||||
|
public StaticMockitoSession mMockitoSession;
|
||||||
@Mock Installer mInstaller;
|
@Mock Installer mInstaller;
|
||||||
@Mock IPackageManager mPM;
|
@Mock IPackageManager mPM;
|
||||||
|
@Mock BatteryManager mMockBatteryManager;
|
||||||
|
@Mock PowerManager mMockPowerManager;
|
||||||
|
|
||||||
private final Object mInstallLock = new Object();
|
private final Object mInstallLock = new Object();
|
||||||
|
|
||||||
private DexManager mDexManager;
|
private DexManager mDexManager;
|
||||||
@@ -117,7 +129,37 @@ public class DexManagerTests {
|
|||||||
mSystemServerJarUpdatedContext = new TestData("android", isa, mUser0,
|
mSystemServerJarUpdatedContext = new TestData("android", isa, mUser0,
|
||||||
DELEGATE_LAST_CLASS_LOADER_NAME);
|
DELEGATE_LAST_CLASS_LOADER_NAME);
|
||||||
|
|
||||||
mDexManager = new DexManager(/*Context*/ null, mPM, /*PackageDexOptimizer*/ null,
|
// Initialize Static Mocking
|
||||||
|
|
||||||
|
mMockitoSession = ExtendedMockito.mockitoSession()
|
||||||
|
.initMocks(this)
|
||||||
|
.strictness(Strictness.LENIENT)
|
||||||
|
.startMocking();
|
||||||
|
|
||||||
|
// Mock....
|
||||||
|
|
||||||
|
mMockBatteryManager = ExtendedMockito.mock(BatteryManager.class);
|
||||||
|
mMockPowerManager = ExtendedMockito.mock(PowerManager.class);
|
||||||
|
|
||||||
|
setDefaultMockValues();
|
||||||
|
|
||||||
|
Resources mockResources = ExtendedMockito.mock(Resources.class);
|
||||||
|
ExtendedMockito.when(mockResources
|
||||||
|
.getInteger(com.android.internal.R.integer.config_criticalBatteryWarningLevel))
|
||||||
|
.thenReturn(15);
|
||||||
|
|
||||||
|
Context mockContext = ExtendedMockito.mock(Context.class);
|
||||||
|
ExtendedMockito.doReturn(mockResources)
|
||||||
|
.when(mockContext)
|
||||||
|
.getResources();
|
||||||
|
ExtendedMockito.doReturn(mMockBatteryManager)
|
||||||
|
.when(mockContext)
|
||||||
|
.getSystemService(BatteryManager.class);
|
||||||
|
ExtendedMockito.doReturn(mMockPowerManager)
|
||||||
|
.when(mockContext)
|
||||||
|
.getSystemService(PowerManager.class);
|
||||||
|
|
||||||
|
mDexManager = new DexManager(mockContext, mPM, /*PackageDexOptimizer*/ null,
|
||||||
mInstaller, mInstallLock);
|
mInstaller, mInstallLock);
|
||||||
|
|
||||||
// Foo and Bar are available to user0.
|
// Foo and Bar are available to user0.
|
||||||
@@ -128,6 +170,25 @@ public class DexManagerTests {
|
|||||||
mDexManager.load(existingPackages);
|
mDexManager.load(existingPackages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void teardown() throws Exception {
|
||||||
|
mMockitoSession.finishMocking();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDefaultMockValues() {
|
||||||
|
ExtendedMockito.doReturn(BatteryManager.BATTERY_STATUS_DISCHARGING)
|
||||||
|
.when(mMockBatteryManager)
|
||||||
|
.getIntProperty(BatteryManager.BATTERY_PROPERTY_STATUS);
|
||||||
|
|
||||||
|
ExtendedMockito.doReturn(TEST_BATTERY_LEVEL_DEFAULT)
|
||||||
|
.when(mMockBatteryManager)
|
||||||
|
.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||||
|
|
||||||
|
ExtendedMockito.doReturn(PowerManager.THERMAL_STATUS_NONE)
|
||||||
|
.when(mMockPowerManager)
|
||||||
|
.getCurrentThermalStatus();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotifyPrimaryUse() {
|
public void testNotifyPrimaryUse() {
|
||||||
// The main dex file and splits are re-loaded by the app.
|
// The main dex file and splits are re-loaded by the app.
|
||||||
@@ -633,6 +694,114 @@ public class DexManagerTests {
|
|||||||
assertNoDclInfo(mSystemServerJarInvalid);
|
assertNoDclInfo(mSystemServerJarInvalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallScenarioToReasonDefault() {
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_DEFAULT));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_FAST,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_FAST));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_BULK,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_BULK));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_BULK_SECONDARY,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_BULK_SECONDARY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallScenarioToReasonThermal() {
|
||||||
|
ExtendedMockito.doReturn(PowerManager.THERMAL_STATUS_SEVERE)
|
||||||
|
.when(mMockPowerManager)
|
||||||
|
.getCurrentThermalStatus();
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_DEFAULT));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_FAST,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_FAST));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_BULK_DOWNGRADED,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_BULK));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_BULK_SECONDARY_DOWNGRADED,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_BULK_SECONDARY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallScenarioToReasonBatteryDischarging() {
|
||||||
|
ExtendedMockito.doReturn(TEST_BATTERY_LEVEL_CRITICAL)
|
||||||
|
.when(mMockBatteryManager)
|
||||||
|
.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_DEFAULT));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_FAST,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_FAST));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_BULK_DOWNGRADED,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_BULK));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_BULK_SECONDARY_DOWNGRADED,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_BULK_SECONDARY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallScenarioToReasonBatteryCharging() {
|
||||||
|
ExtendedMockito.doReturn(TEST_BATTERY_LEVEL_CRITICAL)
|
||||||
|
.when(mMockBatteryManager)
|
||||||
|
.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||||
|
|
||||||
|
ExtendedMockito.doReturn(BatteryManager.BATTERY_STATUS_CHARGING)
|
||||||
|
.when(mMockBatteryManager)
|
||||||
|
.getIntProperty(BatteryManager.BATTERY_PROPERTY_STATUS);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_DEFAULT));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_FAST,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_FAST));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_BULK,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_BULK));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
PackageManagerService.REASON_INSTALL_BULK_SECONDARY,
|
||||||
|
mDexManager.getCompilationReasonForInstallScenario(
|
||||||
|
PackageManager.INSTALL_SCENARIO_BULK_SECONDARY));
|
||||||
|
}
|
||||||
|
|
||||||
private void assertSecondaryUse(TestData testData, PackageUseInfo pui,
|
private void assertSecondaryUse(TestData testData, PackageUseInfo pui,
|
||||||
List<String> secondaries, boolean isUsedByOtherApps, int ownerUserId,
|
List<String> secondaries, boolean isUsedByOtherApps, int ownerUserId,
|
||||||
String[] expectedContexts) {
|
String[] expectedContexts) {
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
calin@google.com
|
||||||
|
ngeoffray@google.com
|
||||||
Reference in New Issue
Block a user