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

Commit 4cd5e7e9 authored by Aayush Gupta's avatar Aayush Gupta Committed by Romain Hunault
Browse files

Resolve current MicroG EN issues

parent bbc047bc
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,15 @@ android {
        vectorDrawables.useSupportLibrary = true
    }

    signingConfigs {
        config {
            storeFile file("../platform.keystore")
            storePassword 'android'
            keyAlias 'platform'
            keyPassword 'android'
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
@@ -28,6 +37,9 @@ android {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        platform {
            signingConfig signingConfigs.config
        }
    }
    lintOptions {
        lintConfig file("lint.xml")
+0 −8
Original line number Diff line number Diff line
@@ -75,14 +75,6 @@
            android:launchMode="singleInstance"
            android:theme="@style/AppTheme1"
            android:windowSoftInputMode="adjustResize" />


        <provider
            android:name=".MicroGProvider"
            android:authorities="foundation.e.apps.micro.status"
            android:exported="true"
          />

    </application>

</manifest>
 No newline at end of file
+5 −22
Original line number Diff line number Diff line
@@ -49,8 +49,10 @@ import foundation.e.apps.search.SearchFragment
import foundation.e.apps.settings.SettingsFragment
import foundation.e.apps.updates.UpdatesFragment
import foundation.e.apps.updates.UpdatesManager
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
import foundation.e.apps.utils.Constants.CURRENTLY_SELECTED_FRAGMENT_KEY
import foundation.e.apps.utils.Constants.MICROG_SHARED_PREF
import foundation.e.apps.utils.PreferenceStorage
import kotlinx.android.synthetic.main.activity_main.*

@@ -110,6 +112,8 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS

        disableShiftingOfNabBarItems()

        Common.updateMicroGStatus(this)

        initialiseUpdatesWorker()


@@ -132,15 +136,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS

    override fun onResume() {
        super.onResume()
        if (retrieveStatus() != null) {
            if (retrieveStatus().equals("true")) {
                PreferenceStorage(this).save(getString(R.string.prefs_microg_vrsn_installed), true)
            } else {
                PreferenceStorage(this).save(getString(R.string.prefs_microg_vrsn_installed), false)
            }
        } else {
            PreferenceStorage(this).save(getString(R.string.prefs_microg_vrsn_installed), false)
        }
        Common.updateMicroGStatus(this)
    }

    private fun openSearchFragment() {
@@ -172,19 +168,6 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS

    }

    private fun retrieveStatus(): String? {
        var status: String? = null
        val c: Cursor? = contentResolver.query(MicroGProvider.CONTENT_URI, null, "id=?", arrayOf("1"), "installStatus")
        if (c!!.moveToFirst()) {
            do {
                status = c.getString(c.getColumnIndex("installStatus"))
            } while (c.moveToNext())
        }
        c.close()
        return status
    }


    private fun initialiseUpdatesWorker() {
        UpdatesManager(applicationContext).startWorker()

+0 −161
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019-2021  E FOUNDATION
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps;

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;

import java.util.HashMap;

public class MicroGProvider extends ContentProvider {

    public static final String PROVIDER_NAME = "foundation.e.apps.micro.status";
    public static final String URL = "content://" + PROVIDER_NAME + "/cte";
    public static final Uri CONTENT_URI = Uri.parse(URL);

    public static final String id = "id";
    public static final String installStatus = "installStatus";
    public static final int uriCode = 1;
    public static final UriMatcher uriMatcher;
    private static HashMap<String, String> values;

    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.equals("")) {
            sortOrder = installStatus;
        }
        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 SQLiteDatabase db;
    static final String DATABASE_NAME = "microGDB";
    static final String TABLE_NAME = "microgtable";
    static final int DATABASE_VERSION = 1;
    static final String CREATE_DB_TABLE = " CREATE TABLE " + TABLE_NAME
            + " (id INTEGER PRIMARY KEY AUTOINCREMENT, "
            + " installStatus TEXT NOT NULL);";

    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);
        }
    }
}
+7 −14
Original line number Diff line number Diff line
@@ -27,10 +27,10 @@ import android.net.Uri
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import foundation.e.apps.MicroGProvider
import foundation.e.apps.R
import foundation.e.apps.XAPK.FsUtils.deleteFileOrDir
import foundation.e.apps.utils.Constants
import foundation.e.apps.utils.Constants.MICROG_SHARED_PREF
import foundation.e.apps.utils.PreferenceStorage
import java.io.File
import java.io.IOException
@@ -126,7 +126,11 @@ class Installer(private val packageName: String,
            context.unregisterReceiver(receiver)
            Log.i(TAG, "Unregistered old broadcast receiver")
        } catch (exception: Exception) {
            if (exception !is IllegalArgumentException) {
                exception.printStackTrace()
            } else {
                Log.d(TAG, "Broadcast receiver is already unregistered")
            }
        }
        context.registerReceiver(receiver, IntentFilter().apply {
            addAction(Intent.ACTION_PACKAGE_ADDED)
@@ -146,18 +150,7 @@ class Installer(private val packageName: String,
                callback.onInstallationComplete(context)

                if (packageName == Constants.MICROG_PACKAGE) {
                      PreferenceStorage(context).save(context.getString(R.string.prefs_microg_vrsn_installed), true)
                    if (count(MicroGProvider.CONTENT_URI, context)) {
                        val values = ContentValues()
                        values.put(MicroGProvider.installStatus, "true")
                        val state=context.contentResolver.update(MicroGProvider.CONTENT_URI, values,
                                MicroGProvider.id + "=?", arrayOf("1"))
                    } else {
                        val values = ContentValues()
                        values.put(MicroGProvider.installStatus, "true")
                        val state=context.contentResolver.insert(MicroGProvider.CONTENT_URI, values);
                    }

                      PreferenceStorage(context).save(MICROG_SHARED_PREF, true)
                }
            }
        }
Loading