Bug 1168175 - Follow-up: Guard against null contexts. r=bustage

On a CLOSED TREE.

So, apparently we race to have a non-null application context from the
target context.  No matter, we can use the target context directly.
This commit is contained in:
Nick Alexander 2016-02-04 17:17:07 -08:00
parent 685025dfb0
commit 2f4cc4cba4

View File

@ -40,19 +40,22 @@ public class FennecInstrumentationTestRunner extends InstrumentationTestRunner {
@Override
public void onStart() {
final Context app = getTargetContext().getApplicationContext();
final Context app = getTargetContext();
if (app != null) {
final String name = FennecInstrumentationTestRunner.class.getSimpleName();
// Unlock the device so that the tests can input keystrokes.
final KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
// Deprecated in favour of window flags, which aren't appropriate here.
keyguardLock = keyguard.newKeyguardLock(name);
keyguardLock.disableKeyguard();
final String name = FennecInstrumentationTestRunner.class.getSimpleName();
// Unlock the device so that the tests can input keystrokes.
final KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
// Deprecated in favour of window flags, which aren't appropriate here.
keyguardLock = keyguard.newKeyguardLock(name);
keyguardLock.disableKeyguard();
// Wake up the screen.
final PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name);
wakeLock.acquire();
// Wake up the screen.
final PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name);
wakeLock.acquire();
} else {
Log.e("GeckoInstTestRunner", "Application target context is null: not disabling keyguard and not taking wakelock.");
}
super.onStart();
}
@ -61,8 +64,12 @@ public class FennecInstrumentationTestRunner extends InstrumentationTestRunner {
public void onDestroy() {
super.onDestroy();
wakeLock.release();
// Deprecated in favour of window flags, which aren't appropriate here.
keyguardLock.reenableKeyguard();
if (wakeLock != null) {
wakeLock.release();
}
if (keyguardLock != null) {
// Deprecated in favour of window flags, which aren't appropriate here.
keyguardLock.reenableKeyguard();
}
}
}