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

Commit b1e5137a authored by Jim Miller's avatar Jim Miller Committed by Android (Google) Code Review
Browse files

Merge "Move owner info from Settings.Secure to LockSettings" into jb-mr2-dev

parents a0042742 187ec581
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -3260,6 +3260,7 @@ public final class Settings {
        /**
        /**
         * This preference contains the string that shows for owner info on LockScreen.
         * This preference contains the string that shows for owner info on LockScreen.
         * @hide
         * @hide
         * @deprecated
         */
         */
        public static final String LOCK_SCREEN_OWNER_INFO = "lock_screen_owner_info";
        public static final String LOCK_SCREEN_OWNER_INFO = "lock_screen_owner_info";


@@ -3287,6 +3288,7 @@ public final class Settings {
        /**
        /**
         * This preference enables showing the owner info on LockScreen.
         * This preference enables showing the owner info on LockScreen.
         * @hide
         * @hide
         * @deprecated
         */
         */
        public static final String LOCK_SCREEN_OWNER_INFO_ENABLED =
        public static final String LOCK_SCREEN_OWNER_INFO_ENABLED =
            "lock_screen_owner_info_enabled";
            "lock_screen_owner_info_enabled";
@@ -4102,9 +4104,7 @@ public final class Settings {
            MOUNT_UMS_AUTOSTART,
            MOUNT_UMS_AUTOSTART,
            MOUNT_UMS_PROMPT,
            MOUNT_UMS_PROMPT,
            MOUNT_UMS_NOTIFY_ENABLED,
            MOUNT_UMS_NOTIFY_ENABLED,
            UI_NIGHT_MODE,
            UI_NIGHT_MODE
            LOCK_SCREEN_OWNER_INFO,
            LOCK_SCREEN_OWNER_INFO_ENABLED
        };
        };


        /**
        /**
+20 −0
Original line number Original line Diff line number Diff line
@@ -140,6 +140,10 @@ public class LockPatternUtils {


    public final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory";
    public final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory";


    private static final String LOCK_SCREEN_OWNER_INFO = Settings.Secure.LOCK_SCREEN_OWNER_INFO;
    private static final String LOCK_SCREEN_OWNER_INFO_ENABLED =
            Settings.Secure.LOCK_SCREEN_OWNER_INFO_ENABLED;

    private final Context mContext;
    private final Context mContext;
    private final ContentResolver mContentResolver;
    private final ContentResolver mContentResolver;
    private DevicePolicyManager mDevicePolicyManager;
    private DevicePolicyManager mDevicePolicyManager;
@@ -526,6 +530,22 @@ public class LockPatternUtils {
        }
        }
    }
    }


    public void setOwnerInfo(String info, int userId) {
        setString(LOCK_SCREEN_OWNER_INFO, info, userId);
    }

    public void setOwnerInfoEnabled(boolean enabled) {
        setBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, enabled);
    }

    public String getOwnerInfo(int userId) {
        return getString(LOCK_SCREEN_OWNER_INFO);
    }

    public boolean isOwnerInfoEnabled() {
        return getBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, false);
    }

    /**
    /**
     * Compute the password quality from the given password string.
     * Compute the password quality from the given password string.
     */
     */
+19 −7
Original line number Original line Diff line number Diff line
@@ -23,12 +23,16 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.os.BatteryManager;
import android.os.BatteryManager;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.View;
import android.view.View;
import android.widget.TextView;
import android.widget.TextView;


@@ -37,6 +41,8 @@ import libcore.util.MutableInt;
import java.lang.ref.WeakReference;
import java.lang.ref.WeakReference;


import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.widget.ILockSettings;
import com.android.internal.widget.LockPatternUtils;


/***
/***
 * Manages a number of views inside of the given layout. See below for a list of widgets.
 * Manages a number of views inside of the given layout. See below for a list of widgets.
@@ -57,6 +63,8 @@ class KeyguardMessageArea extends TextView {
    static final int SECURITY_MESSAGE_DURATION = 5000;
    static final int SECURITY_MESSAGE_DURATION = 5000;
    protected static final int FADE_DURATION = 750;
    protected static final int FADE_DURATION = 750;


    private static final String TAG = "KeyguardMessageArea";

    // are we showing battery information?
    // are we showing battery information?
    boolean mShowingBatteryInfo = false;
    boolean mShowingBatteryInfo = false;


@@ -82,6 +90,9 @@ class KeyguardMessageArea extends TextView {


    CharSequence mMessage;
    CharSequence mMessage;
    boolean mShowingMessage;
    boolean mShowingMessage;
    private CharSequence mSeparator;
    private LockPatternUtils mLockPatternUtils;

    Runnable mClearMessageRunnable = new Runnable() {
    Runnable mClearMessageRunnable = new Runnable() {
        @Override
        @Override
        public void run() {
        public void run() {
@@ -156,8 +167,6 @@ class KeyguardMessageArea extends TextView {
        }
        }
    };
    };


    private CharSequence mSeparator;

    public KeyguardMessageArea(Context context) {
    public KeyguardMessageArea(Context context) {
        this(context, null);
        this(context, null);
    }
    }
@@ -165,6 +174,8 @@ class KeyguardMessageArea extends TextView {
    public KeyguardMessageArea(Context context, AttributeSet attrs) {
    public KeyguardMessageArea(Context context, AttributeSet attrs) {
        super(context, attrs);
        super(context, attrs);


        mLockPatternUtils = new LockPatternUtils(context);

        // This is required to ensure marquee works
        // This is required to ensure marquee works
        setSelected(true);
        setSelected(true);


@@ -228,11 +239,12 @@ class KeyguardMessageArea extends TextView {


    String getOwnerInfo() {
    String getOwnerInfo() {
        ContentResolver res = getContext().getContentResolver();
        ContentResolver res = getContext().getContentResolver();
        final boolean ownerInfoEnabled = Settings.Secure.getIntForUser(res,
        String info = null;
                Settings.Secure.LOCK_SCREEN_OWNER_INFO_ENABLED, 1, UserHandle.USER_CURRENT) != 0;
        final boolean ownerInfoEnabled = mLockPatternUtils.isOwnerInfoEnabled();
        return ownerInfoEnabled && !mShowingMessage ?
        if (ownerInfoEnabled && !mShowingMessage) {
                Settings.Secure.getStringForUser(res, Settings.Secure.LOCK_SCREEN_OWNER_INFO,
            info = mLockPatternUtils.getOwnerInfo(mLockPatternUtils.getCurrentUser());
                        UserHandle.USER_CURRENT) : null;
        }
        return info;
    }
    }


    private CharSequence getChargeInfo(MutableInt icon) {
    private CharSequence getChargeInfo(MutableInt icon) {
+53 −13
Original line number Original line Diff line number Diff line
@@ -19,6 +19,9 @@ package com.android.server;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
import android.content.pm.UserInfo;

import static android.content.Context.USER_SERVICE;
import android.database.Cursor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteOpenHelper;
@@ -27,8 +30,10 @@ import android.os.Environment;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.provider.Settings.Secure;
import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Slog;
import android.util.Slog;


@@ -40,6 +45,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.RandomAccessFile;
import java.util.Arrays;
import java.util.Arrays;
import java.util.List;


/**
/**
 * Keeps the lock pattern/password data and related settings for each user.
 * Keeps the lock pattern/password data and related settings for each user.
@@ -79,11 +85,9 @@ public class LockSettingsService extends ILockSettings.Stub {


    private void migrateOldData() {
    private void migrateOldData() {
        try {
        try {
            if (getString("migrated", null, 0) != null) {
            // These Settings moved before multi-user was enabled, so we only have to do it for the
                // Already migrated
            // root user.
                return;
            if (getString("migrated", null, 0) == null) {
            }

                final ContentResolver cr = mContext.getContentResolver();
                final ContentResolver cr = mContext.getContentResolver();
                for (String validSetting : VALID_SETTINGS) {
                for (String validSetting : VALID_SETTINGS) {
                    String value = Settings.Secure.getString(cr, validSetting);
                    String value = Settings.Secure.getString(cr, validSetting);
@@ -94,8 +98,39 @@ public class LockSettingsService extends ILockSettings.Stub {
                // No need to move the password / pattern files. They're already in the right place.
                // No need to move the password / pattern files. They're already in the right place.
                setString("migrated", "true", 0);
                setString("migrated", "true", 0);
                Slog.i(TAG, "Migrated lock settings to new location");
                Slog.i(TAG, "Migrated lock settings to new location");
            }

            // These Settings changed after multi-user was enabled, hence need to be moved per user.
            if (getString("migrated_user_specific", null, 0) == null) {
                final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE);
                final ContentResolver cr = mContext.getContentResolver();
                List<UserInfo> users = um.getUsers();
                for (int user = 0; user < users.size(); user++) {
                    int userId = users.get(user).getUserHandle().getIdentifier();
                    for (String perUserSetting : MIGRATE_SETTINGS_PER_USER) {
                        // Handle Strings
                        String value = Settings.Secure.getStringForUser(cr, perUserSetting, userId);
                        if (value != null) {
                            setString(perUserSetting, value, userId);
                            Settings.Secure.putStringForUser(cr, perUserSetting, "", userId);
                            continue;
                        }

                        // Handle integers
                        try {
                            int ivalue = Settings.Secure.getIntForUser(cr, perUserSetting, userId);
                            setLong(perUserSetting, ivalue, userId);
                            Settings.Secure.putIntForUser(cr, perUserSetting, 0, userId);
                        } catch (SettingNotFoundException e) {
                        }
                    }
                }
                // No need to move the password / pattern files. They're already in the right place.
                setString("migrated_user_specific", "true", 0);
                Slog.i(TAG, "Migrated per-user lock settings to new location");
            }
        } catch (RemoteException re) {
        } catch (RemoteException re) {
            Slog.e(TAG, "Unable to migrate old data");
            Slog.e(TAG, "Unable to migrate old data", re);
        }
        }
    }
    }


@@ -405,4 +440,9 @@ public class LockSettingsService extends ILockSettings.Stub {
        Secure.LOCK_PATTERN_VISIBLE,
        Secure.LOCK_PATTERN_VISIBLE,
        Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED
        Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED
    };
    };

    private static final String[] MIGRATE_SETTINGS_PER_USER = new String[] {
        Secure.LOCK_SCREEN_OWNER_INFO_ENABLED,
        Secure.LOCK_SCREEN_OWNER_INFO
    };
}
}