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

Commit 147b4d75 authored by Jerome Poichet's avatar Jerome Poichet
Browse files

Adding device name

A new global settings to name a device. This will centralize the notion
of device name/nickname and should be used by Cast, Bluetooth, TV Remote and other
advertising applications/services.

Change-Id: I2294deb5c0d1002fb2fc158f62a2d5643d90d749
parent 4cf79657
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -6146,6 +6146,13 @@ public final class Settings {
        /** @hide */ public static final int HEADS_UP_OFF = 0;
        /** @hide */ public static final int HEADS_UP_ON = 1;

        /**
         * The name of the device
         *
         * @hide
         */
        public static final String DEVICE_NAME = "device_name";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+3 −0
Original line number Diff line number Diff line
@@ -189,4 +189,7 @@
    <!-- Default for Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, 1==on -->
    <integer name="def_heads_up_enabled">1</integer>

    <!-- Default for Settings.Global.DEVICE_NAME $1=BRAND $2=MODEL-->
    <string name="def_device_name">%1$s %2$s</string>

</resources>
+26 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.database.sqlite.SQLiteStatement;
import android.media.AudioManager;
import android.media.AudioService;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Environment;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -69,7 +70,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 = 101;
    private static final int DATABASE_VERSION = 102;

    private Context mContext;
    private int mUserHandle;
@@ -1614,6 +1615,23 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 101;
        }

        if (upgradeVersion == 101) {
            if (mUserHandle == UserHandle.USER_OWNER) {
                db.beginTransaction();
                SQLiteStatement stmt = null;
                try {
                    stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
                            + " VALUES(?,?);");
                    loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction();
                    if (stmt != null) stmt.close();
                }
            }
            upgradeVersion = 102;
        }

        // *** Remember to update DATABASE_VERSION above!

        if (upgradeVersion != currentVersion) {
@@ -2342,6 +2360,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
                    R.integer.def_heads_up_enabled);

            loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());

            // --- New global settings start here
        } finally {
            if (stmt != null) stmt.close();
@@ -2398,4 +2418,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        }
        return defaultValue;
    }

    private String getDefaultDeviceName() {
        return mContext.getResources().getString(R.string.def_device_name, Build.BRAND,
                Build.MODEL);
    }
}