Merge "Disable adding keyguard widgets until setup is done" into jb-mr1.1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a8d63ec9f3
@ -24,7 +24,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
@ -54,8 +53,6 @@ import java.util.List;
|
||||
*/
|
||||
public class LockPatternUtils {
|
||||
|
||||
private static final String OPTION_ENABLE_FACELOCK = "enable_facelock";
|
||||
|
||||
private static final String TAG = "LockPatternUtils";
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,7 @@ import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
@ -101,6 +102,8 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
|
||||
private boolean mSafeModeEnabled;
|
||||
|
||||
private boolean mUserSetupCompleted;
|
||||
|
||||
/*package*/ interface TransportCallback {
|
||||
void onListenerDetached();
|
||||
void onListenerAttached();
|
||||
@ -143,6 +146,8 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
}
|
||||
|
||||
mSafeModeEnabled = LockPatternUtils.isSafeModeEnabled();
|
||||
mUserSetupCompleted = Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
|
||||
|
||||
if (mSafeModeEnabled) {
|
||||
Log.v(TAG, "Keyguard widgets disabled by safe mode");
|
||||
@ -270,7 +275,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
addDefaultWidgets();
|
||||
|
||||
addWidgetsFromSettings();
|
||||
if (numWidgets() >= MAX_WIDGETS) {
|
||||
if (!shouldEnableAddWidget()) {
|
||||
mAppWidgetContainer.setAddWidgetEnabled(false);
|
||||
}
|
||||
checkAppWidgetConsistency();
|
||||
@ -282,6 +287,10 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
updateSecurityViews();
|
||||
}
|
||||
|
||||
private boolean shouldEnableAddWidget() {
|
||||
return numWidgets() < MAX_WIDGETS && mUserSetupCompleted;
|
||||
}
|
||||
|
||||
private int getDisabledFeatures(DevicePolicyManager dpm) {
|
||||
int disabledFeatures = DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE;
|
||||
if (dpm != null) {
|
||||
@ -364,7 +373,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
|
||||
@Override
|
||||
public void onAddView(View v) {
|
||||
if (numWidgets() >= MAX_WIDGETS) {
|
||||
if (!shouldEnableAddWidget()) {
|
||||
mAppWidgetContainer.setAddWidgetEnabled(false);
|
||||
}
|
||||
}
|
||||
@ -382,7 +391,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
|
||||
@Override
|
||||
public void onRemoveViewAnimationCompleted() {
|
||||
if (numWidgets() < MAX_WIDGETS) {
|
||||
if (shouldEnableAddWidget()) {
|
||||
mAppWidgetContainer.setAddWidgetEnabled(true);
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import android.os.Handler;
|
||||
import android.os.IRemoteCallback;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.telephony.IccCardConstants;
|
||||
@ -113,7 +114,7 @@ public class KeyguardUpdateMonitor {
|
||||
|
||||
private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>>
|
||||
mCallbacks = Lists.newArrayList();
|
||||
private ContentObserver mContentObserver;
|
||||
private ContentObserver mDeviceProvisionedObserver;
|
||||
|
||||
private final Handler mHandler = new Handler() {
|
||||
@Override
|
||||
@ -322,9 +323,7 @@ public class KeyguardUpdateMonitor {
|
||||
private KeyguardUpdateMonitor(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mDeviceProvisioned = Settings.Global.getInt(
|
||||
mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
|
||||
|
||||
mDeviceProvisioned = isDeviceProvisionedInSettingsDb();
|
||||
// Since device can't be un-provisioned, we only need to register a content observer
|
||||
// to update mDeviceProvisioned when we are...
|
||||
if (!mDeviceProvisioned) {
|
||||
@ -373,13 +372,17 @@ public class KeyguardUpdateMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDeviceProvisionedInSettingsDb() {
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVICE_PROVISIONED, 0) != 0;
|
||||
}
|
||||
|
||||
private void watchForDeviceProvisioning() {
|
||||
mContentObserver = new ContentObserver(mHandler) {
|
||||
mDeviceProvisionedObserver = new ContentObserver(mHandler) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
mDeviceProvisioned = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVICE_PROVISIONED, 0) != 0;
|
||||
mDeviceProvisioned = isDeviceProvisionedInSettingsDb();
|
||||
if (mDeviceProvisioned) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED));
|
||||
}
|
||||
@ -389,12 +392,11 @@ public class KeyguardUpdateMonitor {
|
||||
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED),
|
||||
false, mContentObserver);
|
||||
false, mDeviceProvisionedObserver);
|
||||
|
||||
// prevent a race condition between where we check the flag and where we register the
|
||||
// observer by grabbing the value once again...
|
||||
boolean provisioned = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVICE_PROVISIONED, 0) != 0;
|
||||
boolean provisioned = isDeviceProvisionedInSettingsDb();
|
||||
if (provisioned != mDeviceProvisioned) {
|
||||
mDeviceProvisioned = provisioned;
|
||||
if (mDeviceProvisioned) {
|
||||
@ -475,10 +477,10 @@ public class KeyguardUpdateMonitor {
|
||||
cb.onDeviceProvisioned();
|
||||
}
|
||||
}
|
||||
if (mContentObserver != null) {
|
||||
if (mDeviceProvisionedObserver != null) {
|
||||
// We don't need the observer anymore...
|
||||
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
||||
mContentObserver = null;
|
||||
mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver);
|
||||
mDeviceProvisionedObserver = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user