diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4eb186d32c2396338997de6030ef0e2cc833a66c..69fa9cf3fc00c8c02dc16bbe1ad4cfa304fa138f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -3321,6 +3321,12 @@ + + diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index e9c1efc6e692d47f1abf6eec0920f8f98b1c9246..5915ac57837f5a2cedf8eb8426ad2b3a2b7a48ef 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -57,6 +57,10 @@ Kill app back button Kill the foreground app by long-pressing the back button + + Use staging OTA server + Change to OTA/Production server + /e/ legal diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml index 0262556d0926e0c90a4b469faaac804e9eb32d01..ff8cd126644b632675fcd076627e1b84d14adff8 100644 --- a/res/xml/development_settings.xml +++ b/res/xml/development_settings.xml @@ -614,6 +614,10 @@ android:summary="@string/kill_app_longpress_back_summary" android:defaultValue="false" /> + 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 diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index f18225e8fb578f1520aabbfa5fdbb9e3bb2e6709..caf18e995c1e6b6c2659f39771fe984f6b8903a5 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -1,5 +1,6 @@ /* * 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)); diff --git a/src/com/android/settings/development/OTAProvider.java b/src/com/android/settings/development/OTAProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..6dd785c43f126b5c08489afc38cd77712c5e53da --- /dev/null +++ b/src/com/android/settings/development/OTAProvider.java @@ -0,0 +1,159 @@ +/* + * 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 java.util.HashMap; + +import android.content.ContentProvider; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.content.UriMatcher; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.database.sqlite.SQLiteQueryBuilder; +import android.net.Uri; + +public class OTAProvider extends ContentProvider { + + static final String PROVIDER_NAME = "custom.setting.Provider.OTA_SERVER"; + static final String URL = "content://" + PROVIDER_NAME + "/cte"; + static final Uri CONTENT_URI = Uri.parse(URL); + + static final String id = "id"; + static final String Status = "Status"; + static final int uriCode = 1; + static final UriMatcher uriMatcher; + private static HashMap values; + private SQLiteDatabase db; + static final String DATABASE_NAME = "mydb"; + static final String TABLE_NAME = "ota"; + static final int DATABASE_VERSION = 1; + static final String CREATE_DB_TABLE = " CREATE TABLE " + TABLE_NAME + + " (id INTEGER PRIMARY KEY AUTOINCREMENT, " + + " Status TEXT NOT NULL);"; + static { + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(PROVIDER_NAME, "cte", uriCode); + uriMatcher.addURI(PROVIDER_NAME, "cte/*", uriCode); + } + + @Override + public boolean onCreate() { + Context context = getContext(); + DatabaseHelper dbHelper = new DatabaseHelper(context); + db = dbHelper.getWritableDatabase(); + if (db != null) { + return true; + } + return false; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); + qb.setTables(TABLE_NAME); + + switch (uriMatcher.match(uri)) { + case uriCode: + qb.setProjectionMap(values); + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + if (sortOrder == null || sortOrder == "") { + sortOrder = Status; + } + Cursor c = qb.query(db, projection, selection, selectionArgs, null, + null, sortOrder); + c.setNotificationUri(getContext().getContentResolver(), uri); + return c; + } + + + @Override + public String getType(Uri uri) { + switch (uriMatcher.match(uri)) { + case uriCode: + return "vnd.android.cursor.dir/cte"; + + default: + throw new IllegalArgumentException("Unsupported URI: " + uri); + } + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + long rowID = db.insert(TABLE_NAME, "", values); + if (rowID > 0) { + Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID); + getContext().getContentResolver().notifyChange(_uri, null); + return _uri; + } + throw new SQLException("Failed to add a record into " + uri); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + int count = 0; + switch (uriMatcher.match(uri)) { + case uriCode: + count = db.delete(TABLE_NAME, selection, selectionArgs); + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + getContext().getContentResolver().notifyChange(uri, null); + return count; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + int count = 0; + switch (uriMatcher.match(uri)) { + case uriCode: + count = db.update(TABLE_NAME, values, selection, selectionArgs); + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + getContext().getContentResolver().notifyChange(uri, null); + return count; + } + + + private static class DatabaseHelper extends SQLiteOpenHelper { + DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(CREATE_DB_TABLE); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); + onCreate(db); + } + } +} \ No newline at end of file