author | Shuide Chen <shuide.chen@amlogic.com> | 2017-09-27 06:43:19 (GMT) |
---|---|---|
committer | Shuide Chen <shuide.chen@amlogic.com> | 2017-09-27 06:56:37 (GMT) |
commit | aa09ed54126ee248363d9837a9475986daa7bd56 (patch) | |
tree | f2d0c990876a1c8baea647ed11f09eca33debdc1 | |
parent | d0b33646bb9f90c111029a3e485723fb95c5dc3c (diff) | |
download | frameworks-aa09ed54126ee248363d9837a9475986daa7bd56.zip frameworks-aa09ed54126ee248363d9837a9475986daa7bd56.tar.gz frameworks-aa09ed54126ee248363d9837a9475986daa7bd56.tar.bz2 |
boot: add stub keyguard and disable it when bootcomplete [1/2]
PD# 149086
AMS will wait keyguard showing before start HOME, if not provide any
keyguard service, the default wait timeout is 5S, which introduces a
big delay during booting.
Implement a stub keyguard, showing and then disabling it can fix this
problem.
Change-Id: Ia8b3557130727d2a7c58104a284bccfa3658b8d5
Signed-off-by: Shuide Chen <shuide.chen@amlogic.com>
-rw-r--r-- | core/res/AndroidManifest.xml | 5 | ||||
-rw-r--r-- | core/res/src/com/droidlogic/BootComplete.java | 77 | ||||
-rw-r--r-- | core/res/src/com/droidlogic/StubKeyguardService.java | 227 |
3 files changed, 309 insertions, 0 deletions
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 8681534..8570bdb 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -63,6 +63,11 @@ <service android:name="com.droidlogic.DialogBluetoothService" /> <service android:name="com.droidlogic.EsmService" /> <service android:name="com.droidlogic.WifiSuspendService" /> + <service + android:name=".StubKeyguardService" + android:directBootAware="true" + android:exported="true" + android:enabled="true" /> <receiver android:name="com.droidlogic.BootComplete"> <intent-filter> diff --git a/core/res/src/com/droidlogic/BootComplete.java b/core/res/src/com/droidlogic/BootComplete.java index 381587d..fe5b9ea 100644 --- a/core/res/src/com/droidlogic/BootComplete.java +++ b/core/res/src/com/droidlogic/BootComplete.java @@ -14,6 +14,18 @@ import android.media.AudioManager; import android.media.AudioSystem; import android.provider.Settings; +import android.view.IWindowManager; +import android.os.ServiceManager; +import android.app.KeyguardManager; +import android.app.KeyguardManager.KeyguardLock; + +import android.content.ComponentName; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.os.RemoteException; +import com.android.internal.policy.IKeyguardExitCallback; +import com.android.internal.policy.IKeyguardService; + import com.droidlogic.app.OutputModeManager; import com.droidlogic.app.PlayBackManager; import com.droidlogic.app.SystemControlEvent; @@ -26,6 +38,9 @@ public class BootComplete extends BroadcastReceiver { private static final String FIRST_RUN = "first_run"; private static final int SPEAKER_DEFAULT_VOLUME = 11; + IKeyguardService mService = null; + RemoteServiceConnection mConnection; + @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); @@ -156,10 +171,72 @@ public class BootComplete extends BroadcastReceiver { Log.d(TAG,"setWireDeviceConnectionState"); //simulate DEVPATH=/devices/virtual/amhdmitx/amhdmitx0/hdmi_audio uevent funtion audioManager.setWiredDeviceConnectionState(AudioManager.DEVICE_OUT_HDMI, (outputModeManager.isHDMIPlugged() == true) ? 1 : 0, "", ""); + + bindKeyguardService(context); + + // Dissmiss keyguard first. + final IWindowManager wm = IWindowManager.Stub + .asInterface(ServiceManager.getService(Context.WINDOW_SERVICE)); + try { + wm.dismissKeyguard(null); + } catch (Exception e) { + // ignore it + } + + KeyguardManager km= (KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE); + KeyguardLock kl = km.newKeyguardLock("unLock"); + kl.disableKeyguard(); } } private boolean needCecExtend(SystemControlManager sm, Context context) { return sm.getPropertyInt("ro.hdmi.device_type", -1) == HdmiDeviceInfo.DEVICE_PLAYBACK; } + + class KeyguardExitCallback extends IKeyguardExitCallback.Stub { + + @Override + public void onKeyguardExitResult(final boolean success) throws RemoteException { + Log.i(TAG, "onKeyguardExitResult: " + success); + } + }; + + private class RemoteServiceConnection implements ServiceConnection { + public void onServiceConnected(ComponentName className, IBinder service) { + Log.v(TAG, "onServiceConnected()"); + mService = IKeyguardService.Stub.asInterface(service); + try { + mService.asBinder().linkToDeath(new IBinder.DeathRecipient() { + @Override + public void binderDied() { + } + }, 0); + + mService.verifyUnlock(new KeyguardExitCallback()); + + } catch (RemoteException e) { + Log.w(TAG, "Couldn't linkToDeath"); + e.printStackTrace(); + } + } + + public void onServiceDisconnected(ComponentName className) { + Log.v(TAG, "onServiceDisconnected()"); + mService = null; + } + }; + + private void bindKeyguardService(Context ctx) { + if (mConnection == null) { + mConnection = new RemoteServiceConnection(); + Intent intent = new Intent(); + intent.setClassName("com.droidlogic", "com.droidlogic.StubKeyguardService"); + Log.v(TAG, "BINDING SERVICE: " + "com.droidlogic.StubKeyguardService"); + if (!ctx.getApplicationContext().bindService(intent, mConnection, Context.BIND_AUTO_CREATE)) { + Log.v(TAG, "FAILED TO BIND TO KEYGUARD!"); + } + } else { + Log.v(TAG, "Service already bound"); + } + } } diff --git a/core/res/src/com/droidlogic/StubKeyguardService.java b/core/res/src/com/droidlogic/StubKeyguardService.java new file mode 100644 index 0000000..0ab97cc --- a/dev/null +++ b/core/res/src/com/droidlogic/StubKeyguardService.java @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2014 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.droidlogic; + +import android.app.Service; +import android.content.Intent; +import android.os.Binder; +import android.os.Bundle; +import android.os.Debug; +import android.os.IBinder; +import android.os.Process; +import android.os.RemoteException; +import android.os.DeadObjectException; +import android.os.Trace; +import android.util.Log; + +import com.android.internal.policy.IKeyguardDismissCallback; +import com.android.internal.policy.IKeyguardDrawnCallback; +import com.android.internal.policy.IKeyguardExitCallback; +import com.android.internal.policy.IKeyguardService; +import com.android.internal.policy.IKeyguardStateCallback; +import java.util.ArrayList; + +import static android.content.pm.PackageManager.PERMISSION_GRANTED; + +public class StubKeyguardService extends Service { + static final String TAG = "KeyguardService"; + static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD; + private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>(); + + @Override + public void onCreate() { + } + + @Override + public IBinder onBind(Intent intent) { + return mBinder; + } + + void checkPermission() { + //Log.d("VERI", "here"+Log.getStackTraceString(new Throwable())); + // Avoid deadlock by avoiding calling back into the system process. + if (Binder.getCallingUid() == Process.SYSTEM_UID) return; + + // Otherwise,explicitly check for caller permission ... + if (getBaseContext().checkCallingOrSelfPermission(PERMISSION) != PERMISSION_GRANTED) { + Log.w(TAG, "Caller needs permission '" + PERMISSION + "' to call " + Debug.getCaller()); + throw new SecurityException("Access denied to process: " + Binder.getCallingPid() + + ", must have permission " + PERMISSION); + } + } + +void stateCallback_l() { + int size = mKeyguardStateCallbacks.size(); + for (int i = size - 1; i >= 0; i--) { + final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i); + Log.d("VERI", "stateCallback_l:"+callback); + try { + // input restrict default is true, which will block system window showing + callback.onInputRestrictedStateChanged(false); + callback.onSimSecureStateChanged(false); + callback.onShowingStateChanged(false); + callback.onTrustedChanged(false); + callback.onHasLockscreenWallpaperChanged(false); + } catch (RemoteException e) { + Log.d("VERI", "Failed to call onDeviceProvisioned", e); + if (e instanceof DeadObjectException) { + mKeyguardStateCallbacks.remove(callback); + } + } + } +} + + private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() { + + @Override // Binder interface + public void addStateMonitorCallback(IKeyguardStateCallback callback) { + checkPermission(); + synchronized (this) { + mKeyguardStateCallbacks.add(callback); + stateCallback_l(); + } + } + + @Override // Binder interface + public void verifyUnlock(IKeyguardExitCallback callback) { + checkPermission(); + try { + callback.onKeyguardExitResult(true); + } catch (RemoteException e) { + Log.w(TAG, "Failed to call onKeyguardExitResult(true)", e); + } + Log.d("VERI", "verifyUnlock"); + synchronized (this) { + stateCallback_l(); + } + } + + @Override // Binder interface + public void setOccluded(boolean isOccluded, boolean animate) { + checkPermission(); + } + + @Override // Binder interface + public void dismiss(IKeyguardDismissCallback callback) { + checkPermission(); + if (callback != null) { + Log.w(TAG, "dismiss success+"+callback); + try { + callback.onDismissSucceeded(); + } catch (RemoteException e) { + Log.w(TAG, "Failed to call onKeyguardExitResult(true)", e); + } + } + synchronized (this) { + stateCallback_l(); + } + } + + @Override // Binder interface + public void onDreamingStarted() { + checkPermission(); + } + + @Override // Binder interface + public void onDreamingStopped() { + checkPermission(); + } + + @Override // Binder interface + public void onStartedGoingToSleep(int reason) { + checkPermission(); + } + + @Override // Binder interface + public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) { + checkPermission(); + } + + @Override // Binder interface + public void onStartedWakingUp() { + checkPermission(); + } + + @Override // Binder interface + public void onScreenTurningOn(IKeyguardDrawnCallback callback) { + checkPermission(); + if (callback == null) return; + + try { + callback.onDrawn(); + } catch (RemoteException e) { + Log.w(TAG, "Exception calling onDrawn():", e); + } + synchronized (this) { + stateCallback_l(); + } + } + + @Override // Binder interface + public void onScreenTurnedOn() { + checkPermission(); + synchronized (this) { + stateCallback_l(); + } + } + + @Override // Binder interface + public void onScreenTurnedOff() { + checkPermission(); + } + + @Override // Binder interface + public void setKeyguardEnabled(boolean enabled) { + checkPermission(); + } + + @Override // Binder interface + public void onSystemReady() { + checkPermission(); + } + + @Override // Binder interface + public void doKeyguardTimeout(Bundle options) { + checkPermission(); + } + + @Override // Binder interface + public void setSwitchingUser(boolean switching) { + checkPermission(); + } + + @Override // Binder interface + public void setCurrentUser(int userId) { + checkPermission(); + } + + @Override + public void onBootCompleted() { + checkPermission(); + } + + @Override + public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { + checkPermission(); + } + + @Override + public void onShortPowerPressedGoHome() { + checkPermission(); + } + }; +} + |