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

Commit 9d62c301 authored by Mohit Mali's avatar Mohit Mali Committed by Romain Hunault
Browse files

Switch to select prod or staging OTA server

parent 32697672
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3323,6 +3323,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
@@ -57,6 +57,10 @@
    <string name="kill_app_longpress_back">Kill app back button</string>
    <string name="kill_app_longpress_back_summary">Kill the foreground app by long-pressing the back button</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>

+4 −0
Original line number Diff line number Diff line
@@ -614,6 +614,10 @@
            android:summary="@string/kill_app_longpress_back_summary"
            android:defaultValue="false" />

        <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.
@@ -483,6 +484,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
                bluetoothA2dpConfigStore));
        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