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

Commit 4c71d695 authored by Steve Kondik's avatar Steve Kondik
Browse files

quickboot: Only enable QuickBoot if package is installed

 * Also move to Settings.Global

Change-Id: I87e1464d717b41437072523c0ecab52227d7888b
parent 11527526
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -7218,6 +7218,13 @@ public final class Settings {
         */
        public static final String LOW_BATTERY_SOUND_TIMEOUT = "low_battery_sound_timeout";

        /**
         * Enable the QuickBoot feature
         *
         * @hide
         */
        public static final String ENABLE_QUICKBOOT = "enable_quickboot";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+32 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.XmlResourceParser;
import android.database.Cursor;
import android.database.SQLException;
@@ -78,7 +79,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    private static final int DATABASE_VERSION = 98;
    private static final int DATABASE_VERSION = 99;

    private Context mContext;
    private int mUserHandle;
@@ -1609,6 +1610,13 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 98;
        }

        if (upgradeVersion == 98) {
            if (mUserHandle == UserHandle.USER_OWNER) {
                loadQuickBootSetting(db);
            }
            upgradeVersion = 99;
        }

        // *** Remember to update DATABASE_VERSION above!

        if (upgradeVersion != currentVersion) {
@@ -2014,6 +2022,27 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        }
    }

    private void loadQuickBootSetting(SQLiteDatabase db) {
        boolean qbEnabled = true;
        final PackageManager pm = mContext.getPackageManager();
        try {
            pm.getPackageInfo("com.qapp.quickboot", PackageManager.GET_META_DATA);
        } catch (NameNotFoundException e) {
            qbEnabled = false;
        }
        db.beginTransaction();
        SQLiteStatement stmt = null;
        try {
            stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
                    + " VALUES(?,?);");
            loadSetting(stmt, Settings.Global.ENABLE_QUICKBOOT, qbEnabled ? 1 : 0);
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
            if (stmt != null) stmt.close();
        }
    }

    private void loadSettings(SQLiteDatabase db) {
        loadSystemSettings(db);
        loadSecureSettings(db);
@@ -2392,6 +2421,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                    R.integer.def_wifi_suspend_optimizations_enabled);

            // --- New global settings start here
            loadQuickBootSetting(db);

        } finally {
            if (stmt != null) stmt.close();
        }
+21 −2
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@ import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.ContentObserver;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
@@ -80,6 +82,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


/**
 * Needed for takeScreenshot
 */
@@ -296,8 +299,18 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        final ContentResolver cr = mContext.getContentResolver();
        mItems = new ArrayList<Action>();

        final boolean quickbootEnabled = Settings.System.getInt(
                mContext.getContentResolver(), "enable_quickboot", 0) == 1;
        int quickbootAvailable = 1;
        final PackageManager pm = mContext.getPackageManager();
        try {
            pm.getPackageInfo("com.qapp.quickboot", PackageManager.GET_META_DATA);
        } catch (NameNotFoundException e) {
            quickbootAvailable = 0;
        }

        final boolean quickbootEnabled = Settings.Global.getInt(
                mContext.getContentResolver(), Settings.Global.ENABLE_QUICKBOOT,
                quickbootAvailable) == 1;

        // first: power off
        mItems.add(
            new SinglePressAction(
@@ -315,6 +328,12 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                    mWindowManagerFuncs.shutdown(true);
                }

                public boolean onLongPress() {
                    // long press always does a full shutdown in case quickboot is enabled
                    mWindowManagerFuncs.shutdown(true);
                    return true;
                }

                public boolean showDuringKeyguard() {
                    return true;
                }