Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b06ea706 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Add reporting of activity movement for search manager.

This adds a new API with the activity manager to find out about movement between
activities.  For my sanity, the old IActivityWatcher is now renamed to
IActivityController, and the new activity movement interface is named
IActivityWatcher.

This changes the search manager itself to use the new API to manage its state.
Note that there are still problems when going back to the search dialog after
it was hidden -- the suggestions window no longer appears until you explicitly
dismiss and re-show it.
parent 3660c095
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ LOCAL_SRC_FILES += \
	core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl \
  core/java/android/accessibilityservice/IEventListener.aidl \
	core/java/android/accounts/IAccountsService.aidl \
	core/java/android/app/IActivityController.aidl \
	core/java/android/app/IActivityPendingResult.aidl \
	core/java/android/app/IActivityWatcher.aidl \
	core/java/android/app/IAlarmManager.aidl \
+30 −11
Original line number Diff line number Diff line
@@ -612,6 +612,7 @@ public class Activity extends ContextThemeWrapper
    // set by the thread after the constructor and before onCreate(Bundle savedInstanceState) is called.
    private Instrumentation mInstrumentation;
    private IBinder mToken;
    private int mIdent;
    /*package*/ String mEmbeddedID;
    private Application mApplication;
    /*package*/ Intent mIntent;
@@ -789,9 +790,6 @@ public class Activity extends ContextThemeWrapper
    protected void onCreate(Bundle savedInstanceState) {
        mVisibleFromClient = mWindow.getWindowStyle().getBoolean(
                com.android.internal.R.styleable.Window_windowNoDisplay, true);
        // uses super.getSystemService() since this.getSystemService() looks at the
        // mSearchManager field.
        mSearchManager = (SearchManager) super.getSystemService(Context.SEARCH_SERVICE);
        mCalled = true;
    }

@@ -2531,6 +2529,7 @@ public class Activity extends ContextThemeWrapper
     */
    public void startSearch(String initialQuery, boolean selectInitialQuery, 
            Bundle appSearchData, boolean globalSearch) {
        ensureSearchManager();
        mSearchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
                        appSearchData, globalSearch); 
    }
