Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 174bd2ab authored by Yuxin Hu's avatar Yuxin Hu Committed by Android (Google) Code Review
Browse files

Merge "Toggle switch back when user dismisses dialog by tapping screen" into udc-dev

parents b272dbc6 2cbb587f
Loading
Loading
Loading
Loading
+17 −14
Original line number Original line Diff line number Diff line
@@ -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();
    }
}
}
+7 −9
Original line number Original line Diff line number Diff line
@@ -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() {}
}
}
+56 −15
Original line number Original line Diff line number Diff line
@@ -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;
    }
}
}
+258 −102

File changed.

Preview size limit exceeded, changes collapsed.