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

Commit 3dd3b771 authored by Mohit Mali's avatar Mohit Mali Committed by Aayush Gupta
Browse files

Settings: Switch to select prod or staging OTA server

parent 0a30714f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3453,6 +3453,12 @@
            </intent-filter>
        </activity>

        <provider
            android:name="com.android.settings.development.OTAProvider"
            android:authorities="custom.setting.Provider.OTA_SERVER"
            android:exported="true"
            android:multiprocess="true" />

        <!-- This is the longest AndroidManifest.xml ever. -->
    </application>
</manifest>
+4 −0
Original line number Diff line number Diff line
@@ -64,6 +64,10 @@
    <string name="security_settings_fingerprint_enroll_find_sensor_message_cm" product="device">Locate the fingerprint sensor on the <xliff:g id="sensor_location">%1$s</xliff:g> of your device.</string>
    <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>

    <!-- Device Info screen. /e/ legal. -->
    <string name="elicense_title">/e/ legal</string>

+5 −0
Original line number Diff line number Diff line
@@ -645,6 +645,11 @@
        <Preference
            android:key="reset_shortcut_manager_throttling"
            android:title="@string/reset_shortcut_manager_throttling" />

        <SwitchPreference
            android:key="change_update_source"
            android:title="@string/title_ota_server"
            android:summary="@string/use_ota_summary" />
    </PreferenceCategory>

    <com.android.settings.development.autofill.AutofillPreferenceCategory
+123 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 ECORP SAS
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy
 * of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.android.settings.development;

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.database.Cursor;
import android.net.Uri;

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



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

    private static final String CHANGE_URL_KEY = "change_update_source";
    private String status;
    private final String UPDATE_URI ="content://custom.setting.Provider.OTA_SERVER/cte";

    @VisibleForTesting
    static final int SETTING_VALUE_ON = 1;
    @VisibleForTesting
    static final int SETTING_VALUE_OFF = 0;

    public ChangeSourcePreferenceController(Context context) {
        super(context);
    }

    @Override
    public String getPreferenceKey() {
        return CHANGE_URL_KEY;
    }

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

            if (retrieveStatus().equals("true")) {
                values.put(OTAProvider.Status, "false");
                mContext.getContentResolver().update(OTAProvider.CONTENT_URI, values, OTAProvider.id + "=?", new String[]{"1"});
            } else {
                values.put(OTAProvider.Status, "true");
                mContext.getContentResolver().update(OTAProvider.CONTENT_URI, values, OTAProvider.id + "=?", new String[]{"1"});
            }
        } else {
            ContentValues values = new ContentValues();
            values.put(OTAProvider.Status,"true");
            mContext.getContentResolver().insert(OTAProvider.CONTENT_URI, values);
        }
        return true;
    }

    @Override
    public void updateState(Preference preference) {
        if (retrieveStatus().equals("true")){
            ((SwitchPreference) mPreference).setChecked(true);
        } else {
            ((SwitchPreference) mPreference).setChecked(false);
        }
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        ((SwitchPreference) mPreference).setChecked(false);
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        super.onDeveloperOptionsSwitchEnabled();
        if (!count(OTAProvider.CONTENT_URI)){
            ContentValues values = new ContentValues();
            values.put(OTAProvider.Status,"false");
            mContext.getContentResolver().insert(OTAProvider.CONTENT_URI, values);
        }

    }

    public boolean count(Uri uri) {
        Cursor cursor = mContext.getContentResolver().query(uri, new String[]{"id"},
                null, null, null);
        if (cursor.getCount() > 0) {
            return true;
        } else {
            return false;
        }
    }

    private String retrieveStatus(){
        Cursor cursor = mContext.getContentResolver().query(Uri.parse(UPDATE_URI), null, OTAProvider.id+"=?", new String[]{"1"}, OTAProvider.Status);
        if (cursor.moveToFirst()) {
            do {
                status = cursor.getString(cursor.getColumnIndex(OTAProvider.Status));
            } while (cursor.moveToNext());
        }
        return status;
    }
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 * Copyright (C) 2021 ECORP SAS
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -518,6 +519,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new BluetoothA2dpHwOffloadPreferenceController(context, fragment));
        controllers.add(new BluetoothMaxConnectedAudioDevicesPreferenceController(context));
        controllers.add(new ShowTapsPreferenceController(context));
        controllers.add(new ChangeSourcePreferenceController(context));
        controllers.add(new PointerLocationPreferenceController(context));
        controllers.add(new ShowSurfaceUpdatesPreferenceController(context));
        controllers.add(new ShowLayoutBoundsPreferenceController(context));
Loading