ApplicationThreadNative.java revision 54d068ec6af0ee6d261a135400efe6816c6f5ffe
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_SLEEPING_TRANSACTION:
101        {
102            data.enforceInterface(IApplicationThread.descriptor);
103            IBinder b = data.readStrongBinder();
104            boolean sleeping = data.readInt() != 0;
105            scheduleSleeping(b, sleeping);
106            return true;
107        }
108
109        case SCHEDULE_RESUME_ACTIVITY_TRANSACTION:
110        {
111            data.enforceInterface(IApplicationThread.descriptor);
112            IBinder b = data.readStrongBinder();
113            boolean isForward = data.readInt() != 0;
114            scheduleResumeActivity(b, isForward);
115            return true;
116        }
117
118        case SCHEDULE_SEND_RESULT_TRANSACTION:
119        {
120            data.enforceInterface(IApplicationThread.descriptor);
121            IBinder b = data.readStrongBinder();
122            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
123            scheduleSendResult(b, ri);
124            return true;
125        }
126
127        case SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION:
128        {
129            data.enforceInterface(IApplicationThread.descriptor);
130            Intent intent = Intent.CREATOR.createFromParcel(data);
131            IBinder b = data.readStrongBinder();
132            int ident = data.readInt();
133            ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
134            Bundle state = data.readBundle();
135            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
136            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
137            boolean notResumed = data.readInt() != 0;
138            boolean isForward = data.readInt() != 0;
139            scheduleLaunchActivity(intent, b, ident, info, state, ri, pi,
140                    notResumed, isForward);
141            return true;
142        }
143
144        case SCHEDULE_RELAUNCH_ACTIVITY_TRANSACTION:
145        {
146            data.enforceInterface(IApplicationThread.descriptor);
147            IBinder b = data.readStrongBinder();
148            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
149            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
150            int configChanges = data.readInt();
151            boolean notResumed = data.readInt() != 0;
152            Configuration config = null;
153            if (data.readInt() != 0) {
154                config = Configuration.CREATOR.createFromParcel(data);
155            }
156            scheduleRelaunchActivity(b, ri, pi, configChanges, notResumed, config);
157            return true;
158        }
159
160        case SCHEDULE_NEW_INTENT_TRANSACTION:
161        {
162            data.enforceInterface(IApplicationThread.descriptor);
163            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
164            IBinder b = data.readStrongBinder();
165            scheduleNewIntent(pi, b);
166            return true;
167        }
168
169        case SCHEDULE_FINISH_ACTIVITY_TRANSACTION:
170        {
171            data.enforceInterface(IApplicationThread.descriptor);
172            IBinder b = data.readStrongBinder();
173            boolean finishing = data.readInt() != 0;
174            int configChanges = data.readInt();
175            scheduleDestroyActivity(b, finishing, configChanges);
176            return true;
177        }
178
179        case SCHEDULE_RECEIVER_TRANSACTION:
180        {
181            data.enforceInterface(IApplicationThread.descriptor);
182            Intent intent = Intent.CREATOR.createFromParcel(data);
183            ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
184            int resultCode = data.readInt();
185            String resultData = data.readString();
186            Bundle resultExtras = data.readBundle();
187            boolean sync = data.readInt() != 0;
188            scheduleReceiver(intent, info, resultCode, resultData,
189                    resultExtras, sync);
190            return true;
191        }
192
193        case SCHEDULE_CREATE_SERVICE_TRANSACTION: {
194            data.enforceInterface(IApplicationThread.descriptor);
195            IBinder token = data.readStrongBinder();
196            ServiceInfo info = ServiceInfo.CREATOR.createFromParcel(data);
197            scheduleCreateService(token, info);
198            return true;
199        }
200
201        case SCHEDULE_BIND_SERVICE_TRANSACTION: {
202            data.enforceInterface(IApplicationThread.descriptor);
203            IBinder token = data.readStrongBinder();
204            Intent intent = Intent.CREATOR.createFromParcel(data);
205            boolean rebind = data.readInt() != 0;
206            scheduleBindService(token, intent, rebind);
207            return true;
208        }
209
210        case SCHEDULE_UNBIND_SERVICE_TRANSACTION: {
211            data.enforceInterface(IApplicationThread.descriptor);
212            IBinder token = data.readStrongBinder();
213            Intent intent = Intent.CREATOR.createFromParcel(data);
214            scheduleUnbindService(token, intent);
215            return true;
216        }
217
218        case SCHEDULE_SERVICE_ARGS_TRANSACTION:
219        {
220            data.enforceInterface(IApplicationThread.descriptor);
221            IBinder token = data.readStrongBinder();
222            int startId = data.readInt();
223            int fl = data.readInt();
224            Intent args;
225            if (data.readInt() != 0) {
226                args = Intent.CREATOR.createFromParcel(data);
227            } else {
228                args = null;
229            }
230            scheduleServiceArgs(token, startId, fl, args);
231            return true;
232        }
233
234        case SCHEDULE_STOP_SERVICE_TRANSACTION:
235        {
236            data.enforceInterface(IApplicationThread.descriptor);
237            IBinder token = data.readStrongBinder();
238            scheduleStopService(token);
239            return true;
240        }
241
242        case BIND_APPLICATION_TRANSACTION:
243        {
244            data.enforceInterface(IApplicationThread.descriptor);
245            String packageName = data.readString();
246            ApplicationInfo info =
247                ApplicationInfo.CREATOR.createFromParcel(data);
248            List<ProviderInfo> providers =
249                data.createTypedArrayList(ProviderInfo.CREATOR);
250            ComponentName testName = (data.readInt() != 0)
251                ? new ComponentName(data) : null;
252            String profileName = data.readString();
253            Bundle testArgs = data.readBundle();
254            IBinder binder = data.readStrongBinder();
255            IInstrumentationWatcher testWatcher = IInstrumentationWatcher.Stub.asInterface(binder);
256            int testMode = data.readInt();
257            boolean restrictedBackupMode = (data.readInt() != 0);
258            Configuration config = Configuration.CREATOR.createFromParcel(data);
259            HashMap<String, IBinder> services = data.readHashMap(null);
260            Bundle coreSettings = data.readBundle();
261            bindApplication(packageName, info,
262                            providers, testName, profileName,
263                            testArgs, testWatcher, testMode, restrictedBackupMode,
264                            config, services, coreSettings);
265            return true;
266        }
267
268        case SCHEDULE_EXIT_TRANSACTION:
269        {
270            data.enforceInterface(IApplicationThread.descriptor);
271            scheduleExit();
272            return true;
273        }
274
275        case SCHEDULE_SUICIDE_TRANSACTION:
276        {
277            data.enforceInterface(IApplicationThread.descriptor);
278            scheduleSuicide();
279            return true;
280        }
281
282        case REQUEST_THUMBNAIL_TRANSACTION:
283        {
284            data.enforceInterface(IApplicationThread.descriptor);
285            IBinder b = data.readStrongBinder();
286            requestThumbnail(b);
287            return true;
288        }
289
290        case SCHEDULE_CONFIGURATION_CHANGED_TRANSACTION:
291        {
292            data.enforceInterface(IApplicationThread.descriptor);
293            Configuration config = Configuration.CREATOR.createFromParcel(data);
294            scheduleConfigurationChanged(config);
295            return true;
296        }
297
298        case UPDATE_TIME_ZONE_TRANSACTION: {
299            data.enforceInterface(IApplicationThread.descriptor);
300            updateTimeZone();
301            return true;
302        }
303
304        case CLEAR_DNS_CACHE_TRANSACTION: {
305            data.enforceInterface(IApplicationThread.descriptor);
306            clearDnsCache();
307            return true;
308        }
309
310        case SET_HTTP_PROXY_TRANSACTION: {
311            data.enforceInterface(IApplicationThread.descriptor);
312            final String proxy = data.readString();
313            final String port = data.readString();
314            final String exclList = data.readString();
315            setHttpProxy(proxy, port, exclList);
316            return true;
317        }
318
319        case PROCESS_IN_BACKGROUND_TRANSACTION: {
320            data.enforceInterface(IApplicationThread.descriptor);
321            processInBackground();
322            return true;
323        }
324
325        case DUMP_SERVICE_TRANSACTION: {
326            data.enforceInterface(IApplicationThread.descriptor);
327            ParcelFileDescriptor fd = data.readFileDescriptor();
328            final IBinder service = data.readStrongBinder();
329            final String[] args = data.readStringArray();
330            if (fd != null) {
331                dumpService(fd.getFileDescriptor(), service, args);
332                try {
333                    fd.close();
334                } catch (IOException e) {
335                }
336            }
337            return true;
338        }
339
340        case SCHEDULE_REGISTERED_RECEIVER_TRANSACTION: {
341            data.enforceInterface(IApplicationThread.descriptor);
342            IIntentReceiver receiver = IIntentReceiver.Stub.asInterface(
343                    data.readStrongBinder());
344            Intent intent = Intent.CREATOR.createFromParcel(data);
345            int resultCode = data.readInt();
346            String dataStr = data.readString();
347            Bundle extras = data.readBundle();
348            boolean ordered = data.readInt() != 0;
349            boolean sticky = data.readInt() != 0;
350            scheduleRegisteredReceiver(receiver, intent,
351                    resultCode, dataStr, extras, ordered, sticky);
352            return true;
353        }
354
355        case SCHEDULE_LOW_MEMORY_TRANSACTION:
356        {
357            scheduleLowMemory();
358            return true;
359        }
360
361        case SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION:
362        {
363            data.enforceInterface(IApplicationThread.descriptor);
364            IBinder b = data.readStrongBinder();
365            scheduleActivityConfigurationChanged(b);
366            return true;
367        }
368
369        case PROFILER_CONTROL_TRANSACTION:
370        {
371            data.enforceInterface(IApplicationThread.descriptor);
372            boolean start = data.readInt() != 0;
373            String path = data.readString();
374            ParcelFileDescriptor fd = data.readInt() != 0
375                    ? data.readFileDescriptor() : null;
376            profilerControl(start, path, fd);
377            return true;
378        }
379
380        case SET_SCHEDULING_GROUP_TRANSACTION:
381        {
382            data.enforceInterface(IApplicationThread.descriptor);
383            int group = data.readInt();
384            setSchedulingGroup(group);
385            return true;
386        }
387
388        case SCHEDULE_CREATE_BACKUP_AGENT_TRANSACTION:
389        {
390            data.enforceInterface(IApplicationThread.descriptor);
391            ApplicationInfo appInfo = ApplicationInfo.CREATOR.createFromParcel(data);
392            int backupMode = data.readInt();
393            scheduleCreateBackupAgent(appInfo, backupMode);
394            return true;
395        }
396
397        case SCHEDULE_DESTROY_BACKUP_AGENT_TRANSACTION:
398        {
399            data.enforceInterface(IApplicationThread.descriptor);
400            ApplicationInfo appInfo = ApplicationInfo.CREATOR.createFromParcel(data);
401            scheduleDestroyBackupAgent(appInfo);
402            return true;
403        }
404
405        case GET_MEMORY_INFO_TRANSACTION:
406        {
407            data.enforceInterface(IApplicationThread.descriptor);
408            Debug.MemoryInfo mi = new Debug.MemoryInfo();
409            getMemoryInfo(mi);
410            reply.writeNoException();
411            mi.writeToParcel(reply, 0);
412            return true;
413        }
414
415        case DISPATCH_PACKAGE_BROADCAST_TRANSACTION:
416        {
417            data.enforceInterface(IApplicationThread.descriptor);
418            int cmd = data.readInt();
419            String[] packages = data.readStringArray();
420            dispatchPackageBroadcast(cmd, packages);
421            return true;
422        }
423
424        case SCHEDULE_CRASH_TRANSACTION:
425        {
426            data.enforceInterface(IApplicationThread.descriptor);
427            String msg = data.readString();
428            scheduleCrash(msg);
429            return true;
430        }
431
432        case DUMP_HEAP_TRANSACTION:
433        {
434            data.enforceInterface(IApplicationThread.descriptor);
435            boolean managed = data.readInt() != 0;
436            String path = data.readString();
437            ParcelFileDescriptor fd = data.readInt() != 0
438                    ? data.readFileDescriptor() : null;
439            dumpHeap(managed, path, fd);
440            return true;
441        }
442
443        case DUMP_ACTIVITY_TRANSACTION: {
444            data.enforceInterface(IApplicationThread.descriptor);
445            ParcelFileDescriptor fd = data.readFileDescriptor();
446            final IBinder activity = data.readStrongBinder();
447            final String prefix = data.readString();
448            final String[] args = data.readStringArray();
449            if (fd != null) {
450                dumpActivity(fd.getFileDescriptor(), activity, prefix, args);
451                try {
452                    fd.close();
453                } catch (IOException e) {
454                }
455            }
456            return true;
457        }
458
459        case SET_CORE_SETTINGS: {
460            data.enforceInterface(IApplicationThread.descriptor);
461            Bundle settings = data.readBundle();
462            setCoreSettings(settings);
463            return true;
464        }
465        }
466
467        return super.onTransact(code, data, reply, flags);
468    }
469
470    public IBinder asBinder()
471    {
472        return this;
473    }
474}
475
476class ApplicationThreadProxy implements IApplicationThread {
477    private final IBinder mRemote;
478
479    public ApplicationThreadProxy(IBinder remote) {
480        mRemote = remote;
481    }
482
483    public final IBinder asBinder() {
484        return mRemote;
485    }
486
487    public final void schedulePauseActivity(IBinder token, boolean finished,
488            boolean userLeaving, int configChanges) throws RemoteException {
489        Parcel data = Parcel.obtain();
490        data.writeInterfaceToken(IApplicationThread.descriptor);
491        data.writeStrongBinder(token);
492        data.writeInt(finished ? 1 : 0);
493        data.writeInt(userLeaving ? 1 :0);
494        data.writeInt(configChanges);
495        mRemote.transact(SCHEDULE_PAUSE_ACTIVITY_TRANSACTION, data, null,
496                IBinder.FLAG_ONEWAY);
497        data.recycle();
498    }
499
500    public final void scheduleStopActivity(IBinder token, boolean showWindow,
501            int configChanges) throws RemoteException {
502        Parcel data = Parcel.obtain();
503        data.writeInterfaceToken(IApplicationThread.descriptor);
504        data.writeStrongBinder(token);
505        data.writeInt(showWindow ? 1 : 0);
506        data.writeInt(configChanges);
507        mRemote.transact(SCHEDULE_STOP_ACTIVITY_TRANSACTION, data, null,
508                IBinder.FLAG_ONEWAY);
509        data.recycle();
510    }
511
512    public final void scheduleWindowVisibility(IBinder token,
513            boolean showWindow) throws RemoteException {
514        Parcel data = Parcel.obtain();
515        data.writeInterfaceToken(IApplicationThread.descriptor);
516        data.writeStrongBinder(token);
517        data.writeInt(showWindow ? 1 : 0);
518        mRemote.transact(SCHEDULE_WINDOW_VISIBILITY_TRANSACTION, data, null,
519                IBinder.FLAG_ONEWAY);
520        data.recycle();
521    }
522
523    public final void scheduleSleeping(IBinder token,
524            boolean sleeping) throws RemoteException {
525        Parcel data = Parcel.obtain();
526        data.writeInterfaceToken(IApplicationThread.descriptor);
527        data.writeStrongBinder(token);
528        data.writeInt(sleeping ? 1 : 0);
529        mRemote.transact(SCHEDULE_SLEEPING_TRANSACTION, data, null,
530                IBinder.FLAG_ONEWAY);
531        data.recycle();
532    }
533
534    public final void scheduleResumeActivity(IBinder token, boolean isForward)
535            throws RemoteException {
536        Parcel data = Parcel.obtain();
537        data.writeInterfaceToken(IApplicationThread.descriptor);
538        data.writeStrongBinder(token);
539        data.writeInt(isForward ? 1 : 0);
540        mRemote.transact(SCHEDULE_RESUME_ACTIVITY_TRANSACTION, data, null,
541                IBinder.FLAG_ONEWAY);
542        data.recycle();
543    }
544
545    public final void scheduleSendResult(IBinder token, List<ResultInfo> results)
546    		throws RemoteException {
547        Parcel data = Parcel.obtain();
548        data.writeInterfaceToken(IApplicationThread.descriptor);
549        data.writeStrongBinder(token);
550        data.writeTypedList(results);
551        mRemote.transact(SCHEDULE_SEND_RESULT_TRANSACTION, data, null,
552                IBinder.FLAG_ONEWAY);
553        data.recycle();
554    }
555
556    public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
557            ActivityInfo info, Bundle state, List<ResultInfo> pendingResults,
558    		List<Intent> pendingNewIntents, boolean notResumed, boolean isForward)
559    		throws RemoteException {
560        Parcel data = Parcel.obtain();
561        data.writeInterfaceToken(IApplicationThread.descriptor);
562        intent.writeToParcel(data, 0);
563        data.writeStrongBinder(token);
564        data.writeInt(ident);
565        info.writeToParcel(data, 0);
566        data.writeBundle(state);
567        data.writeTypedList(pendingResults);
568        data.writeTypedList(pendingNewIntents);
569        data.writeInt(notResumed ? 1 : 0);
570        data.writeInt(isForward ? 1 : 0);
571        mRemote.transact(SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION, data, null,
572                IBinder.FLAG_ONEWAY);
573        data.recycle();
574    }
575
576    public final void scheduleRelaunchActivity(IBinder token,
577            List<ResultInfo> pendingResults, List<Intent> pendingNewIntents,
578            int configChanges, boolean notResumed, Configuration config)
579            throws RemoteException {
580        Parcel data = Parcel.obtain();
581        data.writeInterfaceToken(IApplicationThread.descriptor);
582        data.writeStrongBinder(token);
583        data.writeTypedList(pendingResults);
584        data.writeTypedList(pendingNewIntents);
585        data.writeInt(configChanges);
586        data.writeInt(notResumed ? 1 : 0);
587        if (config != null) {
588            data.writeInt(1);
589            config.writeToParcel(data, 0);
590        } else {
591            data.writeInt(0);
592        }
593        mRemote.transact(SCHEDULE_RELAUNCH_ACTIVITY_TRANSACTION, data, null,
594                IBinder.FLAG_ONEWAY);
595        data.recycle();
596    }
597
598    public void scheduleNewIntent(List<Intent> intents, IBinder token)
599            throws RemoteException {
600        Parcel data = Parcel.obtain();
601        data.writeInterfaceToken(IApplicationThread.descriptor);
602        data.writeTypedList(intents);
603        data.writeStrongBinder(token);
604        mRemote.transact(SCHEDULE_NEW_INTENT_TRANSACTION, data, null,
605                IBinder.FLAG_ONEWAY);
606        data.recycle();
607    }
608
609    public final void scheduleDestroyActivity(IBinder token, boolean finishing,
610            int configChanges) throws RemoteException {
611        Parcel data = Parcel.obtain();
612        data.writeInterfaceToken(IApplicationThread.descriptor);
613        data.writeStrongBinder(token);
614        data.writeInt(finishing ? 1 : 0);
615        data.writeInt(configChanges);
616        mRemote.transact(SCHEDULE_FINISH_ACTIVITY_TRANSACTION, data, null,
617                IBinder.FLAG_ONEWAY);
618        data.recycle();
619    }
620
621    public final void scheduleReceiver(Intent intent, ActivityInfo info,
622            int resultCode, String resultData,
623            Bundle map, boolean sync) throws RemoteException {
624        Parcel data = Parcel.obtain();
625        data.writeInterfaceToken(IApplicationThread.descriptor);
626        intent.writeToParcel(data, 0);
627        info.writeToParcel(data, 0);
628        data.writeInt(resultCode);
629        data.writeString(resultData);
630        data.writeBundle(map);
631        data.writeInt(sync ? 1 : 0);
632        mRemote.transact(SCHEDULE_RECEIVER_TRANSACTION, data, null,
633                IBinder.FLAG_ONEWAY);
634        data.recycle();
635    }
636
637    public final void scheduleCreateBackupAgent(ApplicationInfo app, int backupMode)
638            throws RemoteException {
639        Parcel data = Parcel.obtain();
640        data.writeInterfaceToken(IApplicationThread.descriptor);
641        app.writeToParcel(data, 0);
642        data.writeInt(backupMode);
643        mRemote.transact(SCHEDULE_CREATE_BACKUP_AGENT_TRANSACTION, data, null,
644                IBinder.FLAG_ONEWAY);
645        data.recycle();
646    }
647
648    public final void scheduleDestroyBackupAgent(ApplicationInfo app) throws RemoteException {
649        Parcel data = Parcel.obtain();
650        data.writeInterfaceToken(IApplicationThread.descriptor);
651        app.writeToParcel(data, 0);
652        mRemote.transact(SCHEDULE_DESTROY_BACKUP_AGENT_TRANSACTION, data, null,
653                IBinder.FLAG_ONEWAY);
654        data.recycle();
655    }
656
657    public final void scheduleCreateService(IBinder token, ServiceInfo info)
658            throws RemoteException {
659        Parcel data = Parcel.obtain();
660        data.writeInterfaceToken(IApplicationThread.descriptor);
661        data.writeStrongBinder(token);
662        info.writeToParcel(data, 0);
663        mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
664                IBinder.FLAG_ONEWAY);
665        data.recycle();
666    }
667
668    public final void scheduleBindService(IBinder token, Intent intent, boolean rebind)
669            throws RemoteException {
670        Parcel data = Parcel.obtain();
671        data.writeInterfaceToken(IApplicationThread.descriptor);
672        data.writeStrongBinder(token);
673        intent.writeToParcel(data, 0);
674        data.writeInt(rebind ? 1 : 0);
675        mRemote.transact(SCHEDULE_BIND_SERVICE_TRANSACTION, data, null,
676                IBinder.FLAG_ONEWAY);
677        data.recycle();
678    }
679
680    public final void scheduleUnbindService(IBinder token, Intent intent)
681            throws RemoteException {
682        Parcel data = Parcel.obtain();
683        data.writeInterfaceToken(IApplicationThread.descriptor);
684        data.writeStrongBinder(token);
685        intent.writeToParcel(data, 0);
686        mRemote.transact(SCHEDULE_UNBIND_SERVICE_TRANSACTION, data, null,
687                IBinder.FLAG_ONEWAY);
688        data.recycle();
689    }
690
691    public final void scheduleServiceArgs(IBinder token, int startId,
692	    int flags, Intent args) throws RemoteException {
693        Parcel data = Parcel.obtain();
694        data.writeInterfaceToken(IApplicationThread.descriptor);
695        data.writeStrongBinder(token);
696        data.writeInt(startId);
697        data.writeInt(flags);
698        if (args != null) {
699            data.writeInt(1);
700            args.writeToParcel(data, 0);
701        } else {
702            data.writeInt(0);
703        }
704        mRemote.transact(SCHEDULE_SERVICE_ARGS_TRANSACTION, data, null,
705                IBinder.FLAG_ONEWAY);
706        data.recycle();
707    }
708
709    public final void scheduleStopService(IBinder token)
710            throws RemoteException {
711        Parcel data = Parcel.obtain();
712        data.writeInterfaceToken(IApplicationThread.descriptor);
713        data.writeStrongBinder(token);
714        mRemote.transact(SCHEDULE_STOP_SERVICE_TRANSACTION, data, null,
715                IBinder.FLAG_ONEWAY);
716        data.recycle();
717    }
718
719    public final void bindApplication(String packageName, ApplicationInfo info,
720            List<ProviderInfo> providers, ComponentName testName,
721            String profileName, Bundle testArgs, IInstrumentationWatcher testWatcher, int debugMode,
722            boolean restrictedBackupMode, Configuration config,
723            Map<String, IBinder> services, Bundle coreSettings) throws RemoteException {
724        Parcel data = Parcel.obtain();
725        data.writeInterfaceToken(IApplicationThread.descriptor);
726        data.writeString(packageName);
727        info.writeToParcel(data, 0);
728        data.writeTypedList(providers);
729        if (testName == null) {
730            data.writeInt(0);
731        } else {
732            data.writeInt(1);
733            testName.writeToParcel(data, 0);
734        }
735        data.writeString(profileName);
736        data.writeBundle(testArgs);
737        data.writeStrongInterface(testWatcher);
738        data.writeInt(debugMode);
739        data.writeInt(restrictedBackupMode ? 1 : 0);
740        config.writeToParcel(data, 0);
741        data.writeMap(services);
742        data.writeBundle(coreSettings);
743        mRemote.transact(BIND_APPLICATION_TRANSACTION, data, null,
744                IBinder.FLAG_ONEWAY);
745        data.recycle();
746    }
747
748    public final void scheduleExit() throws RemoteException {
749        Parcel data = Parcel.obtain();
750        data.writeInterfaceToken(IApplicationThread.descriptor);
751        mRemote.transact(SCHEDULE_EXIT_TRANSACTION, data, null,
752                IBinder.FLAG_ONEWAY);
753        data.recycle();
754    }
755
756    public final void scheduleSuicide() throws RemoteException {
757        Parcel data = Parcel.obtain();
758        data.writeInterfaceToken(IApplicationThread.descriptor);
759        mRemote.transact(SCHEDULE_SUICIDE_TRANSACTION, data, null,
760                IBinder.FLAG_ONEWAY);
761        data.recycle();
762    }
763
764    public final void requestThumbnail(IBinder token)
765            throws RemoteException {
766        Parcel data = Parcel.obtain();
767        data.writeInterfaceToken(IApplicationThread.descriptor);
768        data.writeStrongBinder(token);
769        mRemote.transact(REQUEST_THUMBNAIL_TRANSACTION, data, null,
770                IBinder.FLAG_ONEWAY);
771        data.recycle();
772    }
773
774    public final void scheduleConfigurationChanged(Configuration config)
775            throws RemoteException {
776        Parcel data = Parcel.obtain();
777        data.writeInterfaceToken(IApplicationThread.descriptor);
778        config.writeToParcel(data, 0);
779        mRemote.transact(SCHEDULE_CONFIGURATION_CHANGED_TRANSACTION, data, null,
780                IBinder.FLAG_ONEWAY);
781        data.recycle();
782    }
783
784    public void updateTimeZone() throws RemoteException {
785        Parcel data = Parcel.obtain();
786        data.writeInterfaceToken(IApplicationThread.descriptor);
787        mRemote.transact(UPDATE_TIME_ZONE_TRANSACTION, data, null,
788                IBinder.FLAG_ONEWAY);
789        data.recycle();
790    }
791
792    public void clearDnsCache() throws RemoteException {
793        Parcel data = Parcel.obtain();
794        data.writeInterfaceToken(IApplicationThread.descriptor);
795        mRemote.transact(CLEAR_DNS_CACHE_TRANSACTION, data, null,
796                IBinder.FLAG_ONEWAY);
797        data.recycle();
798    }
799
800    public void setHttpProxy(String proxy, String port, String exclList) throws RemoteException {
801        Parcel data = Parcel.obtain();
802        data.writeInterfaceToken(IApplicationThread.descriptor);
803        data.writeString(proxy);
804        data.writeString(port);
805        data.writeString(exclList);
806        mRemote.transact(SET_HTTP_PROXY_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
807        data.recycle();
808    }
809
810    public void processInBackground() throws RemoteException {
811        Parcel data = Parcel.obtain();
812        data.writeInterfaceToken(IApplicationThread.descriptor);
813        mRemote.transact(PROCESS_IN_BACKGROUND_TRANSACTION, data, null,
814                IBinder.FLAG_ONEWAY);
815        data.recycle();
816    }
817
818    public void dumpService(FileDescriptor fd, IBinder token, String[] args)
819            throws RemoteException {
820        Parcel data = Parcel.obtain();
821        data.writeInterfaceToken(IApplicationThread.descriptor);
822        data.writeFileDescriptor(fd);
823        data.writeStrongBinder(token);
824        data.writeStringArray(args);
825        mRemote.transact(DUMP_SERVICE_TRANSACTION, data, null, 0);
826        data.recycle();
827    }
828
829    public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent,
830            int resultCode, String dataStr, Bundle extras, boolean ordered, boolean sticky)
831            throws RemoteException {
832        Parcel data = Parcel.obtain();
833        data.writeInterfaceToken(IApplicationThread.descriptor);
834        data.writeStrongBinder(receiver.asBinder());
835        intent.writeToParcel(data, 0);
836        data.writeInt(resultCode);
837        data.writeString(dataStr);
838        data.writeBundle(extras);
839        data.writeInt(ordered ? 1 : 0);
840        data.writeInt(sticky ? 1 : 0);
841        mRemote.transact(SCHEDULE_REGISTERED_RECEIVER_TRANSACTION, data, null,
842                IBinder.FLAG_ONEWAY);
843        data.recycle();
844    }
845
846    public final void scheduleLowMemory() throws RemoteException {
847        Parcel data = Parcel.obtain();
848        data.writeInterfaceToken(IApplicationThread.descriptor);
849        mRemote.transact(SCHEDULE_LOW_MEMORY_TRANSACTION, data, null,
850                IBinder.FLAG_ONEWAY);
851        data.recycle();
852    }
853
854    public final void scheduleActivityConfigurationChanged(
855            IBinder token) throws RemoteException {
856        Parcel data = Parcel.obtain();
857        data.writeInterfaceToken(IApplicationThread.descriptor);
858        data.writeStrongBinder(token);
859        mRemote.transact(SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION, data, null,
860                IBinder.FLAG_ONEWAY);
861        data.recycle();
862    }
863
864    public void profilerControl(boolean start, String path,
865            ParcelFileDescriptor fd) throws RemoteException {
866        Parcel data = Parcel.obtain();
867        data.writeInterfaceToken(IApplicationThread.descriptor);
868        data.writeInt(start ? 1 : 0);
869        data.writeString(path);
870        if (fd != null) {
871            data.writeInt(1);
872            fd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
873        } else {
874            data.writeInt(0);
875        }
876        mRemote.transact(PROFILER_CONTROL_TRANSACTION, data, null,
877                IBinder.FLAG_ONEWAY);
878        data.recycle();
879    }
880
881    public void setSchedulingGroup(int group) throws RemoteException {
882        Parcel data = Parcel.obtain();
883        data.writeInterfaceToken(IApplicationThread.descriptor);
884        data.writeInt(group);
885        mRemote.transact(SET_SCHEDULING_GROUP_TRANSACTION, data, null,
886                IBinder.FLAG_ONEWAY);
887        data.recycle();
888    }
889
890    public void getMemoryInfo(Debug.MemoryInfo outInfo) throws RemoteException {
891        Parcel data = Parcel.obtain();
892        Parcel reply = Parcel.obtain();
893        data.writeInterfaceToken(IApplicationThread.descriptor);
894        mRemote.transact(GET_MEMORY_INFO_TRANSACTION, data, reply, 0);
895        reply.readException();
896        outInfo.readFromParcel(reply);
897        data.recycle();
898        reply.recycle();
899    }
900
901    public void dispatchPackageBroadcast(int cmd, String[] packages) throws RemoteException {
902        Parcel data = Parcel.obtain();
903        data.writeInterfaceToken(IApplicationThread.descriptor);
904        data.writeInt(cmd);
905        data.writeStringArray(packages);
906        mRemote.transact(DISPATCH_PACKAGE_BROADCAST_TRANSACTION, data, null,
907                IBinder.FLAG_ONEWAY);
908        data.recycle();
909
910    }
911
912    public void scheduleCrash(String msg) throws RemoteException {
913        Parcel data = Parcel.obtain();
914        data.writeInterfaceToken(IApplicationThread.descriptor);
915        data.writeString(msg);
916        mRemote.transact(SCHEDULE_CRASH_TRANSACTION, data, null,
917                IBinder.FLAG_ONEWAY);
918        data.recycle();
919
920    }
921
922    public void dumpHeap(boolean managed, String path,
923            ParcelFileDescriptor fd) throws RemoteException {
924        Parcel data = Parcel.obtain();
925        data.writeInterfaceToken(IApplicationThread.descriptor);
926        data.writeInt(managed ? 1 : 0);
927        data.writeString(path);
928        if (fd != null) {
929            data.writeInt(1);
930            fd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
931        } else {
932            data.writeInt(0);
933        }
934        mRemote.transact(DUMP_HEAP_TRANSACTION, data, null,
935                IBinder.FLAG_ONEWAY);
936        data.recycle();
937    }
938
939    public void dumpActivity(FileDescriptor fd, IBinder token, String prefix, String[] args)
940            throws RemoteException {
941        Parcel data = Parcel.obtain();
942        data.writeInterfaceToken(IApplicationThread.descriptor);
943        data.writeFileDescriptor(fd);
944        data.writeStrongBinder(token);
945        data.writeString(prefix);
946        data.writeStringArray(args);
947        mRemote.transact(DUMP_ACTIVITY_TRANSACTION, data, null, 0);
948        data.recycle();
949    }
950
951    public void setCoreSettings(Bundle coreSettings) throws RemoteException {
952        Parcel data = Parcel.obtain();
953        data.writeInterfaceToken(IApplicationThread.descriptor);
954        data.writeBundle(coreSettings);
955        mRemote.transact(SET_CORE_SETTINGS, data, null, IBinder.FLAG_ONEWAY);
956    }
957}
958