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

Commit 581758b8 authored by Mohit Mali's avatar Mohit Mali Committed by Romain Hunault
Browse files

Switch to select prod or staging OTA server

parent 160eb497
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3410,6 +3410,12 @@
        <service android:name=".fuelgauge.batterytip.AnomalyDetectionJobService"
                 android:permission="android.permission.BIND_JOB_SERVICE" />

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

	<!-- /e/ specific changes -->
      <!--  <activity android:name="Settings$OpenKeychainActivity"
            android:label="@string/open_keychain"
+4 −0
Original line number Diff line number Diff line
@@ -309,6 +309,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 url text -->
    <string name="title_ota">Use staging OTA server</string>
    <string name="ota_summary">Change to OTA/Production server</string>

    <!-- Launch Dev Tools -->
    <string name="development_tools_title">Development tools</string>

+5 −0
Original line number Diff line number Diff line
@@ -574,6 +574,11 @@
            android:title="@string/kill_app_longpress_back"
            android:summary="@string/kill_app_longpress_back_summary"
            android:defaultValue="false" />

        <SwitchPreference
            android:key="change_update_source"
            android:title="@string/title_ota"
            android:summary="@string/ota_summary" />
    </PreferenceCategory>

</PreferenceScreen>
+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 android.support.annotation.VisibleForTesting;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.preference.PreferenceManager;
import android.content.SharedPreferences;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.content.Context;

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

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

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

    @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;
    }
}
+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.
@@ -456,6 +457,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