@@ -3241,6 +3240,24 @@ public class Activity extends ContextThemeWrapper
        return getSharedPreferences(getLocalClassName(), mode);
    }
    
    private void ensureSearchManager() {
        if (mSearchManager != null) {
            return;
        }
        
        // uses super.getSystemService() since this.getSystemService() looks at the
        // mSearchManager field.
        mSearchManager = (SearchManager) super.getSystemService(Context.SEARCH_SERVICE);
        int ident = mIdent;
        if (ident == 0) {
            if (mParent != null) ident = mParent.mIdent;
            if (ident == 0) {
                throw new IllegalArgumentException("no ident");
            }
        }
        mSearchManager.setIdent(ident);
    }
    
    @Override
    public Object getSystemService(String name) {
        if (getBaseContext() == null) {
@@ -3251,6 +3268,7 @@ public class Activity extends ContextThemeWrapper
        if (WINDOW_SERVICE.equals(name)) {
            return mWindowManager;
        } else if (SEARCH_SERVICE.equals(name)) {
            ensureSearchManager();
            return mSearchManager;
        }
        return super.getSystemService(name);
@@ -3450,14 +3468,17 @@ public class Activity extends ContextThemeWrapper
            Application application, Intent intent, ActivityInfo info, CharSequence title, 
            Activity parent, String id, Object lastNonConfigurationInstance,
            Configuration config) {
        attach(context, aThread, instr, token, application, intent, info, title, parent, id,
        attach(context, aThread, instr, token, 0, application, intent, info, title, parent, id,
            lastNonConfigurationInstance, null, config);
    }
    
    final void attach(Context context, ActivityThread aThread, Instrumentation instr, IBinder token,
        Application application, Intent intent, ActivityInfo info, CharSequence title, 
        Activity parent, String id, Object lastNonConfigurationInstance,
        HashMap<String,Object> lastNonConfigurationChildInstances, Configuration config) {
    final void attach(Context context, ActivityThread aThread,
            Instrumentation instr, IBinder token, int ident,
            Application application, Intent intent, ActivityInfo info,
            CharSequence title, Activity parent, String id,
            Object lastNonConfigurationInstance,
            HashMap<String,Object> lastNonConfigurationChildInstances,
            Configuration config) {
        attachBaseContext(context);

        mWindow = PolicyManager.makeNewWindow(this);
@@ -3470,6 +3491,7 @@ public class Activity extends ContextThemeWrapper
        mMainThread = aThread;
        mInstrumentation = instr;
        mToken = token;
        mIdent = ident;
        mApplication = application;
        mIntent = intent;
        mComponent = intent.getComponent();
@@ -3554,9 +3576,6 @@ public class Activity extends ContextThemeWrapper

    final void performPause() {
        onPause();

        // dismiss the search dialog if it is open
        mSearchManager.stopSearch();
    }
    
    final void performUserLeaving() {
+45 −5
Original line number Diff line number Diff line
@@ -881,11 +881,11 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case SET_ACTIVITY_WATCHER_TRANSACTION: {
        case SET_ACTIVITY_CONTROLLER_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IActivityWatcher watcher = IActivityWatcher.Stub.asInterface(
            IActivityController watcher = IActivityController.Stub.asInterface(
                    data.readStrongBinder());
            setActivityWatcher(watcher);
            setActivityController(watcher);
            return true;
        }

@@ -1052,6 +1052,22 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            reply.writeNoException();
            return true;
        }
        
        case REGISTER_ACTIVITY_WATCHER_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IActivityWatcher watcher = IActivityWatcher.Stub.asInterface(
                    data.readStrongBinder());
            registerActivityWatcher(watcher);
            return true;
        }
        
        case UNREGISTER_ACTIVITY_WATCHER_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IActivityWatcher watcher = IActivityWatcher.Stub.asInterface(
                    data.readStrongBinder());
            unregisterActivityWatcher(watcher);
            return true;
        }
        }
        
        return super.onTransact(code, data, reply, flags);
@@ -2105,13 +2121,13 @@ class ActivityManagerProxy implements IActivityManager
        data.recycle();
        reply.recycle();
    }
    public void setActivityWatcher(IActivityWatcher watcher) throws RemoteException
    public void setActivityController(IActivityController watcher) throws RemoteException
    {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(watcher != null ? watcher.asBinder() : null);
        mRemote.transact(SET_ACTIVITY_WATCHER_TRANSACTION, data, reply, 0);
        mRemote.transact(SET_ACTIVITY_CONTROLLER_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
@@ -2290,5 +2306,29 @@ class ActivityManagerProxy implements IActivityManager
        data.recycle();
    }
    
    public void registerActivityWatcher(IActivityWatcher watcher)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(watcher != null ? watcher.asBinder() : null);
        mRemote.transact(REGISTER_ACTIVITY_WATCHER_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }
    
    public void unregisterActivityWatcher(IActivityWatcher watcher)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(watcher != null ? watcher.asBinder() : null);
        mRemote.transact(UNREGISTER_ACTIVITY_WATCHER_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }
    
    private IBinder mRemote;
}
+8 −16
Original line number Diff line number Diff line
@@ -1090,6 +1090,7 @@ public final class ActivityThread {

    private static final class ActivityRecord {
        IBinder token;
        int ident;
        Intent intent;
        Bundle state;
        Activity activity;
@@ -1299,12 +1300,13 @@ public final class ActivityThread {

        // we use token to identify this activity without having to send the
        // activity itself back to the activity manager. (matters more with ipc)
        public final void scheduleLaunchActivity(Intent intent, IBinder token,
        public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
                ActivityInfo info, Bundle state, List<ResultInfo> pendingResults,
                List<Intent> pendingNewIntents, boolean notResumed, boolean isForward) {
            ActivityRecord r = new ActivityRecord();

            r.token = token;
            r.ident = ident;
            r.intent = intent;
            r.activityInfo = info;
            r.state = state;
@@ -2196,22 +2198,12 @@ public final class ActivityThread {
        return aInfo;
    }
    
    public final Activity startActivityNow(Activity parent, String id,
            Intent intent, IBinder token, Bundle state) {
        ActivityInfo aInfo = resolveActivityInfo(intent);
        return startActivityNow(parent, id, intent, aInfo, token, state);
    }
    
    public final Activity startActivityNow(Activity parent, String id,
            Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state) {
        return startActivityNow(parent, id, intent, activityInfo, token, state, null);
    }

    public final Activity startActivityNow(Activity parent, String id,
        Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state,
        Object lastNonConfigurationInstance) {
        ActivityRecord r = new ActivityRecord();
            r.token = token;
            r.ident = 0;
            r.intent = intent;
            r.state = state;
            r.parent = parent;
@@ -2335,10 +2327,10 @@ public final class ActivityThread {
                appContext.setOuterContext(activity);
                CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
                Configuration config = new Configuration(mConfiguration);
                activity.attach(appContext, this, getInstrumentation(), r.token, app, 
                        r.intent, r.activityInfo, title, r.parent, r.embeddedID,
                        r.lastNonConfigurationInstance, r.lastNonConfigurationChildInstances,
                        config);
                activity.attach(appContext, this, getInstrumentation(), r.token,
                        r.ident, app, r.intent, r.activityInfo, title, r.parent,
                        r.embeddedID, r.lastNonConfigurationInstance,
                        r.lastNonConfigurationChildInstances, config);
                
                if (customIntent != null) {
                    activity.mIntent = customIntent;
+5 −2
Original line number Diff line number Diff line
@@ -119,13 +119,15 @@ public abstract class ApplicationThreadNative extends Binder
            data.enforceInterface(IApplicationThread.descriptor);
            Intent intent = Intent.CREATOR.createFromParcel(data);
            IBinder b = data.readStrongBinder();
            int ident = data.readInt();
            ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
            Bundle state = data.readBundle();
            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
            boolean notResumed = data.readInt() != 0;
            boolean isForward = data.readInt() != 0;
            scheduleLaunchActivity(intent, b, info, state, ri, pi, notResumed, isForward);
            scheduleLaunchActivity(intent, b, ident, info, state, ri, pi,
                    notResumed, isForward);
            return true;
        }
        
@@ -442,7 +444,7 @@ class ApplicationThreadProxy implements IApplicationThread {
        data.recycle();
    }

    public final void scheduleLaunchActivity(Intent intent, IBinder token,
    public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
            ActivityInfo info, Bundle state, List<ResultInfo> pendingResults,
    		List<Intent> pendingNewIntents, boolean notResumed, boolean isForward)
    		throws RemoteException {
@@ -450,6 +452,7 @@ class ApplicationThreadProxy implements IApplicationThread {
        data.writeInterfaceToken(IApplicationThread.descriptor);
        intent.writeToParcel(data, 0);
        data.writeStrongBinder(token);
        data.writeInt(ident);
        info.writeToParcel(data, 0);
        data.writeBundle(state);
        data.writeTypedList(pendingResults);
Loading