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

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

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

display alert dialog when switch ota server

See merge request !95
parents e2d2a223 2939211d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -312,6 +312,8 @@
    <!-- OTA server url text -->
    <string name="title_ota">Use staging OTA server</string>
    <string name="ota_summary">Change to OTA/Production server</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>

    <!-- Launch Dev Tools -->
    <string name="development_tools_title">Development tools</string>
+34 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.development;

import android.app.AlertDialog;
import android.content.Context;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
@@ -24,13 +25,19 @@ import android.support.v7.preference.Preference;
import android.preference.PreferenceManager;
import android.content.SharedPreferences;
import android.content.ContentValues;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;

import android.database.Cursor;
import android.net.Uri;
import android.content.Context;

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 +60,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 +76,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) {