aboutsummaryrefslogtreecommitdiffstats
path: root/cm
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2015-08-10 11:18:55 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-08-13 10:49:17 -0700
commit307941c0fdb03f316693142a0076345e9be52add (patch)
treee6e6609e9dbf510d98ce6dd6eb97dcff36d0e069 /cm
parentf304ef2ac94ec4c2aef48047a3e21bcaf703d483 (diff)
downloadvendor_cmsdk-307941c0fdb03f316693142a0076345e9be52add.zip
vendor_cmsdk-307941c0fdb03f316693142a0076345e9be52add.tar.gz
vendor_cmsdk-307941c0fdb03f316693142a0076345e9be52add.tar.bz2
cmsdk: fix enabling/disabling keyguard
We cannot create a new WindowManagerPolicy every time since the method isn't called from the main thread every time, which could lead to exceptions being thrown when trying to create PhoneWindowManager. Instead of creating a new policy, bind to the keyguard service on bind, and then pass it to the profile to operate on. Ref: NIGHTLIES-1640 Change-Id: I3ac58bfa534755eaa73890cc5ddf05987a7d0d8c Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'cm')
-rw-r--r--cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java44
1 files changed, 43 insertions, 1 deletions
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java
index 8b8bf4c..e8affd1 100644
--- a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java
+++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java
@@ -16,6 +16,9 @@
package org.cyanogenmod.platform.internal;
+import android.content.ComponentName;
+import android.content.ServiceConnection;
+import com.android.internal.policy.IKeyguardService;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
@@ -63,6 +66,9 @@ public class ProfileManagerService extends SystemService {
public static final String PERMISSION_CHANGE_SETTINGS = "android.permission.WRITE_SETTINGS";
+ public static final String KEYGUARD_PACKAGE = "com.android.systemui";
+ public static final String KEYGUARD_CLASS = "com.android.systemui.keyguard.KeyguardService";
+
/* package */ static final File PROFILE_FILE =
new File(Environment.getSystemSecureDirectory(), "profiles.xml");
@@ -86,6 +92,30 @@ public class ProfileManagerService extends SystemService {
private BackupManager mBackupManager;
private ProfileTriggerHelper mTriggerHelper;
+ private Runnable mBindKeyguard = new Runnable() {
+ @Override
+ public void run() {
+ bindKeyguard();
+ }
+ };
+ private IKeyguardService mKeyguardService;
+ private final ServiceConnection mKeyguardConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ if (LOCAL_LOGV) Log.v(TAG, "*** Keyguard connected (yay!)");
+ mKeyguardService = IKeyguardService.Stub.asInterface(service);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ if (LOCAL_LOGV) Log.v(TAG, "*** Keyguard disconnected, retrying connection soon.");
+ mKeyguardService = null;
+ // system UI died? retry connection in 5s
+ mHandler.removeCallbacks(mBindKeyguard);
+ mHandler.postDelayed(mBindKeyguard, 5000);
+ }
+ };
+
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -123,11 +153,23 @@ public class ProfileManagerService extends SystemService {
mContext.registerReceiver(mIntentReceiver, filter);
}
+ private void bindKeyguard() {
+ if (mKeyguardService == null) {
+ Intent intent = new Intent();
+ intent.setClassName(KEYGUARD_PACKAGE, KEYGUARD_CLASS);
+ if (!mContext.bindServiceAsUser(intent, mKeyguardConnection,
+ Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
+ Log.e(TAG, "error binding to keyguard service");
+ }
+ }
+ }
+
private void initialize() {
initialize(false);
}
private void initialize(boolean skipFile) {
+ bindKeyguard();
mTriggerHelper = new ProfileTriggerHelper(mContext, mHandler, this);
mProfiles = new HashMap<UUID, Profile>();
mProfileNames = new HashMap<String, UUID>();
@@ -588,7 +630,7 @@ public class ProfileManagerService extends SystemService {
if (doInit) {
if (LOCAL_LOGV) Log.v(TAG, "setActiveProfile(Profile, boolean) - Running init");
// Call profile's "doSelect"
- mActiveProfile.doSelect(mContext);
+ mActiveProfile.doSelect(mContext, mKeyguardService);
// Notify other applications of newly selected profile.
Intent broadcast = new Intent(ProfileManager.INTENT_ACTION_PROFILE_SELECTED);