ApplicationThreadNative.java revision 9d39d0cb361c5d3bba04a6bacf299be2162a6e92
1/*
2 * Copyright (C) 2006 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
17package android.app;
18
19import android.content.ComponentName;
20import android.content.Intent;
21import android.content.IIntentReceiver;
22import android.content.pm.ActivityInfo;
23import android.content.pm.ApplicationInfo;
24import android.content.pm.ProviderInfo;
25import android.content.pm.ServiceInfo;
26import android.content.res.Configuration;
27import android.os.Binder;
28import android.os.Bundle;
29import android.os.Debug;
30import android.os.Parcelable;
31import android.os.RemoteException;
32import android.os.IBinder;
33import android.os.Parcel;
34import android.os.ParcelFileDescriptor;
35
36import java.io.FileDescriptor;
37import java.io.IOException;
38import java.util.HashMap;
39import java.util.List;
40import java.util.Map;
41
42/** {@hide} */
43public abstract class ApplicationThreadNative extends Binder
44        implements IApplicationThread {
45    /**
46     * Cast a Binder object into an application thread interface, generating
47     * a proxy if needed.
48     */
49    static public IApplicationThread asInterface(IBinder obj) {
50        if (obj == null) {
51            return null;
52        }
53        IApplicationThread in =
54            (IApplicationThread)obj.queryLocalInterface(descriptor);
55        if (in != null) {
56            return in;
57        }
58
59        return new ApplicationThreadProxy(obj);
60    }
61
62    public ApplicationThreadNative() {
63        attachInterface(this, descriptor);
64    }
65
66    @Override
67    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
68            throws RemoteException {
69        switch (code) {
70        case SCHEDULE_PAUSE_ACTIVITY_TRANSACTION:
71        {
72            data.enforceInterface(IApplicationThread.descriptor);
73            IBinder b = data.readStrongBinder();
74            boolean finished = data.readInt() != 0;
75            boolean userLeaving = data.readInt() != 0;
76            int configChanges = data.readInt();
77            schedulePauseActivity(b, finished, userLeaving, configChanges);
78            return true;
79        }
80
81        case SCHEDULE_STOP_ACTIVITY_TRANSACTION:
82        {
83            data.enforceInterface(IApplicationThread.descriptor);
84            IBinder b = data.readStrongBinder();
85            boolean show = data.readInt() != 0;
86            int configChanges = data.readInt();
87            scheduleStopActivity(b, show, configChanges);
88            return true;
89        }
90
91        case SCHEDULE_WINDOW_VISIBILITY_TRANSACTION:
92        {
93            data.enforceInterface(IApplicationThread.descriptor);
94            IBinder b = data.readStrongBinder();
95            boolean show = data.readInt() != 0;
96            scheduleWindowVisibility(b, show);
97            return true;
98        }
99
100        case SCHEDULE_RESUME_ACTIVITY_TRANSACTION:
101        {
102            data.enforceInterface(IApplicationThread.descriptor);
103            IBinder b = data.readStrongBinder();
104            boolean isForward = data.readInt() != 0;
105            scheduleResumeActivity(b, isForward);
106            return true;
107        }
108
109        case SCHEDULE_SEND_RESULT_TRANSACTION:
110        {
111            data.enforceInterface(IApplicationThread.descriptor);
112            IBinder b = data.readStrongBinder();
113            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
114            scheduleSendResult(b, ri);
115            return true;
116        }
117
118        case SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION:
119        {
120            data.enforceInterface(IApplicationThread.descriptor);
121            Intent intent = Intent.CREATOR.createFromParcel(data);
122            IBinder b = data.readStrongBinder();
123            int ident = data.readInt();
124            ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
125            Bundle state = data.readBundle();
126            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
127            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
128            boolean notResumed = data.readInt() != 0;
129            boolean isForward = data.readInt() != 0;
130            scheduleLaunchActivity(intent, b, ident, info, state, ri, pi,
131                    notResumed, isForward);
132            return true;
133        }
134
135        case SCHEDULE_RELAUNCH_ACTIVITY_TRANSACTION:
136        {
137            data.enforceInterface(IApplicationThread.descriptor);
138            IBinder b = data.readStrongBinder();
139            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
140            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
141            int configChanges = data.readInt();
142            boolean notResumed = data.readInt() != 0;
143            Configuration config = null;
144            if (data.readInt() != 0) {
145                config = Configuration.CREATOR.createFromParcel(data);
146            }
147            scheduleRelaunchActivity(b, ri, pi, configChanges, notResumed, config);
148            return true;
149        }
150
151        case SCHEDULE_NEW_INTENT_TRANSACTION:
152        {
153            data.enforceInterface(IApplicationThread.descriptor);
154            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
155            IBinder b = data.readStrongBinder();
156            scheduleNewIntent(pi, b);
157            return true;
158        }
159
160        case SCHEDULE_FINISH_ACTIVITY_TRANSACTION:
161        {
162            data.enforceInterface(IApplicationThread.descriptor);
163            IBinder b = data.readStrongBinder();
164            boolean finishing = data.readInt() != 0;
165            int configChanges = data.readInt();
166            scheduleDestroyActivity(b, finishing, configChanges);
167            return true;
168        }
169
170        case SCHEDULE_RECEIVER_TRANSACTION:
171        {
172            data.enforceInterface(IApplicationThread.descriptor);
173            Intent intent = Intent.CREATOR.createFromParcel(data);
174            ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
175            int resultCode = data.readInt();
176            String resultData = data.readString();
177            Bundle resultExtras = data.readBundle();
178            boolean sync = data.readInt() != 0;
179            scheduleReceiver(intent, info, resultCode, resultData,
180                    resultExtras, sync);
181            return true;
182        }
183
184        case SCHEDULE_CREATE_SERVICE_TRANSACTION: {
185            data.enforceInterface(IApplicationThread.descriptor);
186            IBinder token = data.readStrongBinder();
187            ServiceInfo info = ServiceInfo.CREATOR.createFromParcel(data);
188            scheduleCreateService(token, info);
189            return true;
190        }
191
192        case SCHEDULE_BIND_SERVICE_TRANSACTION: {
193            data.enforceInterface(IApplicationThread.descriptor);
194            IBinder token = data.readStrongBinder();
195            Intent intent = Intent.CREATOR.createFromParcel(data);
196            boolean rebind = data.readInt() != 0;
197            scheduleBindService(token, intent, rebind);
198            return true;
199        }
200
201        case SCHEDULE_UNBIND_SERVICE_TRANSACTION: {
202            data.enforceInterface(IApplicationThread.descriptor);
203            IBinder token = data.readStrongBinder();
204            Intent intent = Intent.CREATOR.createFromParcel(data);
205            scheduleUnbindService(token, intent);
206            return true;
207        }
208
209        case SCHEDULE_SERVICE_ARGS_TRANSACTION:
210        {
211            data.enforceInterface(IApplicationThread.descriptor);
212            IBinder token = data.readStrongBinder();
213            int startId = data.readInt();
214            int fl = data.readInt();
215            Intent args;
216            if (data.readInt() != 0) {
217                args = Intent.CREATOR.createFromParcel(data);
218            } else {
219                args = null;
220            }
221            scheduleServiceArgs(token, startId, fl, args);
222            return true;
223        }
224
225        case SCHEDULE_STOP_SERVICE_TRANSACTION:
226        {
227            data.enforceInterface(IApplicationThread.descriptor);
228            IBinder token = data.readStrongBinder();
229            scheduleStopService(token);
230            return true;
231        }
232
233        case BIND_APPLICATION_TRANSACTION:
234        {
235            data.enforceInterface(IApplicationThread.descriptor);
236            String packageName = data.readString();
237            ApplicationInfo info =
238                ApplicationInfo.CREATOR.createFromParcel(data);
239            List<ProviderInfo> providers =
240                data.createTypedArrayList(ProviderInfo.CREATOR);
241            ComponentName testName = (data.readInt() != 0)
242                ? new ComponentName(data) : null;
243            String profileName = data.readString();
244            Bundle testArgs = data.readBundle();
245            IBinder binder = data.readStrongBinder();
246            IInstrumentationWatcher testWatcher = IInstrumentationWatcher.Stub.asInterface(binder);
247            int testMode = data.readInt();
248            boolean restrictedBackupMode = (data.readInt() != 0);
249            Configuration config = Configuration.CREATOR.createFromParcel(data);
250            HashMap<String, IBinder> services = data.readHashMap(null);
251            bindApplication(packageName, info,
252                            providers, testName, profileName,
253                            testArgs, testWatcher, testMode, restrictedBackupMode,
254                            config, services);
255            return true;
256        }
257
258        case SCHEDULE_EXIT_TRANSACTION:
259        {
260            data.enforceInterface(IApplicationThread.descriptor);
261            scheduleExit();
262            return true;
263        }
264
265        case SCHEDULE_SUICIDE_TRANSACTION:
266        {
267            data.enforceInterface(IApplicationThread.descriptor);
268            scheduleSuicide();
269            return true;
270        }
271
272        case REQUEST_THUMBNAIL_TRANSACTION:
273        {
274            data.enforceInterface(IApplicationThread.descriptor);
275            IBinder b = data.readStrongBinder();
276            requestThumbnail(b);
277            return true;
278        }
279
280        case SCHEDULE_CONFIGURATION_CHANGED_TRANSACTION:
281        {
282            data.enforceInterface(IApplicationThread.descriptor);
283            Configuration config = Configuration.CREATOR.createFromParcel(data);
284            scheduleConfigurationChanged(config);
285            return true;
286        }
287
288        case UPDATE_TIME_ZONE_TRANSACTION: {
289            data.enforceInterface(IApplicationThread.descriptor);
290            updateTimeZone();
291            return true;
292        }
293
294        case PROCESS_IN_BACKGROUND_TRANSACTION: {
295            data.enforceInterface(IApplicationThread.descriptor);
296            processInBackground();
297            return true;
298        }
299
300        case DUMP_SERVICE_TRANSACTION: {
301            data.enforceInterface(IApplicationThread.descriptor);
302            ParcelFileDescriptor fd = data.readFileDescriptor();
303            final IBinder service = data.readStrongBinder();
304            final String[] args = data.readStringArray();
305            if (fd != null) {
306                dumpService(fd.getFileDescriptor(), service, args);
307                try {
308                    fd.close();
309                } catch (IOException e) {
310                }
311            }
312            return true;
313        }
314
315        case SCHEDULE_REGISTERED_RECEIVER_TRANSACTION: {
316            data.enforceInterface(IApplicationThread.descriptor);
317            IIntentReceiver receiver = IIntentReceiver.Stub.asInterface(
318                    data.readStrongBinder());
319            Intent intent = Intent.CREATOR.createFromParcel(data);
320            int resultCode = data.readInt();
321            String dataStr = data.readString();
322            Bundle extras = data.readBundle();
323            boolean ordered = data.readInt() != 0;
324            boolean sticky = data.readInt() != 0;
325            scheduleRegisteredReceiver(receiver, intent,
326                    resultCode, dataStr, extras, ordered, sticky);
327            return true;
328        }
329
330        case SCHEDULE_LOW_MEMORY_TRANSACTION:
331        {
332            scheduleLowMemory();
333            return true;
334        }
335
336        case SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION:
337        {
338            data.enforceInterface(IApplicationThread.descriptor);
339            IBinder b = data.readStrongBinder();
340            scheduleActivityConfigurationChanged(b);
341            return true;
342        }
343
344        case REQUEST_PSS_TRANSACTION:
345        {
346            data.enforceInterface(IApplicationThread.descriptor);
347            requestPss();
348            return true;
349        }
350
351        case PROFILER_CONTROL_TRANSACTION:
352        {
353            data.enforceInterface(IApplicationThread.descriptor);
354            boolean start = data.readInt() != 0;
355            String path = data.readString();
356            ParcelFileDescriptor fd = data.readInt() != 0
357                    ? data.readFileDescriptor() : null;
358            profilerControl(start, path, fd);
359            return true;
360        }
361
362        case SET_SCHEDULING_GROUP_TRANSACTION:
363        {
364            data.enforceInterface(IApplicationThread.descriptor);
365            int group = data.readInt();
366            setSchedulingGroup(group);
367            return true;
368        }
369
370        case SCHEDULE_CREATE_BACKUP_AGENT_TRANSACTION:
371        {
372            data.enforceInterface(IApplicationThread.descriptor);
373            ApplicationInfo appInfo = ApplicationInfo.CREATOR.createFromParcel(data);
374            int backupMode = data.readInt();
375            scheduleCreateBackupAgent(appInfo, backupMode);
376            return true;
377        }
378
379        case SCHEDULE_DESTROY_BACKUP_AGENT_TRANSACTION:
380        {
381            data.enforceInterface(IApplicationThread.descriptor);
382            ApplicationInfo appInfo = ApplicationInfo.CREATOR.createFromParcel(data);
383            scheduleDestroyBackupAgent(appInfo);
384            return true;
385        }
386
387        case GET_MEMORY_INFO_TRANSACTION:
388        {
389            data.enforceInterface(IApplicationThread.descriptor);
390            Debug.MemoryInfo mi = new Debug.MemoryInfo();
391            getMemoryInfo(mi);
392            reply.writeNoException();
393            mi.writeToParcel(reply, 0);
394            return true;
395        }
396
397        case DISPATCH_PACKAGE_BROADCAST_TRANSACTION:
398        {
399            data.enforceInterface(IApplicationThread.descriptor);
400            int cmd = data.readInt();
401            String[] packages = data.readStringArray();
402            dispatchPackageBroadcast(cmd, packages);
403            return true;
404        }
405
406        case SCHEDULE_CRASH_TRANSACTION:
407        {
408            data.enforceInterface(IApplicationThread.descriptor);
409            String msg = data.readString();
410            scheduleCrash(msg);
411            return true;
412        }
413        }
414
415        return super.onTransact(code, data, reply, flags);
416    }
417
418    public IBinder asBinder()
419    {
420        return this;
421    }
422}
423
424class ApplicationThreadProxy implements IApplicationThread {
425    private final IBinder mRemote;
426
427    public ApplicationThreadProxy(IBinder remote) {
428        mRemote = remote;
429    }
430
431    public final IBinder asBinder() {
432        return mRemote;
433    }
434
435    public final void schedulePauseActivity(IBinder token, boolean finished,
436            boolean userLeaving, int configChanges) throws RemoteException {
437        Parcel data = Parcel.obtain();
438        data.writeInterfaceToken(IApplicationThread.descriptor);
439        data.writeStrongBinder(token);
440        data.writeInt(finished ? 1 : 0);
441        data.writeInt(userLeaving ? 1 :0);
442        data.writeInt(configChanges);
443        mRemote.transact(SCHEDULE_PAUSE_ACTIVITY_TRANSACTION, data, null,
444                IBinder.FLAG_ONEWAY);
445        data.recycle();
446    }
447
448    public final void scheduleStopActivity(IBinder token, boolean showWindow,
449            int configChanges) throws RemoteException {
450        Parcel data = Parcel.obtain();
451        data.writeInterfaceToken(IApplicationThread.descriptor);
452        data.writeStrongBinder(token);
453        data.writeInt(showWindow ? 1 : 0);
454        data.writeInt(configChanges);
455        mRemote.transact(SCHEDULE_STOP_ACTIVITY_TRANSACTION, data, null,
456                IBinder.FLAG_ONEWAY);
457        data.recycle();
458    }
459
460    public final void scheduleWindowVisibility(IBinder token,
461            boolean showWindow) throws RemoteException {
462        Parcel data = Parcel.obtain();
463        data.writeInterfaceToken(IApplicationThread.descriptor);
464        data.writeStrongBinder(token);
465        data.writeInt(showWindow ? 1 : 0);
466        mRemote.transact(SCHEDULE_WINDOW_VISIBILITY_TRANSACTION, data, null,
467                IBinder.FLAG_ONEWAY);
468        data.recycle();
469    }
470
471    public final void scheduleResumeActivity(IBinder token, boolean isForward)
472            throws RemoteException {
473        Parcel data = Parcel.obtain();
474        data.writeInterfaceToken(IApplicationThread.descriptor);
475        data.writeStrongBinder(token);
476        data.writeInt(isForward ? 1 : 0);
477        mRemote.transact(SCHEDULE_RESUME_ACTIVITY_TRANSACTION, data, null,
478                IBinder.FLAG_ONEWAY);
479        data.recycle();
480    }
481
482    public final void scheduleSendResult(IBinder token, List<ResultInfo> results)
483    		throws RemoteException {
484        Parcel data = Parcel.obtain();
485        data.writeInterfaceToken(IApplicationThread.descriptor);
486        data.writeStrongBinder(token);
487        data.writeTypedList(results);
488        mRemote.transact(SCHEDULE_SEND_RESULT_TRANSACTION, data, null,
489                IBinder.FLAG_ONEWAY);
490        data.recycle();
491    }
492
493    public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
494            ActivityInfo info, Bundle state, List<ResultInfo> pendingResults,
495    		List<Intent> pendingNewIntents, boolean notResumed, boolean isForward)
496    		throws RemoteException {
497        Parcel data = Parcel.obtain();
498        data.writeInterfaceToken(IApplicationThread.descriptor);
499        intent.writeToParcel(data, 0);
500        data.writeStrongBinder(token);
501        data.writeInt(ident);
502        info.writeToParcel(data, 0);
503        data.writeBundle(state);
504        data.writeTypedList(pendingResults);
505        data.writeTypedList(pendingNewIntents);
506        data.writeInt(notResumed ? 1 : 0);
507        data.writeInt(isForward ? 1 : 0);
508        mRemote.transact(SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION, data, null,
509                IBinder.FLAG_ONEWAY);
510        data.recycle();
511    }
512
513    public final void scheduleRelaunchActivity(IBinder token,
514            List<ResultInfo> pendingResults, List<Intent> pendingNewIntents,
515            int configChanges, boolean notResumed, Configuration config)
516            throws RemoteException {
517        Parcel data = Parcel.obtain();
518        data.writeInterfaceToken(IApplicationThread.descriptor);
519        data.writeStrongBinder(token);
520        data.writeTypedList(pendingResults);
521        data.writeTypedList(pendingNewIntents);
522        data.writeInt(configChanges);
523        data.writeInt(notResumed ? 1 : 0);
524        if (config != null) {
525            data.writeInt(1);
526            config.writeToParcel(data, 0);
527        } else {
528            data.writeInt(0);
529        }
530        mRemote.transact(SCHEDULE_RELAUNCH_ACTIVITY_TRANSACTION, data, null,
531                IBinder.FLAG_ONEWAY);
532        data.recycle();
533    }
534
535    public void scheduleNewIntent(List<Intent> intents, IBinder token)
536            throws RemoteException {
537        Parcel data = Parcel.obtain();
538        data.writeInterfaceToken(IApplicationThread.descriptor);
539        data.writeTypedList(intents);
540        data.writeStrongBinder(token);
541        mRemote.transact(SCHEDULE_NEW_INTENT_TRANSACTION, data, null,
542                IBinder.FLAG_ONEWAY);
543        data.recycle();
544    }
545
546    public final void scheduleDestroyActivity(IBinder token, boolean finishing,
547            int configChanges) throws RemoteException {
548        Parcel data = Parcel.obtain();
549        data.writeInterfaceToken(IApplicationThread.descriptor);
550        data.writeStrongBinder(token);
551        data.writeInt(finishing ? 1 : 0);
552        data.writeInt(configChanges);
553        mRemote.transact(SCHEDULE_FINISH_ACTIVITY_TRANSACTION, data, null,
554                IBinder.FLAG_ONEWAY);
555        data.recycle();
556    }
557
558    public final void scheduleReceiver(Intent intent, ActivityInfo info,
559            int resultCode, String resultData,
560            Bundle map, boolean sync) throws RemoteException {
561        Parcel data = Parcel.obtain();
562        data.writeInterfaceToken(IApplicationThread.descriptor);
563        intent.writeToParcel(data, 0);
564        info.writeToParcel(data, 0);
565        data.writeInt(resultCode);
566        data.writeString(resultData);
567        data.writeBundle(map);
568        data.writeInt(sync ? 1 : 0);
569        mRemote.transact(SCHEDULE_RECEIVER_TRANSACTION, data, null,
570                IBinder.FLAG_ONEWAY);
571        data.recycle();
572    }
573
574    public final void scheduleCreateBackupAgent(ApplicationInfo app, int backupMode)
575            throws RemoteException {
576        Parcel data = Parcel.obtain();
577        data.writeInterfaceToken(IApplicationThread.descriptor);
578        app.writeToParcel(data, 0);
579        data.writeInt(backupMode);
580        mRemote.transact(SCHEDULE_CREATE_BACKUP_AGENT_TRANSACTION, data, null,
581                IBinder.FLAG_ONEWAY);
582        data.recycle();
583    }
584
585    public final void scheduleDestroyBackupAgent(ApplicationInfo app) throws RemoteException {
586        Parcel data = Parcel.obtain();
587        data.writeInterfaceToken(IApplicationThread.descriptor);
588        app.writeToParcel(data, 0);
589        mRemote.transact(SCHEDULE_DESTROY_BACKUP_AGENT_TRANSACTION, data, null,
590                IBinder.FLAG_ONEWAY);
591        data.recycle();
592    }
593
594    public final void scheduleCreateService(IBinder token, ServiceInfo info)
595            throws RemoteException {
596        Parcel data = Parcel.obtain();
597        data.writeInterfaceToken(IApplicationThread.descriptor);
598        data.writeStrongBinder(token);
599        info.writeToParcel(data, 0);
600        mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
601                IBinder.FLAG_ONEWAY);
602        data.recycle();
603    }
604
605    public final void scheduleBindService(IBinder token, Intent intent, boolean rebind)
606            throws RemoteException {
607        Parcel data = Parcel.obtain();
608        data.writeInterfaceToken(IApplicationThread.descriptor);
609        data.writeStrongBinder(token);
610        intent.writeToParcel(data, 0);
611        data.writeInt(rebind ? 1 : 0);
612        mRemote.transact(SCHEDULE_BIND_SERVICE_TRANSACTION, data, null,
613                IBinder.FLAG_ONEWAY);
614        data.recycle();
615    }
616
617    public final void scheduleUnbindService(IBinder token, Intent intent)
618            throws RemoteException {
619        Parcel data = Parcel.obtain();
620        data.writeInterfaceToken(IApplicationThread.descriptor);
621        data.writeStrongBinder(token);
622        intent.writeToParcel(data, 0);
623        mRemote.transact(SCHEDULE_UNBIND_SERVICE_TRANSACTION, data, null,
624                IBinder.FLAG_ONEWAY);
625        data.recycle();
626    }
627
628    public final void scheduleServiceArgs(IBinder token, int startId,
629	    int flags, Intent args) throws RemoteException {
630        Parcel data = Parcel.obtain();
631        data.writeInterfaceToken(IApplicationThread.descriptor);
632        data.writeStrongBinder(token);
633        data.writeInt(startId);
634        data.writeInt(flags);
635        if (args != null) {
636            data.writeInt(1);
637            args.writeToParcel(data, 0);
638        } else {
639            data.writeInt(0);
640        }
641        mRemote.transact(SCHEDULE_SERVICE_ARGS_TRANSACTION, data, null,
642                IBinder.FLAG_ONEWAY);
643        data.recycle();
644    }
645
646    public final void scheduleStopService(IBinder token)
647            throws RemoteException {
648        Parcel data = Parcel.obtain();
649        data.writeInterfaceToken(IApplicationThread.descriptor);
650        data.writeStrongBinder(token);
651        mRemote.transact(SCHEDULE_STOP_SERVICE_TRANSACTION, data, null,
652                IBinder.FLAG_ONEWAY);
653        data.recycle();
654    }
655
656    public final void bindApplication(String packageName, ApplicationInfo info,
657            List<ProviderInfo> providers, ComponentName testName,
658            String profileName, Bundle testArgs, IInstrumentationWatcher testWatcher, int debugMode,
659            boolean restrictedBackupMode, Configuration config,
660            Map<String, IBinder> services) throws RemoteException {
661        Parcel data = Parcel.obtain();
662        data.writeInterfaceToken(IApplicationThread.descriptor);
663        data.writeString(packageName);
664        info.writeToParcel(data, 0);
665        data.writeTypedList(providers);
666        if (testName == null) {
667            data.writeInt(0);
668        } else {
669            data.writeInt(1);
670            testName.writeToParcel(data, 0);
671        }
672        data.writeString(profileName);
673        data.writeBundle(testArgs);
674        data.writeStrongInterface(testWatcher);
675        data.writeInt(debugMode);
676        data.writeInt(restrictedBackupMode ? 1 : 0);
677        config.writeToParcel(data, 0);
678        data.writeMap(services);
679        mRemote.transact(BIND_APPLICATION_TRANSACTION, data, null,
680                IBinder.FLAG_ONEWAY);
681        data.recycle();
682    }
683
684    public final void scheduleExit() throws RemoteException {
685        Parcel data = Parcel.obtain();
686        data.writeInterfaceToken(IApplicationThread.descriptor);
687        mRemote.transact(SCHEDULE_EXIT_TRANSACTION, data, null,
688                IBinder.FLAG_ONEWAY);
689        data.recycle();
690    }
691
692    public final void scheduleSuicide() throws RemoteException {
693        Parcel data = Parcel.obtain();
694        data.writeInterfaceToken(IApplicationThread.descriptor);
695        mRemote.transact(SCHEDULE_SUICIDE_TRANSACTION, data, null,
696                IBinder.FLAG_ONEWAY);
697        data.recycle();
698    }
699
700    public final void requestThumbnail(IBinder token)
701            throws RemoteException {
702        Parcel data = Parcel.obtain();
703        data.writeInterfaceToken(IApplicationThread.descriptor);
704        data.writeStrongBinder(token);
705        mRemote.transact(REQUEST_THUMBNAIL_TRANSACTION, data, null,
706                IBinder.FLAG_ONEWAY);
707        data.recycle();
708    }
709
710    public final void scheduleConfigurationChanged(Configuration config)
711            throws RemoteException {
712        Parcel data = Parcel.obtain();
713        data.writeInterfaceToken(IApplicationThread.descriptor);
714        config.writeToParcel(data, 0);
715        mRemote.transact(SCHEDULE_CONFIGURATION_CHANGED_TRANSACTION, data, null,
716                IBinder.FLAG_ONEWAY);
717        data.recycle();
718    }
719
720    public void updateTimeZone() throws RemoteException {
721        Parcel data = Parcel.obtain();
722        data.writeInterfaceToken(IApplicationThread.descriptor);
723        mRemote.transact(UPDATE_TIME_ZONE_TRANSACTION, data, null,
724                IBinder.FLAG_ONEWAY);
725        data.recycle();
726    }
727
728    public void processInBackground() throws RemoteException {
729        Parcel data = Parcel.obtain();
730        data.writeInterfaceToken(IApplicationThread.descriptor);
731        mRemote.transact(PROCESS_IN_BACKGROUND_TRANSACTION, data, null,
732                IBinder.FLAG_ONEWAY);
733        data.recycle();
734    }
735
736    public void dumpService(FileDescriptor fd, IBinder token, String[] args)
737            throws RemoteException {
738        Parcel data = Parcel.obtain();
739        data.writeInterfaceToken(IApplicationThread.descriptor);
740        data.writeFileDescriptor(fd);
741        data.writeStrongBinder(token);
742        data.writeStringArray(args);
743        mRemote.transact(DUMP_SERVICE_TRANSACTION, data, null, 0);
744        data.recycle();
745    }
746
747    public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent,
748            int resultCode, String dataStr, Bundle extras, boolean ordered, boolean sticky)
749            throws RemoteException {
750        Parcel data = Parcel.obtain();
751        data.writeInterfaceToken(IApplicationThread.descriptor);
752        data.writeStrongBinder(receiver.asBinder());
753        intent.writeToParcel(data, 0);
754        data.writeInt(resultCode);
755        data.writeString(dataStr);
756        data.writeBundle(extras);
757        data.writeInt(ordered ? 1 : 0);
758        data.writeInt(sticky ? 1 : 0);
759        mRemote.transact(SCHEDULE_REGISTERED_RECEIVER_TRANSACTION, data, null,
760                IBinder.FLAG_ONEWAY);
761        data.recycle();
762    }
763
764    public final void scheduleLowMemory() throws RemoteException {
765        Parcel data = Parcel.obtain();
766        data.writeInterfaceToken(IApplicationThread.descriptor);
767        mRemote.transact(SCHEDULE_LOW_MEMORY_TRANSACTION, data, null,
768                IBinder.FLAG_ONEWAY);
769        data.recycle();
770    }
771
772    public final void scheduleActivityConfigurationChanged(
773            IBinder token) throws RemoteException {
774        Parcel data = Parcel.obtain();
775        data.writeInterfaceToken(IApplicationThread.descriptor);
776        data.writeStrongBinder(token);
777        mRemote.transact(SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION, data, null,
778                IBinder.FLAG_ONEWAY);
779        data.recycle();
780    }
781
782    public final void requestPss() throws RemoteException {
783        Parcel data = Parcel.obtain();
784        data.writeInterfaceToken(IApplicationThread.descriptor);
785        mRemote.transact(REQUEST_PSS_TRANSACTION, data, null,
786                IBinder.FLAG_ONEWAY);
787        data.recycle();
788    }
789
790    public void profilerControl(boolean start, String path,
791            ParcelFileDescriptor fd) throws RemoteException {
792        Parcel data = Parcel.obtain();
793        data.writeInterfaceToken(IApplicationThread.descriptor);
794        data.writeInt(start ? 1 : 0);
795        data.writeString(path);
796        if (fd != null) {
797            data.writeInt(1);
798            fd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
799        } else {
800            data.writeInt(0);
801        }
802        mRemote.transact(PROFILER_CONTROL_TRANSACTION, data, null,
803                IBinder.FLAG_ONEWAY);
804        data.recycle();
805    }
806
807    public void setSchedulingGroup(int group) throws RemoteException {
808        Parcel data = Parcel.obtain();
809        data.writeInterfaceToken(IApplicationThread.descriptor);
810        data.writeInt(group);
811        mRemote.transact(SET_SCHEDULING_GROUP_TRANSACTION, data, null,
812                IBinder.FLAG_ONEWAY);
813        data.recycle();
814    }
815
816    public void getMemoryInfo(Debug.MemoryInfo outInfo) throws RemoteException {
817        Parcel data = Parcel.obtain();
818        Parcel reply = Parcel.obtain();
819        data.writeInterfaceToken(IApplicationThread.descriptor);
820        mRemote.transact(GET_MEMORY_INFO_TRANSACTION, data, reply, 0);
821        reply.readException();
822        outInfo.readFromParcel(reply);
823        data.recycle();
824        reply.recycle();
825    }
826
827    public void dispatchPackageBroadcast(int cmd, String[] packages) throws RemoteException {
828        Parcel data = Parcel.obtain();
829        data.writeInterfaceToken(IApplicationThread.descriptor);
830        data.writeInt(cmd);
831        data.writeStringArray(packages);
832        mRemote.transact(DISPATCH_PACKAGE_BROADCAST_TRANSACTION, data, null,
833                IBinder.FLAG_ONEWAY);
834        data.recycle();
835
836    }
837
838    public void scheduleCrash(String msg) throws RemoteException {
839        Parcel data = Parcel.obtain();
840        data.writeInterfaceToken(IApplicationThread.descriptor);
841        data.writeString(msg);
842        mRemote.transact(SCHEDULE_CRASH_TRANSACTION, data, null,
843                IBinder.FLAG_ONEWAY);
844        data.recycle();
845
846    }
847}
848
849