Merge "Clean up info and callback architecture in KeyguardUpdateMonitor."
This commit is contained in:
@@ -21,8 +21,7 @@ import com.android.internal.telephony.IccCardConstants;
|
||||
import com.android.internal.widget.DigitalClock;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.internal.widget.TransportControlView;
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.InfoCallbackImpl;
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.SimStateCallback;
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.BatteryStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -107,6 +106,8 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
private CharSequence mSpn;
|
||||
protected int mPhoneState;
|
||||
private DigitalClock mDigitalClock;
|
||||
protected boolean mBatteryCharged;
|
||||
protected boolean mBatteryIsLow;
|
||||
|
||||
private class TransientTextManager {
|
||||
private TextView mTextView;
|
||||
@@ -198,8 +199,8 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
|
||||
mTransientTextManager = new TransientTextManager(mCarrierView);
|
||||
|
||||
mUpdateMonitor.registerInfoCallback(mInfoCallback);
|
||||
mUpdateMonitor.registerSimStateCallback(mSimStateCallback);
|
||||
// Registering this callback immediately updates the battery state, among other things.
|
||||
mUpdateMonitor.registerCallback(mInfoCallback);
|
||||
|
||||
resetStatusInfo();
|
||||
refreshDate();
|
||||
@@ -287,7 +288,6 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
public void onPause() {
|
||||
if (DEBUG) Log.v(TAG, "onPause()");
|
||||
mUpdateMonitor.removeCallback(mInfoCallback);
|
||||
mUpdateMonitor.removeCallback(mSimStateCallback);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@@ -299,8 +299,7 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
mDigitalClock.updateTime();
|
||||
}
|
||||
|
||||
mUpdateMonitor.registerInfoCallback(mInfoCallback);
|
||||
mUpdateMonitor.registerSimStateCallback(mSimStateCallback);
|
||||
mUpdateMonitor.registerCallback(mInfoCallback);
|
||||
resetStatusInfo();
|
||||
// Issue the biometric unlock failure message in a centralized place
|
||||
// TODO: we either need to make the Face Unlock multiple failures string a more general
|
||||
@@ -312,9 +311,6 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
|
||||
void resetStatusInfo() {
|
||||
mInstructionText = null;
|
||||
mShowingBatteryInfo = mUpdateMonitor.shouldShowBatteryInfo();
|
||||
mPluggedIn = mUpdateMonitor.isDevicePluggedIn();
|
||||
mBatteryLevel = mUpdateMonitor.getBatteryLevel();
|
||||
updateStatusLines(true);
|
||||
}
|
||||
|
||||
@@ -379,14 +375,11 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
if (mShowingBatteryInfo) {
|
||||
// Battery status
|
||||
if (mPluggedIn) {
|
||||
// Charging or charged
|
||||
if (mUpdateMonitor.isDeviceCharged()) {
|
||||
string = getContext().getString(R.string.lockscreen_charged);
|
||||
} else {
|
||||
string = getContext().getString(R.string.lockscreen_plugged_in, mBatteryLevel);
|
||||
}
|
||||
// Charging, charged or waiting to charge.
|
||||
string = getContext().getString(mBatteryCharged ? R.string.lockscreen_charged
|
||||
:R.string.lockscreen_plugged_in, mBatteryLevel);
|
||||
icon.value = CHARGING_ICON;
|
||||
} else if (mBatteryLevel < KeyguardUpdateMonitor.LOW_BATTERY_THRESHOLD) {
|
||||
} else if (mBatteryIsLow) {
|
||||
// Battery is low
|
||||
string = getContext().getString(R.string.lockscreen_low_battery);
|
||||
icon.value = BATTERY_LOW_ICON;
|
||||
@@ -406,14 +399,11 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
} else if (mShowingBatteryInfo) {
|
||||
// Battery status
|
||||
if (mPluggedIn) {
|
||||
// Charging or charged
|
||||
if (mUpdateMonitor.isDeviceCharged()) {
|
||||
string = getContext().getString(R.string.lockscreen_charged);
|
||||
} else {
|
||||
string = getContext().getString(R.string.lockscreen_plugged_in, mBatteryLevel);
|
||||
}
|
||||
// Charging, charged or waiting to charge.
|
||||
string = getContext().getString(mBatteryCharged ? R.string.lockscreen_charged
|
||||
:R.string.lockscreen_plugged_in, mBatteryLevel);
|
||||
icon.value = CHARGING_ICON;
|
||||
} else if (mBatteryLevel < KeyguardUpdateMonitor.LOW_BATTERY_THRESHOLD) {
|
||||
} else if (mBatteryIsLow) {
|
||||
// Battery is low
|
||||
string = getContext().getString(R.string.lockscreen_low_battery);
|
||||
icon.value = BATTERY_LOW_ICON;
|
||||
@@ -629,14 +619,15 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
private InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
|
||||
private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn,
|
||||
int batteryLevel) {
|
||||
mShowingBatteryInfo = showBatteryInfo;
|
||||
mPluggedIn = pluggedIn;
|
||||
mBatteryLevel = batteryLevel;
|
||||
public void onRefreshBatteryInfo(BatteryStatus status) {
|
||||
mShowingBatteryInfo = status.isPluggedIn() || status.isBatteryLow();
|
||||
mPluggedIn = status.isPluggedIn();
|
||||
mBatteryLevel = status.level;
|
||||
mBatteryCharged = status.isCharged();
|
||||
mBatteryIsLow = status.isBatteryLow();
|
||||
final MutableInt tmpIcon = new MutableInt(0);
|
||||
update(BATTERY_INFO, getAltTextMessage(tmpIcon));
|
||||
}
|
||||
@@ -659,10 +650,7 @@ class KeyguardStatusViewManager implements OnClickListener {
|
||||
updateEmergencyCallButtonState(phoneState);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private SimStateCallback mSimStateCallback = new SimStateCallback() {
|
||||
|
||||
@Override
|
||||
public void onSimStateChanged(IccCardConstants.State simState) {
|
||||
updateCarrierStateWithSimStatus(simState);
|
||||
}
|
||||
|
||||
@@ -57,37 +57,13 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class KeyguardUpdateMonitor {
|
||||
|
||||
static private final String TAG = "KeyguardUpdateMonitor";
|
||||
static private final boolean DEBUG = false;
|
||||
|
||||
/* package */ static final int LOW_BATTERY_THRESHOLD = 20;
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private IccCardConstants.State mSimState = IccCardConstants.State.READY;
|
||||
|
||||
private boolean mDeviceProvisioned;
|
||||
|
||||
private BatteryStatus mBatteryStatus;
|
||||
|
||||
private CharSequence mTelephonyPlmn;
|
||||
private CharSequence mTelephonySpn;
|
||||
|
||||
private int mFailedAttempts = 0;
|
||||
private int mFailedBiometricUnlockAttempts = 0;
|
||||
private static final String TAG = "KeyguardUpdateMonitor";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean DEBUG_SIM_STATES = DEBUG || false;
|
||||
private static final int FAILED_BIOMETRIC_UNLOCK_ATTEMPTS_BEFORE_BACKUP = 3;
|
||||
private static final int LOW_BATTERY_THRESHOLD = 20;
|
||||
|
||||
private boolean mClockVisible;
|
||||
|
||||
private Handler mHandler;
|
||||
|
||||
private ArrayList<InfoCallback> mInfoCallbacks = Lists.newArrayList();
|
||||
private ArrayList<SimStateCallback> mSimStateCallbacks = Lists.newArrayList();
|
||||
private ContentObserver mContentObserver;
|
||||
private int mRingMode;
|
||||
private int mPhoneState;
|
||||
|
||||
// messages for the handler
|
||||
// Callback messages
|
||||
private static final int MSG_TIME_UPDATE = 301;
|
||||
private static final int MSG_BATTERY_UPDATE = 302;
|
||||
private static final int MSG_CARRIER_INFO_UPDATE = 303;
|
||||
@@ -97,9 +73,118 @@ public class KeyguardUpdateMonitor {
|
||||
private static final int MSG_CLOCK_VISIBILITY_CHANGED = 307;
|
||||
private static final int MSG_DEVICE_PROVISIONED = 308;
|
||||
protected static final int MSG_DPM_STATE_CHANGED = 309;
|
||||
protected static final int MSG_USER_CHANGED = 310;
|
||||
protected static final int MSG_USER_SWITCHED = 310;
|
||||
protected static final int MSG_USER_REMOVED = 311;
|
||||
|
||||
protected static final boolean DEBUG_SIM_STATES = DEBUG || false;
|
||||
private final Context mContext;
|
||||
|
||||
// Telephony state
|
||||
private IccCardConstants.State mSimState = IccCardConstants.State.READY;
|
||||
private CharSequence mTelephonyPlmn;
|
||||
private CharSequence mTelephonySpn;
|
||||
private int mRingMode;
|
||||
private int mPhoneState;
|
||||
|
||||
private boolean mDeviceProvisioned;
|
||||
|
||||
private BatteryStatus mBatteryStatus;
|
||||
|
||||
private int mFailedAttempts = 0;
|
||||
private int mFailedBiometricUnlockAttempts = 0;
|
||||
|
||||
private boolean mClockVisible;
|
||||
|
||||
private ArrayList<KeyguardUpdateMonitorCallback> mCallbacks = Lists.newArrayList();
|
||||
private ContentObserver mContentObserver;
|
||||
|
||||
private final Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_TIME_UPDATE:
|
||||
handleTimeUpdate();
|
||||
break;
|
||||
case MSG_BATTERY_UPDATE:
|
||||
handleBatteryUpdate((BatteryStatus) msg.obj);
|
||||
break;
|
||||
case MSG_CARRIER_INFO_UPDATE:
|
||||
handleCarrierInfoUpdate();
|
||||
break;
|
||||
case MSG_SIM_STATE_CHANGE:
|
||||
handleSimStateChange((SimArgs) msg.obj);
|
||||
break;
|
||||
case MSG_RINGER_MODE_CHANGED:
|
||||
handleRingerModeChange(msg.arg1);
|
||||
break;
|
||||
case MSG_PHONE_STATE_CHANGED:
|
||||
handlePhoneStateChanged((String)msg.obj);
|
||||
break;
|
||||
case MSG_CLOCK_VISIBILITY_CHANGED:
|
||||
handleClockVisibilityChanged();
|
||||
break;
|
||||
case MSG_DEVICE_PROVISIONED:
|
||||
handleDeviceProvisioned();
|
||||
break;
|
||||
case MSG_DPM_STATE_CHANGED:
|
||||
handleDevicePolicyManagerStateChanged();
|
||||
break;
|
||||
case MSG_USER_SWITCHED:
|
||||
handleUserSwitched(msg.arg1);
|
||||
break;
|
||||
case MSG_USER_REMOVED:
|
||||
handleUserRemoved(msg.arg1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (DEBUG) Log.d(TAG, "received broadcast " + action);
|
||||
|
||||
if (Intent.ACTION_TIME_TICK.equals(action)
|
||||
|| Intent.ACTION_TIME_CHANGED.equals(action)
|
||||
|| Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_TIME_UPDATE));
|
||||
} else if (TelephonyIntents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
|
||||
mTelephonyPlmn = getTelephonyPlmnFrom(intent);
|
||||
mTelephonySpn = getTelephonySpnFrom(intent);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_CARRIER_INFO_UPDATE));
|
||||
} else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
|
||||
final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
|
||||
final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0);
|
||||
final int level = intent.getIntExtra(EXTRA_LEVEL, 0);
|
||||
final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
|
||||
final Message msg = mHandler.obtainMessage(
|
||||
MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health));
|
||||
mHandler.sendMessage(msg);
|
||||
} else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
|
||||
if (DEBUG_SIM_STATES) {
|
||||
Log.v(TAG, "action " + action + " state" +
|
||||
intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE));
|
||||
}
|
||||
mHandler.sendMessage(mHandler.obtainMessage(
|
||||
MSG_SIM_STATE_CHANGE, SimArgs.fromIntent(intent)));
|
||||
} else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED,
|
||||
intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0));
|
||||
} else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
|
||||
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state));
|
||||
} else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
|
||||
.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_DPM_STATE_CHANGED));
|
||||
} else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED,
|
||||
intent.getIntExtra(Intent.EXTRA_USERID, 0), 0));
|
||||
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_REMOVED,
|
||||
intent.getIntExtra(Intent.EXTRA_USERID, 0), 0));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* When we receive a
|
||||
@@ -156,7 +241,7 @@ public class KeyguardUpdateMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
private static class BatteryStatus {
|
||||
/* package */ static class BatteryStatus {
|
||||
public final int status;
|
||||
public final int level;
|
||||
public final int plugged;
|
||||
@@ -168,91 +253,53 @@ public class KeyguardUpdateMonitor {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the device is plugged in (USB or power).
|
||||
* @return true if the device is plugged in.
|
||||
*/
|
||||
boolean isPluggedIn() {
|
||||
return plugged == BatteryManager.BATTERY_PLUGGED_AC
|
||||
|| plugged == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the device is charged. Note that some devices never return 100% for
|
||||
* battery level, so this allows either battery level or status to determine if the
|
||||
* battery is charged.
|
||||
* @return true if the device is charged
|
||||
*/
|
||||
public boolean isCharged() {
|
||||
return status == BATTERY_STATUS_FULL || level >= 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether battery is low and needs to be charged.
|
||||
* @return true if battery is low
|
||||
*/
|
||||
public boolean isBatteryLow() {
|
||||
return level < LOW_BATTERY_THRESHOLD;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public KeyguardUpdateMonitor(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_TIME_UPDATE:
|
||||
handleTimeUpdate();
|
||||
break;
|
||||
case MSG_BATTERY_UPDATE:
|
||||
handleBatteryUpdate((BatteryStatus) msg.obj);
|
||||
break;
|
||||
case MSG_CARRIER_INFO_UPDATE:
|
||||
handleCarrierInfoUpdate();
|
||||
break;
|
||||
case MSG_SIM_STATE_CHANGE:
|
||||
handleSimStateChange((SimArgs) msg.obj);
|
||||
break;
|
||||
case MSG_RINGER_MODE_CHANGED:
|
||||
handleRingerModeChange(msg.arg1);
|
||||
break;
|
||||
case MSG_PHONE_STATE_CHANGED:
|
||||
handlePhoneStateChanged((String)msg.obj);
|
||||
break;
|
||||
case MSG_CLOCK_VISIBILITY_CHANGED:
|
||||
handleClockVisibilityChanged();
|
||||
break;
|
||||
case MSG_DEVICE_PROVISIONED:
|
||||
handleDeviceProvisioned();
|
||||
break;
|
||||
case MSG_DPM_STATE_CHANGED:
|
||||
handleDevicePolicyManagerStateChanged();
|
||||
break;
|
||||
case MSG_USER_CHANGED:
|
||||
handleUserChanged(msg.arg1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mDeviceProvisioned = Settings.Secure.getInt(
|
||||
mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
|
||||
|
||||
// Since device can't be un-provisioned, we only need to register a content observer
|
||||
// to update mDeviceProvisioned when we are...
|
||||
if (!mDeviceProvisioned) {
|
||||
mContentObserver = new ContentObserver(mHandler) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
mDeviceProvisioned = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
|
||||
if (mDeviceProvisioned) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED));
|
||||
}
|
||||
if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned);
|
||||
}
|
||||
};
|
||||
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.DEVICE_PROVISIONED),
|
||||
false, mContentObserver);
|
||||
|
||||
// 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.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
|
||||
if (provisioned != mDeviceProvisioned) {
|
||||
mDeviceProvisioned = provisioned;
|
||||
if (mDeviceProvisioned) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED));
|
||||
}
|
||||
}
|
||||
watchForDeviceProvisioning();
|
||||
}
|
||||
|
||||
// take a guess to start
|
||||
mSimState = IccCardConstants.State.READY;
|
||||
// Take a guess at initial SIM state, battery status and PLMN until we get an update
|
||||
mSimState = IccCardConstants.State.NOT_READY;
|
||||
mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0);
|
||||
|
||||
mTelephonyPlmn = getDefaultPlmn();
|
||||
|
||||
// setup receiver
|
||||
// Watch for interesting updates
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_TIME_TICK);
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
@@ -265,67 +312,72 @@ public class KeyguardUpdateMonitor {
|
||||
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
filter.addAction(Intent.ACTION_USER_REMOVED);
|
||||
context.registerReceiver(new BroadcastReceiver() {
|
||||
context.registerReceiver(mBroadcastReceiver, filter);
|
||||
}
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (DEBUG) Log.d(TAG, "received broadcast " + action);
|
||||
|
||||
if (Intent.ACTION_TIME_TICK.equals(action)
|
||||
|| Intent.ACTION_TIME_CHANGED.equals(action)
|
||||
|| Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_TIME_UPDATE));
|
||||
} else if (TelephonyIntents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
|
||||
mTelephonyPlmn = getTelephonyPlmnFrom(intent);
|
||||
mTelephonySpn = getTelephonySpnFrom(intent);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_CARRIER_INFO_UPDATE));
|
||||
} else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
|
||||
final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
|
||||
final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0);
|
||||
final int level = intent.getIntExtra(EXTRA_LEVEL, 0);
|
||||
final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
|
||||
final Message msg = mHandler.obtainMessage(
|
||||
MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health));
|
||||
mHandler.sendMessage(msg);
|
||||
} else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
|
||||
if (DEBUG_SIM_STATES) {
|
||||
Log.v(TAG, "action " + action + " state" +
|
||||
intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE));
|
||||
}
|
||||
mHandler.sendMessage(mHandler.obtainMessage(
|
||||
MSG_SIM_STATE_CHANGE, SimArgs.fromIntent(intent)));
|
||||
} else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED,
|
||||
intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0));
|
||||
} else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
|
||||
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state));
|
||||
} else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
|
||||
.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_DPM_STATE_CHANGED));
|
||||
} else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_CHANGED,
|
||||
intent.getIntExtra(Intent.EXTRA_USERID, 0), 0));
|
||||
private void watchForDeviceProvisioning() {
|
||||
mContentObserver = new ContentObserver(mHandler) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
mDeviceProvisioned = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
|
||||
if (mDeviceProvisioned) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED));
|
||||
}
|
||||
if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned);
|
||||
}
|
||||
}, filter);
|
||||
};
|
||||
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.DEVICE_PROVISIONED),
|
||||
false, mContentObserver);
|
||||
|
||||
// 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.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
|
||||
if (provisioned != mDeviceProvisioned) {
|
||||
mDeviceProvisioned = provisioned;
|
||||
if (mDeviceProvisioned) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link #MSG_DPM_STATE_CHANGED}
|
||||
*/
|
||||
protected void handleDevicePolicyManagerStateChanged() {
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
mInfoCallbacks.get(i).onDevicePolicyManagerStateChanged();
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onDevicePolicyManagerStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleUserChanged(int userId) {
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
mInfoCallbacks.get(i).onUserChanged(userId);
|
||||
/**
|
||||
* Handle {@link #MSG_USER_SWITCHED}
|
||||
*/
|
||||
protected void handleUserSwitched(int userId) {
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onUserSwitched(userId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link #MSG_USER_SWITCHED}
|
||||
*/
|
||||
protected void handleUserRemoved(int userId) {
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onUserRemoved(userId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link #MSG_DEVICE_PROVISIONED}
|
||||
*/
|
||||
protected void handleDeviceProvisioned() {
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
mInfoCallbacks.get(i).onDeviceProvisioned();
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onDeviceProvisioned();
|
||||
}
|
||||
if (mContentObserver != null) {
|
||||
// We don't need the observer anymore...
|
||||
@@ -334,6 +386,9 @@ public class KeyguardUpdateMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link #MSG_PHONE_STATE_CHANGED}
|
||||
*/
|
||||
protected void handlePhoneStateChanged(String newState) {
|
||||
if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")");
|
||||
if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) {
|
||||
@@ -343,16 +398,19 @@ public class KeyguardUpdateMonitor {
|
||||
} else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) {
|
||||
mPhoneState = TelephonyManager.CALL_STATE_RINGING;
|
||||
}
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
mInfoCallbacks.get(i).onPhoneStateChanged(mPhoneState);
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onPhoneStateChanged(mPhoneState);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link #MSG_RINGER_MODE_CHANGED}
|
||||
*/
|
||||
protected void handleRingerModeChange(int mode) {
|
||||
if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")");
|
||||
mRingMode = mode;
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
mInfoCallbacks.get(i).onRingerModeChanged(mode);
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onRingerModeChanged(mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,24 +419,21 @@ public class KeyguardUpdateMonitor {
|
||||
*/
|
||||
private void handleTimeUpdate() {
|
||||
if (DEBUG) Log.d(TAG, "handleTimeUpdate");
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
mInfoCallbacks.get(i).onTimeChanged();
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onTimeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link #MSG_BATTERY_UPDATE}
|
||||
*/
|
||||
private void handleBatteryUpdate(BatteryStatus batteryStatus) {
|
||||
private void handleBatteryUpdate(BatteryStatus status) {
|
||||
if (DEBUG) Log.d(TAG, "handleBatteryUpdate");
|
||||
final boolean batteryUpdateInteresting =
|
||||
isBatteryUpdateInteresting(mBatteryStatus, batteryStatus);
|
||||
mBatteryStatus = batteryStatus;
|
||||
final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status);
|
||||
mBatteryStatus = status;
|
||||
if (batteryUpdateInteresting) {
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
// TODO: pass BatteryStatus object to onRefreshBatteryInfo() instead...
|
||||
mInfoCallbacks.get(i).onRefreshBatteryInfo(
|
||||
shouldShowBatteryInfo(),isPluggedIn(batteryStatus), batteryStatus.level);
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onRefreshBatteryInfo(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -390,8 +445,8 @@ public class KeyguardUpdateMonitor {
|
||||
if (DEBUG) Log.d(TAG, "handleCarrierInfoUpdate: plmn = " + mTelephonyPlmn
|
||||
+ ", spn = " + mTelephonySpn);
|
||||
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
mInfoCallbacks.get(i).onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,31 +463,25 @@ public class KeyguardUpdateMonitor {
|
||||
|
||||
if (state != IccCardConstants.State.UNKNOWN && state != mSimState) {
|
||||
mSimState = state;
|
||||
for (int i = 0; i < mSimStateCallbacks.size(); i++) {
|
||||
mSimStateCallbacks.get(i).onSimStateChanged(state);
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onSimStateChanged(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link #MSG_CLOCK_VISIBILITY_CHANGED}
|
||||
*/
|
||||
private void handleClockVisibilityChanged() {
|
||||
if (DEBUG) Log.d(TAG, "handleClockVisibilityChanged()");
|
||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||
mInfoCallbacks.get(i).onClockVisibilityChanged();
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
mCallbacks.get(i).onClockVisibilityChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pluggedIn state from {@link android.os.BatteryManager#EXTRA_PLUGGED}
|
||||
* @return Whether the device is considered "plugged in."
|
||||
*/
|
||||
private static boolean isPluggedIn(BatteryStatus status) {
|
||||
return status.plugged == BatteryManager.BATTERY_PLUGGED_AC
|
||||
|| status.plugged == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
}
|
||||
|
||||
private static boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) {
|
||||
final boolean nowPluggedIn = isPluggedIn(current);
|
||||
final boolean wasPluggedIn = isPluggedIn(old);
|
||||
final boolean nowPluggedIn = current.isPluggedIn();
|
||||
final boolean wasPluggedIn = old.isPluggedIn();
|
||||
final boolean stateChangedWhilePluggedIn =
|
||||
wasPluggedIn == true && nowPluggedIn == true
|
||||
&& (old.status != current.status);
|
||||
@@ -448,16 +497,12 @@ public class KeyguardUpdateMonitor {
|
||||
}
|
||||
|
||||
// change where battery needs charging
|
||||
if (!nowPluggedIn && isBatteryLow(current) && current.level != old.level) {
|
||||
if (!nowPluggedIn && current.isBatteryLow() && current.level != old.level) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isBatteryLow(BatteryStatus status) {
|
||||
return status.level < LOW_BATTERY_THRESHOLD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param intent The intent with action {@link TelephonyIntents#SPN_STRINGS_UPDATED_ACTION}
|
||||
* @return The string to use for the plmn, or null if it should not be shown.
|
||||
@@ -465,11 +510,7 @@ public class KeyguardUpdateMonitor {
|
||||
private CharSequence getTelephonyPlmnFrom(Intent intent) {
|
||||
if (intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) {
|
||||
final String plmn = intent.getStringExtra(TelephonyIntents.EXTRA_PLMN);
|
||||
if (plmn != null) {
|
||||
return plmn;
|
||||
} else {
|
||||
return getDefaultPlmn();
|
||||
}
|
||||
return (plmn != null) ? plmn : getDefaultPlmn();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -478,8 +519,7 @@ public class KeyguardUpdateMonitor {
|
||||
* @return The default plmn (no service)
|
||||
*/
|
||||
private CharSequence getDefaultPlmn() {
|
||||
return mContext.getResources().getText(
|
||||
R.string.lockscreen_carrier_default);
|
||||
return mContext.getResources().getText(R.string.lockscreen_carrier_default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -497,104 +537,12 @@ public class KeyguardUpdateMonitor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given observer from being registered from any of the kinds
|
||||
* of callbacks.
|
||||
* @param observer The observer to remove (an instance of {@link ConfigurationChangeCallback},
|
||||
* {@link InfoCallback} or {@link SimStateCallback}
|
||||
* Remove the given observer's callback.
|
||||
*
|
||||
* @param observer The observer to remove
|
||||
*/
|
||||
public void removeCallback(Object observer) {
|
||||
mInfoCallbacks.remove(observer);
|
||||
mSimStateCallbacks.remove(observer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for general information relevant to lock screen.
|
||||
*/
|
||||
interface InfoCallback {
|
||||
void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel);
|
||||
void onTimeChanged();
|
||||
|
||||
/**
|
||||
* @param plmn The operator name of the registered network. May be null if it shouldn't
|
||||
* be displayed.
|
||||
* @param spn The service provider name. May be null if it shouldn't be displayed.
|
||||
*/
|
||||
void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn);
|
||||
|
||||
/**
|
||||
* Called when the ringer mode changes.
|
||||
* @param state the current ringer state, as defined in
|
||||
* {@link AudioManager#RINGER_MODE_CHANGED_ACTION}
|
||||
*/
|
||||
void onRingerModeChanged(int state);
|
||||
|
||||
/**
|
||||
* Called when the phone state changes. String will be one of:
|
||||
* {@link TelephonyManager#EXTRA_STATE_IDLE}
|
||||
* {@link TelephonyManager@EXTRA_STATE_RINGING}
|
||||
* {@link TelephonyManager#EXTRA_STATE_OFFHOOK
|
||||
*/
|
||||
void onPhoneStateChanged(int phoneState);
|
||||
|
||||
/**
|
||||
* Called when visibility of lockscreen clock changes, such as when
|
||||
* obscured by a widget.
|
||||
*/
|
||||
void onClockVisibilityChanged();
|
||||
|
||||
/**
|
||||
* Called when the device becomes provisioned
|
||||
*/
|
||||
void onDeviceProvisioned();
|
||||
|
||||
/**
|
||||
* Called when the device policy changes.
|
||||
* See {@link DevicePolicyManager#ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED}
|
||||
*/
|
||||
void onDevicePolicyManagerStateChanged();
|
||||
|
||||
/**
|
||||
* Called when the user changes.
|
||||
*/
|
||||
void onUserChanged(int userId);
|
||||
}
|
||||
|
||||
// Simple class that allows methods to easily be overwritten
|
||||
public static class InfoCallbackImpl implements InfoCallback {
|
||||
public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn,
|
||||
int batteryLevel) {
|
||||
}
|
||||
|
||||
public void onTimeChanged() {
|
||||
}
|
||||
|
||||
public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) {
|
||||
}
|
||||
|
||||
public void onRingerModeChanged(int state) {
|
||||
}
|
||||
|
||||
public void onPhoneStateChanged(int phoneState) {
|
||||
}
|
||||
|
||||
public void onClockVisibilityChanged() {
|
||||
}
|
||||
|
||||
public void onDeviceProvisioned() {
|
||||
}
|
||||
|
||||
public void onDevicePolicyManagerStateChanged() {
|
||||
}
|
||||
|
||||
public void onUserChanged(int userId) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to notify of sim state change.
|
||||
*/
|
||||
interface SimStateCallback {
|
||||
void onSimStateChanged(IccCardConstants.State simState);
|
||||
mCallbacks.remove(observer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,35 +550,20 @@ public class KeyguardUpdateMonitor {
|
||||
* (see {@link InfoCallback}.
|
||||
* @param callback The callback.
|
||||
*/
|
||||
public void registerInfoCallback(InfoCallback callback) {
|
||||
if (!mInfoCallbacks.contains(callback)) {
|
||||
mInfoCallbacks.add(callback);
|
||||
public void registerCallback(KeyguardUpdateMonitorCallback callback) {
|
||||
if (!mCallbacks.contains(callback)) {
|
||||
mCallbacks.add(callback);
|
||||
// Notify listener of the current state
|
||||
callback.onRefreshBatteryInfo(shouldShowBatteryInfo(),isPluggedIn(mBatteryStatus),
|
||||
mBatteryStatus.level);
|
||||
callback.onRefreshBatteryInfo(mBatteryStatus);
|
||||
callback.onTimeChanged();
|
||||
callback.onRingerModeChanged(mRingMode);
|
||||
callback.onPhoneStateChanged(mPhoneState);
|
||||
callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
|
||||
callback.onClockVisibilityChanged();
|
||||
} else {
|
||||
if (DEBUG) Log.e(TAG, "Object tried to add another INFO callback",
|
||||
new Exception("Whoops"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register to be notified of sim state changes.
|
||||
* @param callback The callback.
|
||||
*/
|
||||
public void registerSimStateCallback(SimStateCallback callback) {
|
||||
if (!mSimStateCallbacks.contains(callback)) {
|
||||
mSimStateCallbacks.add(callback);
|
||||
// Notify listener of the current state
|
||||
callback.onSimStateChanged(mSimState);
|
||||
} else {
|
||||
if (DEBUG) Log.e(TAG, "Object tried to add another SIM callback",
|
||||
new Exception("Whoops"));
|
||||
if (DEBUG) Log.e(TAG, "Object tried to add another callback",
|
||||
new Exception("Called by"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -655,23 +588,6 @@ public class KeyguardUpdateMonitor {
|
||||
handleSimStateChange(new SimArgs(IccCardConstants.State.READY));
|
||||
}
|
||||
|
||||
public boolean isDevicePluggedIn() {
|
||||
return isPluggedIn(mBatteryStatus);
|
||||
}
|
||||
|
||||
public boolean isDeviceCharged() {
|
||||
return mBatteryStatus.status == BATTERY_STATUS_FULL
|
||||
|| mBatteryStatus.level >= 100; // in case particular device doesn't flag it
|
||||
}
|
||||
|
||||
public int getBatteryLevel() {
|
||||
return mBatteryStatus.level;
|
||||
}
|
||||
|
||||
public boolean shouldShowBatteryInfo() {
|
||||
return isPluggedIn(mBatteryStatus) || isBatteryLow(mBatteryStatus);
|
||||
}
|
||||
|
||||
public CharSequence getTelephonyPlmn() {
|
||||
return mTelephonyPlmn;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.internal.policy.impl;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.BatteryStatus;
|
||||
import com.android.internal.telephony.IccCardConstants;
|
||||
|
||||
/**
|
||||
* Callback for general information relevant to lock screen.
|
||||
*/
|
||||
class KeyguardUpdateMonitorCallback {
|
||||
/**
|
||||
* Called when the battery status changes, e.g. when plugged in or unplugged, charge
|
||||
* level, etc. changes.
|
||||
*
|
||||
* @param status current battery status
|
||||
*/
|
||||
void onRefreshBatteryInfo(BatteryStatus status) { }
|
||||
|
||||
/**
|
||||
* Called once per minute or when the time changes.
|
||||
*/
|
||||
void onTimeChanged() { }
|
||||
|
||||
/**
|
||||
* Called when the carrier PLMN or SPN changes.
|
||||
*
|
||||
* @param plmn The operator name of the registered network. May be null if it shouldn't
|
||||
* be displayed.
|
||||
* @param spn The service provider name. May be null if it shouldn't be displayed.
|
||||
*/
|
||||
void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) { }
|
||||
|
||||
/**
|
||||
* Called when the ringer mode changes.
|
||||
* @param state the current ringer state, as defined in
|
||||
* {@link AudioManager#RINGER_MODE_CHANGED_ACTION}
|
||||
*/
|
||||
void onRingerModeChanged(int state) { }
|
||||
|
||||
/**
|
||||
* Called when the phone state changes. String will be one of:
|
||||
* {@link TelephonyManager#EXTRA_STATE_IDLE}
|
||||
* {@link TelephonyManager@EXTRA_STATE_RINGING}
|
||||
* {@link TelephonyManager#EXTRA_STATE_OFFHOOK
|
||||
*/
|
||||
void onPhoneStateChanged(int phoneState) { }
|
||||
|
||||
/**
|
||||
* Called when visibility of lockscreen clock changes, such as when
|
||||
* obscured by a widget.
|
||||
*/
|
||||
void onClockVisibilityChanged() { }
|
||||
|
||||
/**
|
||||
* Called when the device becomes provisioned
|
||||
*/
|
||||
void onDeviceProvisioned() { }
|
||||
|
||||
/**
|
||||
* Called when the device policy changes.
|
||||
* See {@link DevicePolicyManager#ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED}
|
||||
*/
|
||||
void onDevicePolicyManagerStateChanged() { }
|
||||
|
||||
/**
|
||||
* Called when the user changes.
|
||||
*/
|
||||
void onUserSwitched(int userId) { }
|
||||
|
||||
/**
|
||||
* Called when the SIM state changes.
|
||||
* @param simState
|
||||
*/
|
||||
void onSimStateChanged(IccCardConstants.State simState) { }
|
||||
|
||||
/**
|
||||
* Called when a user is removed.
|
||||
*/
|
||||
void onUserRemoved(int userId) { }
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package com.android.internal.policy.impl;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.InfoCallbackImpl;
|
||||
import com.android.internal.telephony.IccCardConstants;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
|
||||
@@ -90,8 +89,7 @@ import android.view.WindowManagerPolicy;
|
||||
* directly to the keyguard UI is posted to a {@link Handler} to ensure it is taken on the UI
|
||||
* thread of the keyguard.
|
||||
*/
|
||||
public class KeyguardViewMediator implements KeyguardViewCallback,
|
||||
KeyguardUpdateMonitor.SimStateCallback {
|
||||
public class KeyguardViewMediator implements KeyguardViewCallback {
|
||||
private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
|
||||
private final static boolean DEBUG = false;
|
||||
private final static boolean DBG_WAKE = false;
|
||||
@@ -257,7 +255,38 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
|
||||
*/
|
||||
private final float mLockSoundVolume;
|
||||
|
||||
InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
|
||||
KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void onUserSwitched(int userId) {
|
||||
mLockPatternUtils.setCurrentUser(userId);
|
||||
synchronized (KeyguardViewMediator.this) {
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserRemoved(int userId) {
|
||||
mLockPatternUtils.removeUser(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onPhoneStateChanged(int phoneState) {
|
||||
synchronized (KeyguardViewMediator.this) {
|
||||
if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
|
||||
&& !mScreenOn // screen off
|
||||
&& mExternallyEnabled) { // not disabled by any app
|
||||
|
||||
// note: this is a way to gracefully reenable the keyguard when the call
|
||||
// ends and the screen is off without always reenabling the keyguard
|
||||
// each time the screen turns off while in call (and having an occasional ugly
|
||||
// flicker while turning back on the screen and disabling the keyguard again).
|
||||
if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
|
||||
+ "keyguard is showing");
|
||||
doKeyguardLocked();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onClockVisibilityChanged() {
|
||||
@@ -269,40 +298,86 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
|
||||
mContext.sendBroadcast(mUserPresentIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSimStateChanged(IccCardConstants.State simState) {
|
||||
if (DEBUG) Log.d(TAG, "onSimStateChanged: " + simState);
|
||||
|
||||
switch (simState) {
|
||||
case NOT_READY:
|
||||
case ABSENT:
|
||||
// only force lock screen in case of missing sim if user hasn't
|
||||
// gone through setup wizard
|
||||
synchronized (this) {
|
||||
if (!mUpdateMonitor.isDeviceProvisioned()) {
|
||||
if (!isShowing()) {
|
||||
if (DEBUG) Log.d(TAG, "ICC_ABSENT isn't showing,"
|
||||
+ " we need to show the keyguard since the "
|
||||
+ "device isn't provisioned yet.");
|
||||
doKeyguardLocked();
|
||||
} else {
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PIN_REQUIRED:
|
||||
case PUK_REQUIRED:
|
||||
synchronized (this) {
|
||||
if (!isShowing()) {
|
||||
if (DEBUG) Log.d(TAG, "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
|
||||
+ "showing; need to show keyguard so user can enter sim pin");
|
||||
doKeyguardLocked();
|
||||
} else {
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PERM_DISABLED:
|
||||
synchronized (this) {
|
||||
if (!isShowing()) {
|
||||
if (DEBUG) Log.d(TAG, "PERM_DISABLED and "
|
||||
+ "keygaurd isn't showing.");
|
||||
doKeyguardLocked();
|
||||
} else {
|
||||
if (DEBUG) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
|
||||
+ "show permanently disabled message in lockscreen.");
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case READY:
|
||||
synchronized (this) {
|
||||
if (isShowing()) {
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public KeyguardViewMediator(Context context, PhoneWindowManager callback,
|
||||
LocalPowerManager powerManager) {
|
||||
mContext = context;
|
||||
|
||||
mCallback = callback;
|
||||
mRealPowerManager = powerManager;
|
||||
mPM = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = mPM.newWakeLock(
|
||||
PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
|
||||
"keyguard");
|
||||
PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "keyguard");
|
||||
mWakeLock.setReferenceCounted(false);
|
||||
mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
|
||||
mShowKeyguardWakeLock.setReferenceCounted(false);
|
||||
|
||||
mWakeAndHandOff = mPM.newWakeLock(
|
||||
PowerManager.PARTIAL_WAKE_LOCK,
|
||||
"keyguardWakeAndHandOff");
|
||||
mWakeAndHandOff = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "keyguardWakeAndHandOff");
|
||||
mWakeAndHandOff.setReferenceCounted(false);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(DELAYED_KEYGUARD_ACTION);
|
||||
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
|
||||
context.registerReceiver(mBroadCastReceiver, filter);
|
||||
mAlarmManager = (AlarmManager) context
|
||||
.getSystemService(Context.ALARM_SERVICE);
|
||||
mCallback = callback;
|
||||
mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION));
|
||||
|
||||
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
|
||||
mUpdateMonitor = new KeyguardUpdateMonitor(context);
|
||||
|
||||
mUpdateMonitor.registerInfoCallback(mInfoCallback);
|
||||
|
||||
mUpdateMonitor.registerSimStateCallback(this);
|
||||
|
||||
mLockPatternUtils = new LockPatternUtils(mContext);
|
||||
mKeyguardViewProperties
|
||||
= new LockPatternKeyguardViewProperties(mLockPatternUtils, mUpdateMonitor);
|
||||
@@ -336,10 +411,6 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
|
||||
int lockSoundDefaultAttenuation = context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_lockSoundVolumeDb);
|
||||
mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
|
||||
IntentFilter userFilter = new IntentFilter();
|
||||
userFilter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
userFilter.addAction(Intent.ACTION_USER_REMOVED);
|
||||
mContext.registerReceiver(mUserChangeReceiver, userFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,6 +420,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
|
||||
synchronized (this) {
|
||||
if (DEBUG) Log.d(TAG, "onSystemReady");
|
||||
mSystemReady = true;
|
||||
mUpdateMonitor.registerCallback(mUpdateCallback);
|
||||
doKeyguardLocked();
|
||||
}
|
||||
}
|
||||
@@ -726,123 +798,21 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void onSimStateChanged(IccCardConstants.State simState) {
|
||||
if (DEBUG) Log.d(TAG, "onSimStateChanged: " + simState);
|
||||
|
||||
switch (simState) {
|
||||
case ABSENT:
|
||||
// only force lock screen in case of missing sim if user hasn't
|
||||
// gone through setup wizard
|
||||
synchronized (this) {
|
||||
if (!mUpdateMonitor.isDeviceProvisioned()) {
|
||||
if (!isShowing()) {
|
||||
if (DEBUG) Log.d(TAG, "ICC_ABSENT isn't showing,"
|
||||
+ " we need to show the keyguard since the "
|
||||
+ "device isn't provisioned yet.");
|
||||
doKeyguardLocked();
|
||||
} else {
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PIN_REQUIRED:
|
||||
case PUK_REQUIRED:
|
||||
synchronized (this) {
|
||||
if (!isShowing()) {
|
||||
if (DEBUG) Log.d(TAG, "INTENT_VALUE_ICC_LOCKED and keygaurd isn't showing, "
|
||||
+ "we need to show keyguard so user can enter their sim pin");
|
||||
doKeyguardLocked();
|
||||
} else {
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PERM_DISABLED:
|
||||
synchronized (this) {
|
||||
if (!isShowing()) {
|
||||
if (DEBUG) Log.d(TAG, "PERM_DISABLED and "
|
||||
+ "keygaurd isn't showing.");
|
||||
doKeyguardLocked();
|
||||
} else {
|
||||
if (DEBUG) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
|
||||
+ "show permanently disabled message in lockscreen.");
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case READY:
|
||||
synchronized (this) {
|
||||
if (isShowing()) {
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSecure() {
|
||||
return mKeyguardViewProperties.isSecure();
|
||||
}
|
||||
|
||||
private void onUserSwitched(int userId) {
|
||||
mLockPatternUtils.setCurrentUser(userId);
|
||||
synchronized (KeyguardViewMediator.this) {
|
||||
resetStateLocked();
|
||||
}
|
||||
}
|
||||
|
||||
private void onUserRemoved(int userId) {
|
||||
mLockPatternUtils.removeUser(userId);
|
||||
}
|
||||
|
||||
private BroadcastReceiver mUserChangeReceiver = new BroadcastReceiver() {
|
||||
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
|
||||
onUserSwitched(intent.getIntExtra(Intent.EXTRA_USERID, 0));
|
||||
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
|
||||
onUserRemoved(intent.getIntExtra(Intent.EXTRA_USERID, 0));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private BroadcastReceiver mBroadCastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (action.equals(DELAYED_KEYGUARD_ACTION)) {
|
||||
|
||||
int sequence = intent.getIntExtra("seq", 0);
|
||||
|
||||
if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
|
||||
final int sequence = intent.getIntExtra("seq", 0);
|
||||
if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
|
||||
+ sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
|
||||
|
||||
synchronized (KeyguardViewMediator.this) {
|
||||
if (mDelayedShowingSequence == sequence) {
|
||||
// Don't play lockscreen SFX if the screen went off due to
|
||||
// timeout.
|
||||
// Don't play lockscreen SFX if the screen went off due to timeout.
|
||||
mSuppressNextLockSound = true;
|
||||
|
||||
doKeyguardLocked();
|
||||
}
|
||||
}
|
||||
} else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
|
||||
mPhoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
|
||||
|
||||
synchronized (KeyguardViewMediator.this) {
|
||||
if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState) // call ending
|
||||
&& !mScreenOn // screen off
|
||||
&& mExternallyEnabled) { // not disabled by any app
|
||||
|
||||
// note: this is a way to gracefully reenable the keyguard when the call
|
||||
// ends and the screen is off without always reenabling the keyguard
|
||||
// each time the screen turns off while in call (and having an occasional ugly
|
||||
// flicker while turning back on the screen and disabling the keyguard again).
|
||||
if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
|
||||
+ "keyguard is showing");
|
||||
doKeyguardLocked();
|
||||
}
|
||||
}
|
||||
@@ -850,7 +820,6 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* When a key is received when the screen is off and the keyguard is showing,
|
||||
* we need to decide whether to actually turn on the screen, and if so, tell
|
||||
|
||||
@@ -17,13 +17,10 @@
|
||||
package com.android.internal.policy.impl;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.InfoCallback;
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.InfoCallbackImpl;
|
||||
import com.android.internal.policy.impl.LockPatternKeyguardView.UnlockMode;
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.BatteryStatus;
|
||||
import com.android.internal.telephony.IccCardConstants;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.internal.widget.LockScreenWidgetCallback;
|
||||
import com.android.internal.widget.LockScreenWidgetInterface;
|
||||
import com.android.internal.widget.TransportControlView;
|
||||
|
||||
import android.accounts.Account;
|
||||
@@ -40,10 +37,8 @@ import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
@@ -449,9 +444,8 @@ public class LockPatternKeyguardView extends KeyguardViewBase {
|
||||
mWindowController = controller;
|
||||
mSuppressBiometricUnlock = sIsFirstAppearanceAfterBoot;
|
||||
sIsFirstAppearanceAfterBoot = false;
|
||||
mPluggedIn = mUpdateMonitor.isDevicePluggedIn();
|
||||
mScreenOn = ((PowerManager)context.getSystemService(Context.POWER_SERVICE)).isScreenOn();
|
||||
mUpdateMonitor.registerInfoCallback(mInfoCallback);
|
||||
mUpdateMonitor.registerCallback(mInfoCallback);
|
||||
|
||||
/**
|
||||
* We'll get key events the current screen doesn't use. see
|
||||
@@ -692,17 +686,17 @@ public class LockPatternKeyguardView extends KeyguardViewBase {
|
||||
post(mRecreateRunnable);
|
||||
}
|
||||
|
||||
InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
|
||||
KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn,
|
||||
int batteryLevel) {
|
||||
public void onRefreshBatteryInfo(BatteryStatus status) {
|
||||
// When someone plugs in or unplugs the device, we hide the biometric sensor area and
|
||||
// suppress its startup for the next onScreenTurnedOn(). Since plugging/unplugging
|
||||
// causes the screen to turn on, the biometric unlock would start if it wasn't
|
||||
// suppressed.
|
||||
//
|
||||
// However, if the biometric unlock is already running, we do not want to interrupt it.
|
||||
final boolean pluggedIn = status.isPluggedIn();
|
||||
if (mBiometricUnlock != null && mPluggedIn != pluggedIn
|
||||
&& !mBiometricUnlock.isRunning()) {
|
||||
mBiometricUnlock.stop();
|
||||
@@ -732,7 +726,7 @@ public class LockPatternKeyguardView extends KeyguardViewBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserChanged(int userId) {
|
||||
public void onUserSwitched(int userId) {
|
||||
if (mBiometricUnlock != null) {
|
||||
mBiometricUnlock.stop();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package com.android.internal.policy.impl;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.InfoCallbackImpl;
|
||||
import com.android.internal.policy.impl.KeyguardUpdateMonitor.SimStateCallback;
|
||||
import com.android.internal.telephony.IccCardConstants;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.internal.widget.SlidingTab;
|
||||
@@ -86,7 +84,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
|
||||
// Is there a vibrator
|
||||
private final boolean mHasVibrator;
|
||||
|
||||
InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
|
||||
KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void onRingerModeChanged(int state) {
|
||||
@@ -102,9 +100,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
|
||||
updateTargets();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SimStateCallback mSimStateCallback = new SimStateCallback() {
|
||||
@Override
|
||||
public void onSimStateChanged(IccCardConstants.State simState) {
|
||||
updateTargets();
|
||||
}
|
||||
@@ -582,7 +578,6 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
|
||||
/** {@inheritDoc} */
|
||||
public void onPause() {
|
||||
mUpdateMonitor.removeCallback(mInfoCallback);
|
||||
mUpdateMonitor.removeCallback(mSimStateCallback);
|
||||
mStatusViewManager.onPause();
|
||||
mUnlockWidgetMethods.reset(false);
|
||||
}
|
||||
@@ -597,8 +592,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
|
||||
public void onResume() {
|
||||
// We don't want to show the camera target if SIM state prevents us from
|
||||
// launching the camera. So watch for SIM changes...
|
||||
mUpdateMonitor.registerSimStateCallback(mSimStateCallback);
|
||||
mUpdateMonitor.registerInfoCallback(mInfoCallback);
|
||||
mUpdateMonitor.registerCallback(mInfoCallback);
|
||||
|
||||
mStatusViewManager.onResume();
|
||||
postDelayed(mOnResumePing, ON_RESUME_PING_DELAY);
|
||||
@@ -607,7 +601,6 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
|
||||
/** {@inheritDoc} */
|
||||
public void cleanUp() {
|
||||
mUpdateMonitor.removeCallback(mInfoCallback); // this must be first
|
||||
mUpdateMonitor.removeCallback(mSimStateCallback);
|
||||
mUnlockWidgetMethods.cleanUp();
|
||||
mLockPatternUtils = null;
|
||||
mUpdateMonitor = null;
|
||||
|
||||
Reference in New Issue
Block a user