Merge "Toggle switch back when user dismisses dialog by tapping screen" into udc-dev am: 174bd2ab74
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23220112 Change-Id: I211c5ae0aa764a885957573622af13be0e288206 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -28,11 +28,9 @@ import androidx.fragment.app.FragmentManager;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
|
|
||||||
/**
|
/** Dialog fragment for reboot confirmation when enabling certain features. */
|
||||||
* Dialog fragment for reboot confirmation when enabling certain features.
|
|
||||||
*/
|
|
||||||
public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
|
public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
|
||||||
implements DialogInterface.OnClickListener {
|
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
|
||||||
|
|
||||||
private static final String TAG = "FreeformPrefRebootDlg";
|
private static final String TAG = "FreeformPrefRebootDlg";
|
||||||
|
|
||||||
@@ -40,18 +38,17 @@ public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
|
|||||||
private final int mCancelButtonId;
|
private final int mCancelButtonId;
|
||||||
private final RebootConfirmationDialogHost mHost;
|
private final RebootConfirmationDialogHost mHost;
|
||||||
|
|
||||||
/**
|
/** Show an instance of this dialog. */
|
||||||
* Show an instance of this dialog.
|
|
||||||
*/
|
|
||||||
public static void show(Fragment fragment, int messageId, RebootConfirmationDialogHost host) {
|
public static void show(Fragment fragment, int messageId, RebootConfirmationDialogHost host) {
|
||||||
show(fragment, messageId, R.string.reboot_dialog_reboot_later, host);
|
show(fragment, messageId, R.string.reboot_dialog_reboot_later, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Show an instance of this dialog with cancel button string set as cancelButtonId */
|
||||||
* Show an instance of this dialog with cancel button string set as cancelButtonId
|
public static void show(
|
||||||
*/
|
Fragment fragment,
|
||||||
public static void show(Fragment fragment, int messageId,
|
int messageId,
|
||||||
int cancelButtonId, RebootConfirmationDialogHost host) {
|
int cancelButtonId,
|
||||||
|
RebootConfirmationDialogHost host) {
|
||||||
final FragmentManager manager = fragment.getActivity().getSupportFragmentManager();
|
final FragmentManager manager = fragment.getActivity().getSupportFragmentManager();
|
||||||
if (manager.findFragmentByTag(TAG) == null) {
|
if (manager.findFragmentByTag(TAG) == null) {
|
||||||
final RebootConfirmationDialogFragment dialog =
|
final RebootConfirmationDialogFragment dialog =
|
||||||
@@ -60,8 +57,8 @@ public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RebootConfirmationDialogFragment(int messageId,
|
private RebootConfirmationDialogFragment(
|
||||||
int cancelButtonId, RebootConfirmationDialogHost host) {
|
int messageId, int cancelButtonId, RebootConfirmationDialogHost host) {
|
||||||
mMessageId = messageId;
|
mMessageId = messageId;
|
||||||
mCancelButtonId = cancelButtonId;
|
mCancelButtonId = cancelButtonId;
|
||||||
mHost = host;
|
mHost = host;
|
||||||
@@ -89,4 +86,10 @@ public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
|
|||||||
mHost.onRebootCancelled();
|
mHost.onRebootCancelled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
super.onDismiss(dialog);
|
||||||
|
mHost.onRebootDialogDismissed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,22 +20,20 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Host of {@link RebootConfirmationDialogFragment} that provides callback when user
|
* Host of {@link RebootConfirmationDialogFragment} that provides callback when user interacts with
|
||||||
* interacts with the UI.
|
* the UI.
|
||||||
*/
|
*/
|
||||||
public interface RebootConfirmationDialogHost {
|
public interface RebootConfirmationDialogHost {
|
||||||
/**
|
/** Called when user made a decision to reboot the device. */
|
||||||
* Called when user made a decision to reboot the device.
|
|
||||||
*/
|
|
||||||
default void onRebootConfirmed(Context context) {
|
default void onRebootConfirmed(Context context) {
|
||||||
// user presses button "Reboot now", reboot the device
|
// user presses button "Reboot now", reboot the device
|
||||||
final Intent intent = new Intent(Intent.ACTION_REBOOT);
|
final Intent intent = new Intent(Intent.ACTION_REBOOT);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Called when user made a decision to cancel the reboot Default to do nothing */
|
||||||
* Called when user made a decision to cancel the reboot
|
|
||||||
* Default to do nothing
|
|
||||||
*/
|
|
||||||
default void onRebootCancelled() {}
|
default void onRebootCancelled() {}
|
||||||
|
|
||||||
|
/** Called when reboot dialog is dismissed Default to do nothing */
|
||||||
|
default void onRebootDialogDismissed() {}
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.development.graphicsdriver;
|
package com.android.settings.development.graphicsdriver;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.GraphicsEnvironment;
|
import android.os.GraphicsEnvironment;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -33,9 +34,7 @@ import com.android.settings.development.RebootConfirmationDialogFragment;
|
|||||||
import com.android.settings.development.RebootConfirmationDialogHost;
|
import com.android.settings.development.RebootConfirmationDialogHost;
|
||||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||||
|
|
||||||
/**
|
/** Controller to handle the events when user toggles this developer option switch: Enable ANGLE */
|
||||||
* Controller to handle the events when user toggles this developer option switch: Enable ANGLE
|
|
||||||
*/
|
|
||||||
public class GraphicsDriverEnableAngleAsSystemDriverController
|
public class GraphicsDriverEnableAngleAsSystemDriverController
|
||||||
extends DeveloperOptionsPreferenceController
|
extends DeveloperOptionsPreferenceController
|
||||||
implements Preference.OnPreferenceChangeListener,
|
implements Preference.OnPreferenceChangeListener,
|
||||||
@@ -50,14 +49,15 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
|
|||||||
|
|
||||||
private final GraphicsDriverSystemPropertiesWrapper mSystemProperties;
|
private final GraphicsDriverSystemPropertiesWrapper mSystemProperties;
|
||||||
|
|
||||||
|
private boolean mShouldToggleSwitchBackOnRebootDialogDismiss;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String PROPERTY_RO_GFX_ANGLE_SUPPORTED = "ro.gfx.angle.supported";
|
static final String PROPERTY_RO_GFX_ANGLE_SUPPORTED = "ro.gfx.angle.supported";
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String PROPERTY_PERSISTENT_GRAPHICS_EGL = "persist.graphics.egl";
|
static final String PROPERTY_PERSISTENT_GRAPHICS_EGL = "persist.graphics.egl";
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting static final String ANGLE_DRIVER_SUFFIX = "angle";
|
||||||
static final String ANGLE_DRIVER_SUFFIX = "angle";
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static class Injector {
|
static class Injector {
|
||||||
@@ -87,6 +87,10 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
|
|||||||
super(context);
|
super(context);
|
||||||
mFragment = fragment;
|
mFragment = fragment;
|
||||||
mSystemProperties = injector.createSystemPropertiesWrapper();
|
mSystemProperties = injector.createSystemPropertiesWrapper();
|
||||||
|
// By default, when the reboot dialog is dismissed we want to toggle the switch back.
|
||||||
|
// Exception is when user chooses to reboot now, the switch should keep its current value
|
||||||
|
// and persist its' state over reboot.
|
||||||
|
mShouldToggleSwitchBackOnRebootDialogDismiss = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -108,11 +112,12 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void showRebootDialog() {
|
void showRebootDialog() {
|
||||||
RebootConfirmationDialogFragment.show(
|
RebootConfirmationDialogFragment.show(
|
||||||
mFragment, R.string.reboot_dialog_enable_angle_as_system_driver,
|
mFragment,
|
||||||
R.string.cancel, this);
|
R.string.reboot_dialog_enable_angle_as_system_driver,
|
||||||
|
R.string.cancel,
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
// set switch on if "persist.graphics.egl" is "angle" and angle is built in /vendor
|
// set switch on if "persist.graphics.egl" is "angle" and angle is built in /vendor
|
||||||
@@ -120,8 +125,9 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
|
|||||||
final String currentGlesDriver =
|
final String currentGlesDriver =
|
||||||
mSystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL, "");
|
mSystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL, "");
|
||||||
final boolean isAngle = TextUtils.equals(ANGLE_DRIVER_SUFFIX, currentGlesDriver);
|
final boolean isAngle = TextUtils.equals(ANGLE_DRIVER_SUFFIX, currentGlesDriver);
|
||||||
final boolean isAngleSupported = TextUtils
|
final boolean isAngleSupported =
|
||||||
.equals(mSystemProperties.get(PROPERTY_RO_GFX_ANGLE_SUPPORTED, ""), "true");
|
TextUtils.equals(
|
||||||
|
mSystemProperties.get(PROPERTY_RO_GFX_ANGLE_SUPPORTED, ""), "true");
|
||||||
((SwitchPreference) mPreference).setChecked(isAngle && isAngleSupported);
|
((SwitchPreference) mPreference).setChecked(isAngle && isAngleSupported);
|
||||||
((SwitchPreference) mPreference).setEnabled(isAngleSupported);
|
((SwitchPreference) mPreference).setEnabled(isAngleSupported);
|
||||||
}
|
}
|
||||||
@@ -130,8 +136,9 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
|
|||||||
protected void onDeveloperOptionsSwitchEnabled() {
|
protected void onDeveloperOptionsSwitchEnabled() {
|
||||||
// only enable the switch if ro.gfx.angle.supported is true
|
// only enable the switch if ro.gfx.angle.supported is true
|
||||||
// we use ro.gfx.angle.supported to indicate if ANGLE libs are installed under /vendor
|
// we use ro.gfx.angle.supported to indicate if ANGLE libs are installed under /vendor
|
||||||
final boolean isAngleSupported = TextUtils
|
final boolean isAngleSupported =
|
||||||
.equals(mSystemProperties.get(PROPERTY_RO_GFX_ANGLE_SUPPORTED, ""), "true");
|
TextUtils.equals(
|
||||||
|
mSystemProperties.get(PROPERTY_RO_GFX_ANGLE_SUPPORTED, ""), "true");
|
||||||
((SwitchPreference) mPreference).setEnabled(isAngleSupported);
|
((SwitchPreference) mPreference).setEnabled(isAngleSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,9 +152,7 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
|
|||||||
((SwitchPreference) mPreference).setEnabled(false);
|
((SwitchPreference) mPreference).setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void toggleSwitchBack() {
|
||||||
public void onRebootCancelled() {
|
|
||||||
// if user presses button "Cancel", do not reboot the device, and toggles switch back
|
|
||||||
final String currentGlesDriver =
|
final String currentGlesDriver =
|
||||||
mSystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL, "");
|
mSystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL, "");
|
||||||
if (TextUtils.equals(ANGLE_DRIVER_SUFFIX, currentGlesDriver)) {
|
if (TextUtils.equals(ANGLE_DRIVER_SUFFIX, currentGlesDriver)) {
|
||||||
@@ -169,4 +174,40 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
|
|||||||
// if persist.graphics.egl holds values other than the above two, log error message
|
// if persist.graphics.egl holds values other than the above two, log error message
|
||||||
Log.e(TAG, "Invalid persist.graphics.egl property value");
|
Log.e(TAG, "Invalid persist.graphics.egl property value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void rebootDevice(Context context) {
|
||||||
|
final Intent intent = new Intent(Intent.ACTION_REBOOT);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRebootConfirmed(Context context) {
|
||||||
|
// User chooses to reboot now, do not toggle switch back
|
||||||
|
mShouldToggleSwitchBackOnRebootDialogDismiss = false;
|
||||||
|
|
||||||
|
// Reboot the device
|
||||||
|
rebootDevice(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRebootCancelled() {
|
||||||
|
// User chooses to cancel reboot, toggle switch back
|
||||||
|
mShouldToggleSwitchBackOnRebootDialogDismiss = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRebootDialogDismissed() {
|
||||||
|
// If reboot dialog is dismissed either from
|
||||||
|
// 1) User clicks cancel
|
||||||
|
// 2) User taps phone screen area outside of reboot dialog
|
||||||
|
// do not reboot the device, and toggles switch back.
|
||||||
|
if (mShouldToggleSwitchBackOnRebootDialogDismiss) {
|
||||||
|
toggleSwitchBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset the flag so that the default option is to toggle switch back
|
||||||
|
// on reboot dialog dismissed.
|
||||||
|
mShouldToggleSwitchBackOnRebootDialogDismiss = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,11 +56,39 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
|
|||||||
|
|
||||||
private GraphicsDriverEnableAngleAsSystemDriverController mController;
|
private GraphicsDriverEnableAngleAsSystemDriverController mController;
|
||||||
|
|
||||||
@Mock
|
// Signal to wait for SystemProperty values changed
|
||||||
private DevelopmentSettingsDashboardFragment mFragment;
|
private class PropertyChangeSignal {
|
||||||
|
private CountDownLatch mCountDownLatch;
|
||||||
|
|
||||||
@Mock
|
private Runnable mCountDownJob;
|
||||||
private GraphicsDriverSystemPropertiesWrapper mSystemPropertiesMock;
|
|
||||||
|
PropertyChangeSignal() {
|
||||||
|
mCountDownLatch = new CountDownLatch(1);
|
||||||
|
mCountDownJob =
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mCountDownLatch.countDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Runnable getCountDownJob() {
|
||||||
|
return mCountDownJob;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void wait(int timeoutInMilliSeconds) {
|
||||||
|
try {
|
||||||
|
mCountDownLatch.await(timeoutInMilliSeconds, TimeUnit.MILLISECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Assert.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mock private DevelopmentSettingsDashboardFragment mFragment;
|
||||||
|
|
||||||
|
@Mock private GraphicsDriverSystemPropertiesWrapper mSystemPropertiesMock;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -76,10 +104,14 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
|
|||||||
// so we can force the SystemProperties with values we need to run tests.
|
// so we can force the SystemProperties with values we need to run tests.
|
||||||
// 2) Override the showRebootDialog() to do nothing.
|
// 2) Override the showRebootDialog() to do nothing.
|
||||||
// We do not need to pop up the reboot dialog in the test.
|
// We do not need to pop up the reboot dialog in the test.
|
||||||
|
// 3) Override the rebootDevice() to do nothing.
|
||||||
mController = new GraphicsDriverEnableAngleAsSystemDriverController(
|
mController = new GraphicsDriverEnableAngleAsSystemDriverController(
|
||||||
mContext, mFragment, new Injector(){
|
mContext,
|
||||||
|
mFragment,
|
||||||
|
new Injector() {
|
||||||
@Override
|
@Override
|
||||||
public GraphicsDriverSystemPropertiesWrapper createSystemPropertiesWrapper() {
|
public GraphicsDriverSystemPropertiesWrapper
|
||||||
|
createSystemPropertiesWrapper() {
|
||||||
return mSystemPropertiesMock;
|
return mSystemPropertiesMock;
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
@@ -87,6 +119,11 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
|
|||||||
void showRebootDialog() {
|
void showRebootDialog() {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void rebootDevice(Context context) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
@@ -99,58 +136,42 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onPreferenceChange_switchOn_shouldEnableAngleAsSystemDriver() {
|
public void onPreferenceChange_switchOn_shouldEnableAngleAsSystemDriver() {
|
||||||
|
// Step 1: toggle the switch "Enable ANGLE" on
|
||||||
// Add a callback when SystemProperty changes.
|
// Add a callback when SystemProperty changes.
|
||||||
// This allows the thread to wait until
|
// This allows the thread to wait until
|
||||||
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
PropertyChangeSignal propertyChangeSignal = new PropertyChangeSignal();
|
||||||
Runnable countDown = new Runnable() {
|
SystemProperties.addChangeCallback(propertyChangeSignal.getCountDownJob());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
countDownLatch.countDown();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
SystemProperties.addChangeCallback(countDown);
|
|
||||||
|
|
||||||
// Test onPreferenceChange(true) updates the persist.graphics.egl to "angle"
|
|
||||||
mController.onPreferenceChange(mPreference, true);
|
mController.onPreferenceChange(mPreference, true);
|
||||||
try {
|
propertyChangeSignal.wait(100);
|
||||||
countDownLatch.await(100, TimeUnit.MILLISECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
// Step 2: verify results
|
||||||
Assert.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
assertThat(systemEGLDriver).isEqualTo(ANGLE_DRIVER_SUFFIX);
|
assertThat(systemEGLDriver).isEqualTo(ANGLE_DRIVER_SUFFIX);
|
||||||
|
|
||||||
|
// Step 3: clean up
|
||||||
// Done with the test, remove the callback
|
// Done with the test, remove the callback
|
||||||
SystemProperties.removeChangeCallback(countDown);
|
SystemProperties.removeChangeCallback(propertyChangeSignal.getCountDownJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onPreferenceChange_switchOff_shouldDisableAngleAsSystemDriver() {
|
public void onPreferenceChange_switchOff_shouldDisableAngleAsSystemDriver() {
|
||||||
|
// Step 1: toggle the switch "Enable ANGLE" off
|
||||||
// Add a callback when SystemProperty changes.
|
// Add a callback when SystemProperty changes.
|
||||||
// This allows the thread to wait until
|
// This allows the thread to wait until
|
||||||
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
PropertyChangeSignal propertyChangeSignal = new PropertyChangeSignal();
|
||||||
Runnable countDown = new Runnable() {
|
SystemProperties.addChangeCallback(propertyChangeSignal.getCountDownJob());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
countDownLatch.countDown();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
SystemProperties.addChangeCallback(countDown);
|
|
||||||
|
|
||||||
// Test onPreferenceChange(false) updates the persist.graphics.egl to ""
|
|
||||||
mController.onPreferenceChange(mPreference, false);
|
mController.onPreferenceChange(mPreference, false);
|
||||||
try {
|
propertyChangeSignal.wait(100);
|
||||||
countDownLatch.await(100, TimeUnit.MILLISECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
// Step 2: verify results
|
||||||
Assert.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
assertThat(systemEGLDriver).isEqualTo("");
|
assertThat(systemEGLDriver).isEqualTo("");
|
||||||
|
|
||||||
|
// Step 3: clean up
|
||||||
// Done with the test, remove the callback
|
// Done with the test, remove the callback
|
||||||
SystemProperties.removeChangeCallback(countDown);
|
SystemProperties.removeChangeCallback(propertyChangeSignal.getCountDownJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -162,8 +183,7 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_angleNotSupported_PreferenceShouldNotBeChecked() {
|
public void updateState_angleNotSupported_PreferenceShouldNotBeChecked() {
|
||||||
when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
|
when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any())).thenReturn("");
|
||||||
.thenReturn("");
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
assertThat(mPreference.isChecked()).isFalse();
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -191,8 +211,7 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
|
|||||||
updateState_angleSupported_angleIsNotSystemGLESDriver_PreferenceShouldNotBeChecked() {
|
updateState_angleSupported_angleIsNotSystemGLESDriver_PreferenceShouldNotBeChecked() {
|
||||||
when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
|
when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
|
||||||
.thenReturn("true");
|
.thenReturn("true");
|
||||||
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any())).thenReturn("");
|
||||||
.thenReturn("");
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
assertThat(mPreference.isChecked()).isFalse();
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -218,28 +237,18 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
|
|||||||
// Add a callback when SystemProperty changes.
|
// Add a callback when SystemProperty changes.
|
||||||
// This allows the thread to wait until
|
// This allows the thread to wait until
|
||||||
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
PropertyChangeSignal propertyChangeSignal1 = new PropertyChangeSignal();
|
||||||
Runnable countDown = new Runnable() {
|
SystemProperties.addChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
countDownLatch.countDown();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
SystemProperties.addChangeCallback(countDown);
|
|
||||||
|
|
||||||
// Test that onDeveloperOptionSwitchDisabled,
|
// Test that onDeveloperOptionSwitchDisabled,
|
||||||
// persist.graphics.egl updates to ""
|
// persist.graphics.egl updates to ""
|
||||||
mController.onDeveloperOptionsSwitchDisabled();
|
mController.onDeveloperOptionsSwitchDisabled();
|
||||||
try {
|
propertyChangeSignal1.wait(100);
|
||||||
countDownLatch.await(100, TimeUnit.MILLISECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Assert.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
assertThat(systemEGLDriver).isEqualTo("");
|
assertThat(systemEGLDriver).isEqualTo("");
|
||||||
|
|
||||||
// Done with the test, remove the callback
|
// Done with the test, remove the callback
|
||||||
SystemProperties.removeChangeCallback(countDown);
|
SystemProperties.removeChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -256,70 +265,217 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onRebootCancelled_ToggleSwitchFromOnToOff() {
|
public void onRebootCancelled_ToggleSwitchFromOnToOff() {
|
||||||
|
// Step 1: Toggle the "Enable ANGLE" switch on
|
||||||
// Add a callback when SystemProperty changes.
|
// Add a callback when SystemProperty changes.
|
||||||
// This allows the thread to wait until
|
// This allows the thread to wait until
|
||||||
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
PropertyChangeSignal propertyChangeSignal1 = new PropertyChangeSignal();
|
||||||
Runnable countDown = new Runnable() {
|
SystemProperties.addChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
@Override
|
mController.onPreferenceChange(mPreference, true);
|
||||||
public void run() {
|
// Block the following code execution until the "persist.graphics.egl" property value is
|
||||||
countDownLatch.countDown();
|
// changed.
|
||||||
}
|
propertyChangeSignal1.wait(100);
|
||||||
};
|
|
||||||
SystemProperties.addChangeCallback(countDown);
|
|
||||||
|
|
||||||
// Test that if the current persist.graphics.egl is "angle",
|
// Step 2: Cancel reboot
|
||||||
// when reboot is cancelled, persist.graphics.egl is changed back to "",
|
PropertyChangeSignal propertyChangeSignal2 = new PropertyChangeSignal();
|
||||||
// and switch is set to unchecked.
|
SystemProperties.addChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
||||||
.thenReturn(ANGLE_DRIVER_SUFFIX);
|
.thenReturn(SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL));
|
||||||
mController.onRebootCancelled();
|
mController.onRebootCancelled();
|
||||||
try {
|
mController.onRebootDialogDismissed();
|
||||||
countDownLatch.await(100, TimeUnit.MILLISECONDS);
|
// Block the following code execution until the "persist.graphics.egl" property valye is
|
||||||
} catch (InterruptedException e) {
|
// changed.
|
||||||
Assert.fail(e.getMessage());
|
propertyChangeSignal2.wait(100);
|
||||||
}
|
|
||||||
|
|
||||||
|
// Step 3: Verify results
|
||||||
|
// 1) Test that persist.graphics.egl is changed back to "".
|
||||||
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
assertThat(systemEGLDriver).isEqualTo("");
|
assertThat(systemEGLDriver).isEqualTo("");
|
||||||
|
// 2) Test that the switch is set to unchecked.
|
||||||
assertThat(mPreference.isChecked()).isFalse();
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
|
|
||||||
// Done with the test, remove the callback.
|
// Step 4: Clean up
|
||||||
SystemProperties.removeChangeCallback(countDown);
|
// Done with the test, remove the callback
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onRebootCancelled_ToggleSwitchFromOffToOn() {
|
public void onRebootCancelled_ToggleSwitchFromOffToOn() {
|
||||||
|
// Step 1: Toggle off the switch "Enable ANGLE"
|
||||||
// Add a callback when SystemProperty changes.
|
// Add a callback when SystemProperty changes.
|
||||||
// This allows the thread to wait until
|
// This allows the thread to wait until
|
||||||
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
PropertyChangeSignal propertyChangeSignal1 = new PropertyChangeSignal();
|
||||||
Runnable countDown = new Runnable() {
|
SystemProperties.addChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
@Override
|
mController.onPreferenceChange(mPreference, false);
|
||||||
public void run() {
|
// Block the following code execution until the "persist.graphics.egl" property value is
|
||||||
countDownLatch.countDown();
|
// changed.
|
||||||
}
|
propertyChangeSignal1.wait(100);
|
||||||
};
|
|
||||||
SystemProperties.addChangeCallback(countDown);
|
|
||||||
|
|
||||||
// Test that if the current persist.graphics.egl is "",
|
// Step 2: Cancel reboot
|
||||||
// when reboot is cancelled, persist.graphics.egl is changed back to "angle",
|
PropertyChangeSignal propertyChangeSignal2 = new PropertyChangeSignal();
|
||||||
// and switch is set to checked.
|
SystemProperties.addChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
||||||
.thenReturn("");
|
.thenReturn(SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL));
|
||||||
mController.onRebootCancelled();
|
mController.onRebootCancelled();
|
||||||
try {
|
mController.onRebootDialogDismissed();
|
||||||
countDownLatch.await(100, TimeUnit.MILLISECONDS);
|
// Block the following code execution until the "persist.graphics.egl" property valye is
|
||||||
} catch (InterruptedException e) {
|
// changed.
|
||||||
Assert.fail(e.getMessage());
|
propertyChangeSignal2.wait(100);
|
||||||
}
|
|
||||||
|
|
||||||
|
// Step 3: Verify results
|
||||||
|
// 1) Test that persist.graphics.egl is changed back to "ANGLE"
|
||||||
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
assertThat(systemEGLDriver).isEqualTo(ANGLE_DRIVER_SUFFIX);
|
assertThat(systemEGLDriver).isEqualTo(ANGLE_DRIVER_SUFFIX);
|
||||||
|
// 2) Test that the switch is set to checked
|
||||||
assertThat(mPreference.isChecked()).isTrue();
|
assertThat(mPreference.isChecked()).isTrue();
|
||||||
|
|
||||||
|
// Step 4: Clean up
|
||||||
// Done with the test, remove the callback.
|
// Done with the test, remove the callback.
|
||||||
SystemProperties.removeChangeCallback(countDown);
|
SystemProperties.removeChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onRebootDialogDismissed_ToggleSwitchFromOnToOff() {
|
||||||
|
// Step 1: Toggle on the switch "Enable ANGLE"
|
||||||
|
// Add a callback when SystemProperty changes.
|
||||||
|
// This allows the thread to wait until
|
||||||
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
|
PropertyChangeSignal propertyChangeSignal1 = new PropertyChangeSignal();
|
||||||
|
SystemProperties.addChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
mController.onPreferenceChange(mPreference, true);
|
||||||
|
// Block the following code execution until the "persist.graphics.egl" property value is
|
||||||
|
// changed.
|
||||||
|
propertyChangeSignal1.wait(100);
|
||||||
|
|
||||||
|
// Step 2: Dismiss the reboot dialog
|
||||||
|
PropertyChangeSignal propertyChangeSignal2 = new PropertyChangeSignal();
|
||||||
|
SystemProperties.addChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
|
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
||||||
|
.thenReturn(SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL));
|
||||||
|
mController.onRebootDialogDismissed();
|
||||||
|
// Block the following code execution until the "persist.graphics.egl" property valye is
|
||||||
|
// changed.
|
||||||
|
propertyChangeSignal2.wait(100);
|
||||||
|
|
||||||
|
// Step 3: Verify results
|
||||||
|
// 1) Test that persist.graphics.egl is changed back to "".
|
||||||
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
|
assertThat(systemEGLDriver).isEqualTo("");
|
||||||
|
// 2) Test that the switch is set to unchecked.
|
||||||
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
|
|
||||||
|
// Step 4: Clean up
|
||||||
|
// Done with the test, remove the callback
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onRebootDialogDismissed_ToggleSwitchFromOffToOn() {
|
||||||
|
// Step 1: Toggle on the switch "Enable ANGLE"
|
||||||
|
// Add a callback when SystemProperty changes.
|
||||||
|
// This allows the thread to wait until
|
||||||
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
|
PropertyChangeSignal propertyChangeSignal1 = new PropertyChangeSignal();
|
||||||
|
SystemProperties.addChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
mController.onPreferenceChange(mPreference, false);
|
||||||
|
// Block the following code execution until the "persist.graphics.egl" property value is
|
||||||
|
// changed.
|
||||||
|
propertyChangeSignal1.wait(100);
|
||||||
|
|
||||||
|
// Step 2: Dismiss the reboot dialog
|
||||||
|
PropertyChangeSignal propertyChangeSignal2 = new PropertyChangeSignal();
|
||||||
|
SystemProperties.addChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
|
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
||||||
|
.thenReturn(SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL));
|
||||||
|
mController.onRebootDialogDismissed();
|
||||||
|
// Block the following code execution until the "persist.graphics.egl" property valye is
|
||||||
|
// changed.
|
||||||
|
propertyChangeSignal2.wait(100);
|
||||||
|
|
||||||
|
// Step 3: Verify results
|
||||||
|
// 1) Test that persist.graphics.egl is changed back to "ANGLE"
|
||||||
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
|
assertThat(systemEGLDriver).isEqualTo(ANGLE_DRIVER_SUFFIX);
|
||||||
|
// 2) Test that the switch is set to checked
|
||||||
|
assertThat(mPreference.isChecked()).isTrue();
|
||||||
|
|
||||||
|
// Step 4: Clean up
|
||||||
|
// Done with the test, remove the callback
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onRebootDialogConfirmed_ToggleSwitchOnRemainsOn() {
|
||||||
|
// Step 1: Toggle on the switch "Enable ANGLE"
|
||||||
|
// Add a callback when SystemProperty changes.
|
||||||
|
// This allows the thread to wait until
|
||||||
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
|
PropertyChangeSignal propertyChangeSignal1 = new PropertyChangeSignal();
|
||||||
|
SystemProperties.addChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
mController.onPreferenceChange(mPreference, true);
|
||||||
|
// Block the following code execution until the "persist.graphics.egl" property value is
|
||||||
|
// changed.
|
||||||
|
propertyChangeSignal1.wait(100);
|
||||||
|
|
||||||
|
// Step 2: Confirm reboot
|
||||||
|
PropertyChangeSignal propertyChangeSignal2 = new PropertyChangeSignal();
|
||||||
|
SystemProperties.addChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
|
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
||||||
|
.thenReturn(SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL));
|
||||||
|
mController.onRebootConfirmed(mContext);
|
||||||
|
mController.onRebootDialogDismissed();
|
||||||
|
// Block the following code execution until the "persist.graphics.egl" property valye is
|
||||||
|
// changed.
|
||||||
|
propertyChangeSignal2.wait(100);
|
||||||
|
|
||||||
|
// Step 3: Verify Results
|
||||||
|
// Test that persist.graphics.egl remains to be "ANGLE"
|
||||||
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
|
assertThat(systemEGLDriver).isEqualTo(ANGLE_DRIVER_SUFFIX);
|
||||||
|
|
||||||
|
// Step 4: Clean up
|
||||||
|
// Done with the test, remove the callback
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onRebootDialogConfirmed_ToggleSwitchOffRemainsOff() {
|
||||||
|
// Step 1: Toggle off the switch "Enable ANGLE"
|
||||||
|
// Add a callback when SystemProperty changes.
|
||||||
|
// This allows the thread to wait until
|
||||||
|
// GpuService::toggleAngleAsSystemDriver() updates the persist.graphics.egl.
|
||||||
|
PropertyChangeSignal propertyChangeSignal1 = new PropertyChangeSignal();
|
||||||
|
SystemProperties.addChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
mController.onPreferenceChange(mPreference, false);
|
||||||
|
// Block the following code execution until the "persist.graphics.egl" property value is
|
||||||
|
// changed.
|
||||||
|
propertyChangeSignal1.wait(100);
|
||||||
|
|
||||||
|
// Step 2: Confirm reboot
|
||||||
|
PropertyChangeSignal propertyChangeSignal2 = new PropertyChangeSignal();
|
||||||
|
SystemProperties.addChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
|
when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
|
||||||
|
.thenReturn(SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL));
|
||||||
|
mController.onRebootConfirmed(mContext);
|
||||||
|
mController.onRebootDialogDismissed();
|
||||||
|
// Block the following code execution until the "persist.graphics.egl" property valye is
|
||||||
|
// changed.
|
||||||
|
propertyChangeSignal2.wait(100);
|
||||||
|
|
||||||
|
// Step 3: Verify Results
|
||||||
|
// Test that persist.graphics.egl remains to be ""
|
||||||
|
final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
|
||||||
|
assertThat(systemEGLDriver).isEqualTo("");
|
||||||
|
|
||||||
|
// Step 4: Clean up
|
||||||
|
// Done with the test, remove the callback
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal1.getCountDownJob());
|
||||||
|
SystemProperties.removeChangeCallback(propertyChangeSignal2.getCountDownJob());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user