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

Commit caecc3a3 authored by Alexandre Roux's avatar Alexandre Roux
Browse files

Merge branch '4881-r-confirmation-ota' into 'v1-r'

display alert dialog when switch ota server

See merge request !94
parents fa468c23 e1a64def
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -67,8 +67,10 @@
    <string name="security_settings_fingerprint_enroll_find_sensor_message_cm" product="default">Locate the fingerprint sensor on the <xliff:g id="sensor_location">%1$s</xliff:g> of your phone.</string>

    <!-- OTA server change -->
    <string name="title_ota_server">Use staging OTA server</string>
    <string name="use_ota_summary">Change to OTA/Production server</string>
    <string name="title_ota_server">Connect to /e/OS test channel</string>
    <string name="use_ota_summary">Access test releases of /e/OS</string>
    <string name="use_ota_staging_popup_title">You are about to connect to /e/OS test channel</string>
    <string name="use_ota_staging_popup_message">It will allow you to download and install test versions of /e/OS. Those builds may be unstable, and should be used only for test purposes. Please accept only if you know what you are doing.</string>

    <!-- Device Info screen. /e/ legal. -->
    <string name="elicense_title">/e/ legal</string>
+31 −8
Original line number Diff line number Diff line
@@ -16,22 +16,23 @@

package com.android.settings.development;

import android.app.AlertDialog;
import android.content.Context;
import android.provider.Settings;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.net.Uri;

import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.R;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;



public class ChangeSourcePreferenceController extends DeveloperOptionsPreferenceController implements
        Preference.OnPreferenceChangeListener, PreferenceControllerMixin {

@@ -53,10 +54,7 @@ public class ChangeSourcePreferenceController extends DeveloperOptionsPreference
        return CHANGE_URL_KEY;
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        final boolean isEnabled = (Boolean) newValue;
        ((SwitchPreference) mPreference).setChecked(isEnabled);
   public void updateOtaServer(){
        if (count(OTAProvider.CONTENT_URI)) {
            ContentValues values = new ContentValues();

@@ -72,8 +70,33 @@ public class ChangeSourcePreferenceController extends DeveloperOptionsPreference
            values.put(OTAProvider.Status,"true");
            mContext.getContentResolver().insert(OTAProvider.CONTENT_URI, values);
        }
   }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        final boolean isEnabled = (Boolean) newValue;
        ((SwitchPreference) mPreference).setChecked(isEnabled);
        if(retrieveStatus().equals("true")){
            updateOtaServer();
            return true;
        }
        new AlertDialog.Builder(mContext).
            setTitle(R.string.use_ota_staging_popup_title)
            .setMessage(mContext.getResources().getString(R.string.use_ota_staging_popup_message))
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int which) {
                    ((SwitchPreference) mPreference).setChecked(true);
                    updateOtaServer();
                }
            }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int which) {
                    ((SwitchPreference) mPreference).setChecked(false);
                }
            }).show();
        return false;
    }

    @Override
    public void updateState(Preference preference) {