Merge changes I2d6f9932,Ib3cc799d into nyc-dev

* changes:
  Rely on SystemService#onSwitchUser() in TSMS.
  Switch to SystemService lifecycle in TSMS.
This commit is contained in:
Yohei Yukawa
2016-03-07 22:12:57 +00:00
committed by Android (Google) Code Review
2 changed files with 49 additions and 42 deletions

View File

@@ -27,9 +27,9 @@ import com.android.internal.textservice.ITextServicesSessionListener;
import org.xmlpull.v1.XmlPullParserException;
import android.annotation.UserIdInt;
import android.app.ActivityManagerNative;
import android.app.AppGlobals;
import android.app.SynchronousUserSwitchObserver;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -81,9 +81,47 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
private final HashMap<String, SpellCheckerBindGroup> mSpellCheckerBindGroups = new HashMap<>();
private final TextServicesSettings mSettings;
public void systemRunning() {
if (!mSystemReady) {
mSystemReady = true;
public static final class Lifecycle extends SystemService {
private TextServicesManagerService mService;
public Lifecycle(Context context) {
super(context);
mService = new TextServicesManagerService(context);
}
@Override
public void onStart() {
publishBinderService(Context.TEXT_SERVICES_MANAGER_SERVICE, mService);
}
@Override
public void onSwitchUser(@UserIdInt int userHandle) {
// Called on the system server's main looper thread.
// TODO: Dispatch this to a worker thread as needed.
mService.onSwitchUser(userHandle);
}
@Override
public void onBootPhase(int phase) {
// Called on the system server's main looper thread.
// TODO: Dispatch this to a worker thread as needed.
if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) {
mService.systemRunning();
}
}
}
void systemRunning() {
synchronized (mSpellCheckerMap) {
if (!mSystemReady) {
mSystemReady = true;
}
}
}
void onSwitchUser(@UserIdInt int userId) {
synchronized (mSpellCheckerMap) {
switchUserLocked(userId);
}
}
@@ -98,24 +136,6 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
int userId = UserHandle.USER_SYSTEM;
try {
ActivityManagerNative.getDefault().registerUserSwitchObserver(
new SynchronousUserSwitchObserver() {
@Override
public void onUserSwitching(int newUserId) throws RemoteException {
synchronized(mSpellCheckerMap) {
switchUserLocked(newUserId);
}
}
@Override
public void onUserSwitchComplete(int newUserId) throws RemoteException {
}
@Override
public void onForegroundProfileSwitch(int newProfileId) {
// Ignore.
}
});
userId = ActivityManagerNative.getDefault().getCurrentUser().id;
} catch (RemoteException e) {
Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e);
@@ -128,7 +148,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
switchUserLocked(userId);
}
private void switchUserLocked(int userId) {
private void switchUserLocked(@UserIdInt int userId) {
mSettings.setCurrentUserId(userId);
updateCurrentProfileIds();
unbindServiceLocked();
@@ -1011,17 +1031,18 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
private static class TextServicesSettings {
private final ContentResolver mResolver;
@UserIdInt
private int mCurrentUserId;
@GuardedBy("mLock")
private int[] mCurrentProfileIds = new int[0];
private Object mLock = new Object();
public TextServicesSettings(ContentResolver resolver, int userId) {
public TextServicesSettings(ContentResolver resolver, @UserIdInt int userId) {
mResolver = resolver;
mCurrentUserId = userId;
}
public void setCurrentUserId(int userId) {
public void setCurrentUserId(@UserIdInt int userId) {
if (DBG) {
Slog.d(TAG, "--- Swtich the current user from " + mCurrentUserId + " to "
+ userId + ", new ime = " + getSelectedSpellChecker());
@@ -1036,7 +1057,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
}
}
public boolean isCurrentProfile(int userId) {
public boolean isCurrentProfile(@UserIdInt int userId) {
synchronized (mLock) {
if (userId == mCurrentUserId) return true;
for (int i = 0; i < mCurrentProfileIds.length; i++) {
@@ -1046,6 +1067,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
}
}
@UserIdInt
public int getCurrentUserId() {
return mCurrentUserId;
}

View File

@@ -635,7 +635,6 @@ public final class SystemServer {
WallpaperManagerService wallpaper = null;
LocationManagerService location = null;
CountryDetectorService countryDetector = null;
TextServicesManagerService tsms = null;
ILockSettings lockSettings = null;
AssetAtlasService atlas = null;
MediaRouterService mediaRouter = null;
@@ -762,14 +761,7 @@ public final class SystemServer {
}
if (!disableNonCoreServices) {
traceBeginAndSlog("StartTextServicesManagerService");
try {
tsms = new TextServicesManagerService(context);
ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
} catch (Throwable e) {
reportWtf("starting Text Service Manager Service", e);
}
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class);
}
if (!disableNetwork) {
@@ -1256,7 +1248,6 @@ public final class SystemServer {
final CountryDetectorService countryDetectorF = countryDetector;
final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
final TextServicesManagerService textServiceManagerServiceF = tsms;
final StatusBarManagerService statusBarF = statusBar;
final AssetAtlasService atlasF = atlas;
final InputManagerService inputManagerF = inputManager;
@@ -1371,12 +1362,6 @@ public final class SystemServer {
} catch (Throwable e) {
reportWtf("Notifying CommonTimeManagementService running", e);
}
try {
if (textServiceManagerServiceF != null)
textServiceManagerServiceF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying TextServicesManagerService running", e);
}
try {
if (atlasF != null) atlasF.systemRunning();
} catch (Throwable e) {