Loading core/java/com/android/internal/widget/LockPatternUtils.java +49 −7 Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ public class LockPatternUtils { = "lockscreen.biometricweakeverchosen"; public final static String LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS = "lockscreen.power_button_instantly_locks"; public final static String LOCKSCREEN_WIDGETS_ENABLED = "lockscreen.widgets_enabled"; public final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory"; Loading Loading @@ -1053,28 +1054,38 @@ public class LockPatternUtils { return nextAlarm; } private boolean getBoolean(String secureSettingKey, boolean defaultValue) { private boolean getBoolean(String secureSettingKey, boolean defaultValue, int userId) { try { return getLockSettings().getBoolean(secureSettingKey, defaultValue, getCurrentOrCallingUserId()); return getLockSettings().getBoolean(secureSettingKey, defaultValue, userId); } catch (RemoteException re) { return defaultValue; } } private void setBoolean(String secureSettingKey, boolean enabled) { private boolean getBoolean(String secureSettingKey, boolean defaultValue) { return getBoolean(secureSettingKey, defaultValue, getCurrentOrCallingUserId()); } private void setBoolean(String secureSettingKey, boolean enabled, int userId) { try { getLockSettings().setBoolean(secureSettingKey, enabled, getCurrentOrCallingUserId()); getLockSettings().setBoolean(secureSettingKey, enabled, userId); } catch (RemoteException re) { // What can we do? Log.e(TAG, "Couldn't write boolean " + secureSettingKey + re); } } private void setBoolean(String secureSettingKey, boolean enabled) { setBoolean(secureSettingKey, enabled, getCurrentOrCallingUserId()); } public int[] getAppWidgets() { return getAppWidgets(UserHandle.USER_CURRENT); } private int[] getAppWidgets(int userId) { String appWidgetIdString = Settings.Secure.getStringForUser( mContentResolver, Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS, UserHandle.USER_CURRENT); mContentResolver, Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS, userId); String delims = ","; if (appWidgetIdString != null && appWidgetIdString.length() > 0) { String[] appWidgetStringIds = appWidgetIdString.split(delims); Loading Loading @@ -1361,4 +1372,35 @@ public class LockPatternUtils { return false; } /** * Determine whether the user has selected any non-system widgets in keyguard * * @return true if widgets have been selected */ public boolean hasWidgetsEnabledInKeyguard(int userid) { int widgets[] = getAppWidgets(userid); for (int i = 0; i < widgets.length; i++) { if (widgets[i] > 0) { return true; } } return false; } public boolean getWidgetsEnabled() { return getWidgetsEnabled(getCurrentOrCallingUserId()); } public boolean getWidgetsEnabled(int userId) { return getBoolean(LOCKSCREEN_WIDGETS_ENABLED, false, userId); } public void setWidgetsEnabled(boolean enabled) { setWidgetsEnabled(enabled, getCurrentOrCallingUserId()); } public void setWidgetsEnabled(boolean enabled, int userId) { setBoolean(LOCKSCREEN_WIDGETS_ENABLED, enabled, userId); } } packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java +11 −7 Original line number Diff line number Diff line Loading @@ -217,7 +217,7 @@ public class KeyguardHostView extends KeyguardViewBase { mCleanupAppWidgetsOnBootCompleted = true; return; } if (!mSafeModeEnabled && !widgetsDisabledByDpm()) { if (!mSafeModeEnabled && !widgetsDisabled()) { // Clean up appWidgetIds that are bound to lockscreen, but not actually used // This is only to clean up after another bug: we used to not call // deleteAppWidgetId when a user manually deleted a widget in keyguard. This code Loading Loading @@ -413,8 +413,11 @@ public class KeyguardHostView extends KeyguardViewBase { return disabledFeatures; } private boolean widgetsDisabledByDpm() { return (mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0; private boolean widgetsDisabled() { boolean disabledByDpm = (mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0; boolean disabledByUser = !mLockPatternUtils.getWidgetsEnabled(); return disabledByDpm || disabledByUser; } private boolean cameraDisabledByDpm() { Loading Loading @@ -1149,7 +1152,7 @@ public class KeyguardHostView extends KeyguardViewBase { } private void addDefaultWidgets() { if (!mSafeModeEnabled && !widgetsDisabledByDpm()) { if (!mSafeModeEnabled && !widgetsDisabled()) { LayoutInflater inflater = LayoutInflater.from(mContext); View addWidget = inflater.inflate(R.layout.keyguard_add_widget, this, false); mAppWidgetContainer.addWidget(addWidget, 0); Loading Loading @@ -1209,7 +1212,7 @@ public class KeyguardHostView extends KeyguardViewBase { } private void addWidgetsFromSettings() { if (mSafeModeEnabled || widgetsDisabledByDpm()) { if (mSafeModeEnabled || widgetsDisabled()) { return; } Loading Loading @@ -1246,7 +1249,6 @@ public class KeyguardHostView extends KeyguardViewBase { try { mAppWidgetManager.bindAppWidgetId(appWidgetId, defaultAppWidget); } catch (IllegalArgumentException e) { Log.e(TAG, "Error when trying to bind default AppWidget: " + e); mAppWidgetHost.deleteAppWidgetId(appWidgetId); Loading @@ -1254,6 +1256,7 @@ public class KeyguardHostView extends KeyguardViewBase { } return appWidgetId; } public void checkAppWidgetConsistency() { // Since this method may bind a widget (which we can't do until boot completed) we // may have to defer it until after boot complete. Loading @@ -1272,7 +1275,8 @@ public class KeyguardHostView extends KeyguardViewBase { if (!widgetPageExists) { final int insertPageIndex = getInsertPageIndex(); final boolean userAddedWidgetsEnabled = !widgetsDisabledByDpm(); final boolean userAddedWidgetsEnabled = !widgetsDisabled(); boolean addedDefaultAppWidget = false; if (!mSafeModeEnabled) { Loading services/java/com/android/server/LockSettingsService.java +45 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server; import android.app.ActivityManagerNative; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; Loading @@ -27,6 +28,9 @@ import static android.Manifest.permission.READ_PROFILE; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; import android.media.AudioManager; import android.media.AudioService; import android.os.Binder; import android.os.Environment; import android.os.RemoteException; Loading @@ -37,6 +41,7 @@ import android.provider.Settings; import android.provider.Settings.Secure; import android.provider.Settings.SettingNotFoundException; import android.text.TextUtils; import android.util.Log; import android.util.Slog; import com.android.internal.widget.ILockSettings; Loading Loading @@ -391,7 +396,7 @@ public class LockSettingsService extends ILockSettings.Stub { private static final String TAG = "LockSettingsDB"; private static final String DATABASE_NAME = "locksettings.db"; private static final int DATABASE_VERSION = 1; private static final int DATABASE_VERSION = 2; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); Loading Loading @@ -424,7 +429,45 @@ public class LockSettingsService extends ILockSettings.Stub { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) { // Nothing yet int upgradeVersion = oldVersion; if (upgradeVersion == 1) { // Set the initial value for {@link LockPatternUtils#LOCKSCREEN_WIDGETS_ENABLED} // during upgrade based on whether each user previously had widgets in keyguard. maybeEnableWidgetSettingForUsers(db); upgradeVersion = 2; } if (upgradeVersion != DATABASE_VERSION) { Log.w(TAG, "Failed to upgrade database!"); } } private void maybeEnableWidgetSettingForUsers(SQLiteDatabase db) { final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE); final ContentResolver cr = mContext.getContentResolver(); final LockPatternUtils utils = new LockPatternUtils(mContext); final List<UserInfo> users = um.getUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; final boolean enabled = utils.hasWidgetsEnabledInKeyguard(userId); Log.v(TAG, "Widget upgrade uid=" + userId + ", enabled=" + enabled + ", w[]=" + utils.getAppWidgets()); loadSetting(db, LockPatternUtils.LOCKSCREEN_WIDGETS_ENABLED, userId, enabled); } } private void loadSetting(SQLiteDatabase db, String key, int userId, boolean value) { SQLiteStatement stmt = null; try { stmt = db.compileStatement( "INSERT OR REPLACE INTO locksettings(name,user,value) VALUES(?,?,?);"); stmt.bindString(1, key); stmt.bindLong(2, userId); stmt.bindLong(3, value ? 1 : 0); stmt.execute(); } finally { if (stmt != null) stmt.close(); } } } Loading Loading
core/java/com/android/internal/widget/LockPatternUtils.java +49 −7 Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ public class LockPatternUtils { = "lockscreen.biometricweakeverchosen"; public final static String LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS = "lockscreen.power_button_instantly_locks"; public final static String LOCKSCREEN_WIDGETS_ENABLED = "lockscreen.widgets_enabled"; public final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory"; Loading Loading @@ -1053,28 +1054,38 @@ public class LockPatternUtils { return nextAlarm; } private boolean getBoolean(String secureSettingKey, boolean defaultValue) { private boolean getBoolean(String secureSettingKey, boolean defaultValue, int userId) { try { return getLockSettings().getBoolean(secureSettingKey, defaultValue, getCurrentOrCallingUserId()); return getLockSettings().getBoolean(secureSettingKey, defaultValue, userId); } catch (RemoteException re) { return defaultValue; } } private void setBoolean(String secureSettingKey, boolean enabled) { private boolean getBoolean(String secureSettingKey, boolean defaultValue) { return getBoolean(secureSettingKey, defaultValue, getCurrentOrCallingUserId()); } private void setBoolean(String secureSettingKey, boolean enabled, int userId) { try { getLockSettings().setBoolean(secureSettingKey, enabled, getCurrentOrCallingUserId()); getLockSettings().setBoolean(secureSettingKey, enabled, userId); } catch (RemoteException re) { // What can we do? Log.e(TAG, "Couldn't write boolean " + secureSettingKey + re); } } private void setBoolean(String secureSettingKey, boolean enabled) { setBoolean(secureSettingKey, enabled, getCurrentOrCallingUserId()); } public int[] getAppWidgets() { return getAppWidgets(UserHandle.USER_CURRENT); } private int[] getAppWidgets(int userId) { String appWidgetIdString = Settings.Secure.getStringForUser( mContentResolver, Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS, UserHandle.USER_CURRENT); mContentResolver, Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS, userId); String delims = ","; if (appWidgetIdString != null && appWidgetIdString.length() > 0) { String[] appWidgetStringIds = appWidgetIdString.split(delims); Loading Loading @@ -1361,4 +1372,35 @@ public class LockPatternUtils { return false; } /** * Determine whether the user has selected any non-system widgets in keyguard * * @return true if widgets have been selected */ public boolean hasWidgetsEnabledInKeyguard(int userid) { int widgets[] = getAppWidgets(userid); for (int i = 0; i < widgets.length; i++) { if (widgets[i] > 0) { return true; } } return false; } public boolean getWidgetsEnabled() { return getWidgetsEnabled(getCurrentOrCallingUserId()); } public boolean getWidgetsEnabled(int userId) { return getBoolean(LOCKSCREEN_WIDGETS_ENABLED, false, userId); } public void setWidgetsEnabled(boolean enabled) { setWidgetsEnabled(enabled, getCurrentOrCallingUserId()); } public void setWidgetsEnabled(boolean enabled, int userId) { setBoolean(LOCKSCREEN_WIDGETS_ENABLED, enabled, userId); } }
packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java +11 −7 Original line number Diff line number Diff line Loading @@ -217,7 +217,7 @@ public class KeyguardHostView extends KeyguardViewBase { mCleanupAppWidgetsOnBootCompleted = true; return; } if (!mSafeModeEnabled && !widgetsDisabledByDpm()) { if (!mSafeModeEnabled && !widgetsDisabled()) { // Clean up appWidgetIds that are bound to lockscreen, but not actually used // This is only to clean up after another bug: we used to not call // deleteAppWidgetId when a user manually deleted a widget in keyguard. This code Loading Loading @@ -413,8 +413,11 @@ public class KeyguardHostView extends KeyguardViewBase { return disabledFeatures; } private boolean widgetsDisabledByDpm() { return (mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0; private boolean widgetsDisabled() { boolean disabledByDpm = (mDisabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0; boolean disabledByUser = !mLockPatternUtils.getWidgetsEnabled(); return disabledByDpm || disabledByUser; } private boolean cameraDisabledByDpm() { Loading Loading @@ -1149,7 +1152,7 @@ public class KeyguardHostView extends KeyguardViewBase { } private void addDefaultWidgets() { if (!mSafeModeEnabled && !widgetsDisabledByDpm()) { if (!mSafeModeEnabled && !widgetsDisabled()) { LayoutInflater inflater = LayoutInflater.from(mContext); View addWidget = inflater.inflate(R.layout.keyguard_add_widget, this, false); mAppWidgetContainer.addWidget(addWidget, 0); Loading Loading @@ -1209,7 +1212,7 @@ public class KeyguardHostView extends KeyguardViewBase { } private void addWidgetsFromSettings() { if (mSafeModeEnabled || widgetsDisabledByDpm()) { if (mSafeModeEnabled || widgetsDisabled()) { return; } Loading Loading @@ -1246,7 +1249,6 @@ public class KeyguardHostView extends KeyguardViewBase { try { mAppWidgetManager.bindAppWidgetId(appWidgetId, defaultAppWidget); } catch (IllegalArgumentException e) { Log.e(TAG, "Error when trying to bind default AppWidget: " + e); mAppWidgetHost.deleteAppWidgetId(appWidgetId); Loading @@ -1254,6 +1256,7 @@ public class KeyguardHostView extends KeyguardViewBase { } return appWidgetId; } public void checkAppWidgetConsistency() { // Since this method may bind a widget (which we can't do until boot completed) we // may have to defer it until after boot complete. Loading @@ -1272,7 +1275,8 @@ public class KeyguardHostView extends KeyguardViewBase { if (!widgetPageExists) { final int insertPageIndex = getInsertPageIndex(); final boolean userAddedWidgetsEnabled = !widgetsDisabledByDpm(); final boolean userAddedWidgetsEnabled = !widgetsDisabled(); boolean addedDefaultAppWidget = false; if (!mSafeModeEnabled) { Loading
services/java/com/android/server/LockSettingsService.java +45 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server; import android.app.ActivityManagerNative; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; Loading @@ -27,6 +28,9 @@ import static android.Manifest.permission.READ_PROFILE; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; import android.media.AudioManager; import android.media.AudioService; import android.os.Binder; import android.os.Environment; import android.os.RemoteException; Loading @@ -37,6 +41,7 @@ import android.provider.Settings; import android.provider.Settings.Secure; import android.provider.Settings.SettingNotFoundException; import android.text.TextUtils; import android.util.Log; import android.util.Slog; import com.android.internal.widget.ILockSettings; Loading Loading @@ -391,7 +396,7 @@ public class LockSettingsService extends ILockSettings.Stub { private static final String TAG = "LockSettingsDB"; private static final String DATABASE_NAME = "locksettings.db"; private static final int DATABASE_VERSION = 1; private static final int DATABASE_VERSION = 2; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); Loading Loading @@ -424,7 +429,45 @@ public class LockSettingsService extends ILockSettings.Stub { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) { // Nothing yet int upgradeVersion = oldVersion; if (upgradeVersion == 1) { // Set the initial value for {@link LockPatternUtils#LOCKSCREEN_WIDGETS_ENABLED} // during upgrade based on whether each user previously had widgets in keyguard. maybeEnableWidgetSettingForUsers(db); upgradeVersion = 2; } if (upgradeVersion != DATABASE_VERSION) { Log.w(TAG, "Failed to upgrade database!"); } } private void maybeEnableWidgetSettingForUsers(SQLiteDatabase db) { final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE); final ContentResolver cr = mContext.getContentResolver(); final LockPatternUtils utils = new LockPatternUtils(mContext); final List<UserInfo> users = um.getUsers(); for (int i = 0; i < users.size(); i++) { final int userId = users.get(i).id; final boolean enabled = utils.hasWidgetsEnabledInKeyguard(userId); Log.v(TAG, "Widget upgrade uid=" + userId + ", enabled=" + enabled + ", w[]=" + utils.getAppWidgets()); loadSetting(db, LockPatternUtils.LOCKSCREEN_WIDGETS_ENABLED, userId, enabled); } } private void loadSetting(SQLiteDatabase db, String key, int userId, boolean value) { SQLiteStatement stmt = null; try { stmt = db.compileStatement( "INSERT OR REPLACE INTO locksettings(name,user,value) VALUES(?,?,?);"); stmt.bindString(1, key); stmt.bindLong(2, userId); stmt.bindLong(3, value ? 1 : 0); stmt.execute(); } finally { if (stmt != null) stmt.close(); } } } Loading