cmsdk: Allow services to conditionally start before decryption

* Essentially everything in CMSDK should remain silent when we
   are being prompted to enter a passcode for decrypting the
   device. Unfortunately, simply shutting off CMSDK entirely
   will cause crashes everywhere. We need to be somewhat
   selective about it.
 * Motivation for this was LiveDisplay kicking into night mode before
   decrypted due to location services failing.

Change-Id: I4d745debb2894776258343e8696ce5144f094404
This commit is contained in:
Steve Kondik 2016-07-28 02:48:59 -07:00 committed by Steve Kondik
parent fa227b12ed
commit 7bf7c4b72e
3 changed files with 32 additions and 2 deletions

View File

@ -17,6 +17,7 @@
package org.cyanogenmod.platform.internal;
import android.content.Context;
import android.os.SystemProperties;
import android.util.Slog;
import com.android.server.LocalServices;
import com.android.server.SystemServiceManager;
@ -33,11 +34,21 @@ public class CMSystemServer {
private Context mSystemContext;
private CMSystemServiceHelper mSystemServiceHelper;
private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
private static final String ENCRYPTED_STATE = "1";
public CMSystemServer(Context systemContext) {
mSystemContext = systemContext;
mSystemServiceHelper = new CMSystemServiceHelper(mSystemContext);
}
public static boolean coreAppsOnly() {
// Only run "core" apps+services if we're encrypting the device.
final String cryptState = SystemProperties.get("vold.decrypt");
return ENCRYPTING_STATE.equals(cryptState) ||
ENCRYPTED_STATE.equals(cryptState);
}
/**
* Invoked via reflection by the SystemServer
*/
@ -64,8 +75,13 @@ public class CMSystemServer {
CMSystemService cmSystemService = mSystemServiceHelper.getServiceFor(service);
if (context.getPackageManager().hasSystemFeature(
cmSystemService.getFeatureDeclaration())) {
Slog.i(TAG, "Starting service " + service);
ssm.startService(cmSystemService.getClass());
if (coreAppsOnly() && !cmSystemService.isCoreService()) {
Slog.d(TAG, "Not starting " + service +
" - only parsing core apps");
} else {
Slog.i(TAG, "Starting service " + service);
ssm.startService(cmSystemService.getClass());
}
} else {
Slog.i(TAG, "Not starting service " + service +
" due to feature not declared on device");

View File

@ -25,4 +25,13 @@ public abstract class CMSystemService extends SystemService {
}
public abstract String getFeatureDeclaration();
/**
* Override and return true if the service should be started
* before the device is decrypted.
*/
public boolean isCoreService() {
return true;
}
}

View File

@ -150,6 +150,11 @@ public class LiveDisplayService extends CMSystemService {
return CMContextConstants.Features.LIVEDISPLAY;
}
@Override
public boolean isCoreService() {
return false;
}
@Override
public void onStart() {
publishBinderService(CMContextConstants.CM_LIVEDISPLAY_SERVICE, mBinder);