Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.ServiceConnection; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.RemoteException; |
| 25 | import android.os.UserHandle; |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 26 | import android.util.Slog; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 27 | import android.view.MotionEvent; |
| 28 | |
| 29 | import com.android.internal.policy.IKeyguardExitCallback; |
| 30 | import com.android.internal.policy.IKeyguardShowCallback; |
| 31 | import com.android.internal.policy.IKeyguardService; |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * Facilitates event communication between navigation bar and keyguard. Currently used to |
| 36 | * control WidgetPager in keyguard to expose the camera widget. |
| 37 | * |
| 38 | */ |
| 39 | public class KeyguardTouchDelegate { |
| 40 | // TODO: propagate changes to these to {@link KeyguardServiceDelegate} |
| 41 | static final String KEYGUARD_PACKAGE = "com.android.keyguard"; |
| 42 | static final String KEYGUARD_CLASS = "com.android.keyguard.KeyguardService"; |
| 43 | |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 44 | private static KeyguardTouchDelegate sInstance; |
| 45 | |
| 46 | private volatile IKeyguardService mService; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 47 | |
| 48 | protected static final boolean DEBUG = false; |
| 49 | protected static final String TAG = "KeyguardTouchDelegate"; |
| 50 | |
| 51 | private final ServiceConnection mKeyguardConnection = new ServiceConnection() { |
| 52 | @Override |
| 53 | public void onServiceConnected(ComponentName name, IBinder service) { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 54 | Slog.v(TAG, "Connected to keyguard"); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 55 | mService = IKeyguardService.Stub.asInterface(service); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void onServiceDisconnected(ComponentName name) { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 61 | Slog.v(TAG, "Disconnected from keyguard"); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 62 | mService = null; |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 63 | sInstance = null; // force reconnection if this goes away |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | }; |
| 67 | |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 68 | private KeyguardTouchDelegate(Context context) { |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 69 | Intent intent = new Intent(); |
| 70 | intent.setClassName(KEYGUARD_PACKAGE, KEYGUARD_CLASS); |
| 71 | if (!context.bindServiceAsUser(intent, mKeyguardConnection, |
| 72 | Context.BIND_AUTO_CREATE, UserHandle.OWNER)) { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 73 | if (DEBUG) Slog.v(TAG, "*** Keyguard: can't bind to " + KEYGUARD_CLASS); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 74 | } else { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 75 | if (DEBUG) Slog.v(TAG, "*** Keyguard started"); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 79 | public static KeyguardTouchDelegate getInstance(Context context) { |
Jim Miller | a999d46 | 2013-10-30 13:58:11 -0700 | [diff] [blame] | 80 | KeyguardTouchDelegate instance = sInstance; |
| 81 | if (instance == null) { |
| 82 | instance = sInstance = new KeyguardTouchDelegate(context); |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 83 | } |
Jim Miller | a999d46 | 2013-10-30 13:58:11 -0700 | [diff] [blame] | 84 | return instance; |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 87 | public boolean isSecure() { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 88 | final IKeyguardService service = mService; |
| 89 | if (service != null) { |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 90 | try { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 91 | return service.isSecure(); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 92 | } catch (RemoteException e) { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 93 | Slog.e(TAG, "RemoteException calling keyguard.isSecure()!", e); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 94 | } |
| 95 | } else { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 96 | Slog.w(TAG, "isSecure(): NO SERVICE!"); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 97 | } |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 98 | return false; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | public boolean dispatch(MotionEvent event) { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 102 | final IKeyguardService service = mService; |
| 103 | if (service != null) { |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 104 | try { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 105 | service.dispatch(event); |
| 106 | return true; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 107 | } catch (RemoteException e) { |
| 108 | // What to do? |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 109 | Slog.e(TAG, "RemoteException sending event to keyguard!", e); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 110 | } |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 111 | } else { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 112 | Slog.w(TAG, "dispatch(event): NO SERVICE!"); |
| 113 | } |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | public boolean isInputRestricted() { |
| 118 | final IKeyguardService service = mService; |
| 119 | if (service != null) { |
| 120 | try { |
| 121 | return service.isInputRestricted(); |
| 122 | } catch (RemoteException e) { |
| 123 | Slog.w(TAG , "Remote Exception", e); |
| 124 | } |
| 125 | } else { |
| 126 | Slog.w(TAG, "isInputRestricted(): NO SERVICE!"); |
| 127 | } |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | public boolean isShowingAndNotHidden() { |
| 132 | final IKeyguardService service = mService; |
| 133 | if (service != null) { |
| 134 | try { |
| 135 | return service.isShowingAndNotHidden(); |
| 136 | } catch (RemoteException e) { |
| 137 | Slog.w(TAG , "Remote Exception", e); |
| 138 | } |
| 139 | } else { |
| 140 | Slog.w(TAG, "isShowingAndNotHidden(): NO SERVICE!"); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 141 | } |
| 142 | return false; |
| 143 | } |
| 144 | |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 145 | public void showAssistant() { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 146 | final IKeyguardService service = mService; |
| 147 | if (service != null) { |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 148 | try { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 149 | service.showAssistant(); |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 150 | } catch (RemoteException e) { |
| 151 | // What to do? |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 152 | Slog.e(TAG, "RemoteException launching assistant!", e); |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 153 | } |
| 154 | } else { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 155 | Slog.w(TAG, "showAssistant(event): NO SERVICE!"); |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
| 159 | public void launchCamera() { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 160 | final IKeyguardService service = mService; |
| 161 | if (service != null) { |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 162 | try { |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 163 | service.launchCamera(); |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 164 | } catch (RemoteException e) { |
| 165 | // What to do? |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 166 | Slog.e(TAG, "RemoteException launching camera!", e); |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 167 | } |
| 168 | } else { |
Jim Miller | a999d46 | 2013-10-30 13:58:11 -0700 | [diff] [blame] | 169 | Slog.w(TAG, "launchCamera(): NO SERVICE!"); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | public void dismiss() { |
| 174 | final IKeyguardService service = mService; |
| 175 | if (service != null) { |
| 176 | try { |
| 177 | service.dismiss(); |
| 178 | } catch (RemoteException e) { |
| 179 | // What to do? |
| 180 | Slog.e(TAG, "RemoteException dismissing keyguard!", e); |
| 181 | } |
| 182 | } else { |
| 183 | Slog.w(TAG, "dismiss(): NO SERVICE!"); |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 187 | } |