From 2939211d154427e74aae467f99826f14006ea36c Mon Sep 17 00:00:00 2001 From: Alexandre Roux D'Anzi Date: Fri, 4 Mar 2022 13:46:51 +0100 Subject: [PATCH] display alert dialog when switch ota server --- res/values/cm_strings.xml | 2 + .../ChangeSourcePreferenceController.java | 39 ++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index f26e8f51446..5ab7febda7d 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -312,6 +312,8 @@ Use staging OTA server Change to OTA/Production server + You are about to connect to /e/OS test channel + 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. Development tools diff --git a/src/com/android/settings/development/ChangeSourcePreferenceController.java b/src/com/android/settings/development/ChangeSourcePreferenceController.java index 7aa070378b7..7c4ae9170c5 100644 --- a/src/com/android/settings/development/ChangeSourcePreferenceController.java +++ b/src/com/android/settings/development/ChangeSourcePreferenceController.java @@ -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,7 +76,32 @@ public class ChangeSourcePreferenceController extends DeveloperOptionsPreference values.put(OTAProvider.Status,"true"); mContext.getContentResolver().insert(OTAProvider.CONTENT_URI, values); } - return true; + } + + @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 -- GitLab