ApplicationThreadNative.java revision e94a3e7f84c4e47f013be07901f8f1ceeedefb6e
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.CompatibilityInfo;
27import android.content.res.Configuration;
28import android.os.Binder;
29import android.os.Bundle;
30import android.os.Debug;
31import android.os.Parcelable;
32import android.os.RemoteException;
33import android.os.IBinder;
34import android.os.Parcel;
35import android.os.ParcelFileDescriptor;
36
37import java.io.FileDescriptor;
38import java.io.IOException;
39import java.util.HashMap;
40import java.util.List;
41import java.util.Map;
42
43/** {@hide} */
44public abstract class ApplicationThreadNative extends Binder
45        implements IApplicationThread {
46    /**
47     * Cast a Binder object into an application thread interface, generating
48     * a proxy if needed.
49     */
50    static public IApplicationThread asInterface(IBinder obj) {
51        if (obj == null) {
52            return null;
53        }
54        IApplicationThread in =
55            (IApplicationThread)obj.queryLocalInterface(descriptor);
56        if (in != null) {
57            return in;
58        }
59
60        return new ApplicationThreadProxy(obj);
61    }
62
63    public ApplicationThreadNative() {
64        attachInterface(this, descriptor);
65    }
66
67    @Override
68    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
69            throws RemoteException {
70        switch (code) {
71        case SCHEDULE_PAUSE_ACTIVITY_TRANSACTION:
72        {
73            data.enforceInterface(IApplicationThread.descriptor);
74            IBinder b = data.readStrongBinder();
75            boolean finished = data.readInt() != 0;
76            boolean userLeaving = data.readInt() != 0;
77            int configChanges = data.readInt();
78            schedulePauseActivity(b, finished, userLeaving, configChanges);
79            return true;
80        }
81
82        case SCHEDULE_STOP_ACTIVITY_TRANSACTION:
83        {
84            data.enforceInterface(IApplicationThread.descriptor);
85            IBinder b = data.readStrongBinder();
86            boolean show = data.readInt() != 0;
87            int configChanges = data.readInt();
88            scheduleStopActivity(b, show, configChanges);
89            return true;
90        }
91
92        case SCHEDULE_WINDOW_VISIBILITY_TRANSACTION:
93        {
94            data.enforceInterface(IApplicationThread.descriptor);
95            IBinder b = data.readStrongBinder();
96            boolean show = data.readInt() != 0;
97            scheduleWindowVisibility(b, show);
98            return true;
99        }
100
101        case SCHEDULE_SLEEPING_TRANSACTION:
102        {
103            data.enforceInterface(IApplicationThread.descriptor);
104            IBinder b = data.readStrongBinder();
105            boolean sleeping = data.readInt() != 0;
106            scheduleSleeping(b, sleeping);
107            return true;
108        }
109
110        case SCHEDULE_RESUME_ACTIVITY_TRANSACTION:
111        {
112            data.enforceInterface(IApplicationThread.descriptor);
113            IBinder b = data.readStrongBinder();
114            boolean isForward = data.readInt() != 0;
115            scheduleResumeActivity(b, isForward);
116            return true;
117        }
118
119        case SCHEDULE_SEND_RESULT_TRANSACTION:
120        {
121            data.enforceInterface(IApplicationThread.descriptor);
122            IBinder b = data.readStrongBinder();
123            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
124            scheduleSendResult(b, ri);
125            return true;
126        }
127
128        case SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION:
129        {
130            data.enforceInterface(IApplicationThread.descriptor);
131            Intent intent = Intent.CREATOR.createFromParcel(data);
132            IBinder b = data.readStrongBinder();
133            int ident = data.readInt();
134            ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
135            Configuration curConfig = Configuration.CREATOR.createFromParcel(data);
136            CompatibilityInfo compatInfo = CompatibilityInfo.CREATOR.createFromParcel(data);
137            Bundle state = data.readBundle();
138            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
139            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
140            boolean notResumed = data.readInt() != 0;
141            boolean isForward = data.readInt() != 0;
142            String profileName = data.readString();
143            ParcelFileDescriptor profileFd = data.readInt() != 0
144                    ? data.readFileDescriptor() : null;
145            boolean autoStopProfiler = data.readInt() != 0;
146            scheduleLaunchActivity(intent, b, ident, info, curConfig, compatInfo, state, ri, pi,
147                    notResumed, isForward, profileName, profileFd, autoStopProfiler);
148            return true;
149        }
150
151        case SCHEDULE_RELAUNCH_ACTIVITY_TRANSACTION:
152        {
153            data.enforceInterface(IApplicationThread.descriptor);
154            IBinder b = data.readStrongBinder();
155            List<ResultInfo> ri = data.createTypedArrayList(ResultInfo.CREATOR);
156            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
157            int configChanges = data.readInt();
158            boolean notResumed = data.readInt() != 0;
159            Configuration config = null;
160            if (data.readInt() != 0) {
161                config = Configuration.CREATOR.createFromParcel(data);
162            }
163            scheduleRelaunchActivity(b, ri, pi, configChanges, notResumed, config);
164            return true;
165        }
166
167        case SCHEDULE_NEW_INTENT_TRANSACTION:
168        {
169            data.enforceInterface(IApplicationThread.descriptor);
170            List<Intent> pi = data.createTypedArrayList(Intent.CREATOR);
171            IBinder b = data.readStrongBinder();
172            scheduleNewIntent(pi, b);
173            return true;
174        }
175
176        case SCHEDULE_FINISH_ACTIVITY_TRANSACTION:
177        {
178            data.enforceInterface(IApplicationThread.descriptor);
179            IBinder b = data.readStrongBinder();
180            boolean finishing = data.readInt() != 0;
181            int configChanges = data.readInt();
182            scheduleDestroyActivity(b, finishing, configChanges);
183            return true;
184        }
185
186        case SCHEDULE_RECEIVER_TRANSACTION:
187        {
188            data.enforceInterface(IApplicationThread.descriptor);
189            Intent intent = Intent.CREATOR.createFromParcel(data);
190            ActivityInfo info = ActivityInfo.CREATOR.createFromParcel(data);
191            CompatibilityInfo compatInfo = CompatibilityInfo.CREATOR.createFromParcel(data);
192            int resultCode = data.readInt();
193            String resultData = data.readString();
194            Bundle resultExtras = data.readBundle();
195            boolean sync = data.readInt() != 0;
196            scheduleReceiver(intent, info, compatInfo, resultCode, resultData,
197                    resultExtras, sync);
198            return true;
199        }
200
201        case SCHEDULE_CREATE_SERVICE_TRANSACTION: {
202            data.enforceInterface(IApplicationThread.descriptor);
203            IBinder token = data.readStrongBinder();
204            ServiceInfo info = ServiceInfo.CREATOR.createFromParcel(data);
205            CompatibilityInfo compatInfo = CompatibilityInfo.CREATOR.createFromParcel(data);
206            scheduleCreateService(token, info, compatInfo);
207            return true;
208        }
209
210        case SCHEDULE_BIND_SERVICE_TRANSACTION: {
211            data.enforceInterface(IApplicationThread.descriptor);
212            IBinder token = data.readStrongBinder();
213            Intent intent = Intent.CREATOR.createFromParcel(data);
214            boolean rebind = data.readInt() != 0;
215            scheduleBindService(token, intent, rebind);
216            return true;
217        }
218
219        case SCHEDULE_UNBIND_SERVICE_TRANSACTION: {
220            data.enforceInterface(IApplicationThread.descriptor);
221            IBinder token = data.readStrongBinder();
222            Intent intent = Intent.CREATOR.createFromParcel(data);
223            scheduleUnbindService(token, intent);
224            return true;
225        }
226
227        case SCHEDULE_SERVICE_ARGS_TRANSACTION:
228        {
229            data.enforceInterface(IApplicationThread.descriptor);
230            IBinder token = data.readStrongBinder();
231            boolean taskRemoved = data.readInt() != 0;
232            int startId = data.readInt();
233            int fl = data.readInt();
234            Intent args;
235            if (data.readInt() != 0) {
236                args = Intent.CREATOR.createFromParcel(data);
237            } else {
238                args = null;
239            }
240            scheduleServiceArgs(token, taskRemoved, startId, fl, args);
241            return true;
242        }
243
244        case SCHEDULE_STOP_SERVICE_TRANSACTION:
245        {
246            data.enforceInterface(IApplicationThread.descriptor);
247            IBinder token = data.readStrongBinder();
248            scheduleStopService(token);
249            return true;
250        }
251
252        case BIND_APPLICATION_TRANSACTION:
253        {
254            data.enforceInterface(IApplicationThread.descriptor);
255            String packageName = data.readString();
256            ApplicationInfo info =
257                ApplicationInfo.CREATOR.createFromParcel(data);
258            List<ProviderInfo> providers =
259                data.createTypedArrayList(ProviderInfo.CREATOR);
260            ComponentName testName = (data.readInt() != 0)
261                ? new ComponentName(data) : null;
262            String profileName = data.readString();
263            ParcelFileDescriptor profileFd = data.readInt() != 0
264                    ? data.readFileDescriptor() : null;
265            boolean autoStopProfiler = data.readInt() != 0;
266            Bundle testArgs = data.readBundle();
267            IBinder binder = data.readStrongBinder();
268            IInstrumentationWatcher testWatcher = IInstrumentationWatcher.Stub.asInterface(binder);
269            int testMode = data.readInt();
270            boolean restrictedBackupMode = (data.readInt() != 0);
271            boolean persistent = (data.readInt() != 0);
272            Configuration config = Configuration.CREATOR.createFromParcel(data);
273            CompatibilityInfo compatInfo = CompatibilityInfo.CREATOR.createFromParcel(data);
274            HashMap<String, IBinder> services = data.readHashMap(null);
275            Bundle coreSettings = data.readBundle();
276            bindApplication(packageName, info,
277                            providers, testName, profileName, profileFd, autoStopProfiler,
278                            testArgs, testWatcher, testMode, restrictedBackupMode, persistent,
279                            config, compatInfo, services, coreSettings);
280            return true;
281        }
282
283        case SCHEDULE_EXIT_TRANSACTION:
284        {
285            data.enforceInterface(IApplicationThread.descriptor);
286            scheduleExit();
287            return true;
288        }
289
290        case SCHEDULE_SUICIDE_TRANSACTION:
291        {
292            data.enforceInterface(IApplicationThread.descriptor);
293            scheduleSuicide();
294            return true;
295        }
296
297        case REQUEST_THUMBNAIL_TRANSACTION:
298        {
299            data.enforceInterface(IApplicationThread.descriptor);
300            IBinder b = data.readStrongBinder();
301            requestThumbnail(b);
302            return true;
303        }
304
305        case SCHEDULE_CONFIGURATION_CHANGED_TRANSACTION:
306        {
307            data.enforceInterface(IApplicationThread.descriptor);
308            Configuration config = Configuration.CREATOR.createFromParcel(data);
309            scheduleConfigurationChanged(config);
310            return true;
311        }
312
313        case UPDATE_TIME_ZONE_TRANSACTION: {
314            data.enforceInterface(IApplicationThread.descriptor);
315            updateTimeZone();
316            return true;
317        }
318
319        case CLEAR_DNS_CACHE_TRANSACTION: {
320            data.enforceInterface(IApplicationThread.descriptor);
321            clearDnsCache();
322            return true;
323        }
324
325        case SET_HTTP_PROXY_TRANSACTION: {
326            data.enforceInterface(IApplicationThread.descriptor);
327            final String proxy = data.readString();
328            final String port = data.readString();
329            final String exclList = data.readString();
330            setHttpProxy(proxy, port, exclList);
331            return true;
332        }
333
334        case PROCESS_IN_BACKGROUND_TRANSACTION: {
335            data.enforceInterface(IApplicationThread.descriptor);
336            processInBackground();
337            return true;
338        }
339
340        case DUMP_SERVICE_TRANSACTION: {
341            data.enforceInterface(IApplicationThread.descriptor);
342            ParcelFileDescriptor fd = data.readFileDescriptor();
343            final IBinder service = data.readStrongBinder();
344            final String[] args = data.readStringArray();
345            if (fd != null) {
346                dumpService(fd.getFileDescriptor(), service, args);
347                try {
348                    fd.close();
349                } catch (IOException e) {
350                }
351            }
352            return true;
353        }
354
355        case SCHEDULE_REGISTERED_RECEIVER_TRANSACTION: {
356            data.enforceInterface(IApplicationThread.descriptor);
357            IIntentReceiver receiver = IIntentReceiver.Stub.asInterface(
358                    data.readStrongBinder());
359            Intent intent = Intent.CREATOR.createFromParcel(data);
360            int resultCode = data.readInt();
361            String dataStr = data.readString();
362            Bundle extras = data.readBundle();
363            boolean ordered = data.readInt() != 0;
364            boolean sticky = data.readInt() != 0;
365            scheduleRegisteredReceiver(receiver, intent,
366                    resultCode, dataStr, extras, ordered, sticky);
367            return true;
368        }
369
370        case SCHEDULE_LOW_MEMORY_TRANSACTION:
371        {
372            data.enforceInterface(IApplicationThread.descriptor);
373            scheduleLowMemory();
374            return true;
375        }
376
377        case SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION:
378        {
379            data.enforceInterface(IApplicationThread.descriptor);
380            IBinder b = data.readStrongBinder();
381            scheduleActivityConfigurationChanged(b);
382            return true;
383        }
384
385        case PROFILER_CONTROL_TRANSACTION:
386        {
387            data.enforceInterface(IApplicationThread.descriptor);
388            boolean start = data.readInt() != 0;
389            int profileType = data.readInt();
390            String path = data.readString();
391            ParcelFileDescriptor fd = data.readInt() != 0
392                    ? data.readFileDescriptor() : null;
393            profilerControl(start, path, fd, profileType);
394            return true;
395        }
396
397        case SET_SCHEDULING_GROUP_TRANSACTION:
398        {
399            data.enforceInterface(IApplicationThread.descriptor);
400            int group = data.readInt();
401            setSchedulingGroup(group);
402            return true;
403        }
404
405        case SCHEDULE_CREATE_BACKUP_AGENT_TRANSACTION:
406        {
407            data.enforceInterface(IApplicationThread.descriptor);
408            ApplicationInfo appInfo = ApplicationInfo.CREATOR.createFromParcel(data);
409            CompatibilityInfo compatInfo = CompatibilityInfo.CREATOR.createFromParcel(data);
410            int backupMode = data.readInt();
411            scheduleCreateBackupAgent(appInfo, compatInfo, backupMode);
412            return true;
413        }
414
415        case SCHEDULE_DESTROY_BACKUP_AGENT_TRANSACTION:
416        {
417            data.enforceInterface(IApplicationThread.descriptor);
418            ApplicationInfo appInfo = ApplicationInfo.CREATOR.createFromParcel(data);
419            CompatibilityInfo compatInfo = CompatibilityInfo.CREATOR.createFromParcel(data);
420            scheduleDestroyBackupAgent(appInfo, compatInfo);
421            return true;
422        }
423
424        case GET_MEMORY_INFO_TRANSACTION:
425        {
426            data.enforceInterface(IApplicationThread.descriptor);
427            Debug.MemoryInfo mi = new Debug.MemoryInfo();
428            getMemoryInfo(mi);
429            reply.writeNoException();
430            mi.writeToParcel(reply, 0);
431            return true;
432        }
433
434        case DISPATCH_PACKAGE_BROADCAST_TRANSACTION:
435        {
436            data.enforceInterface(IApplicationThread.descriptor);
437            int cmd = data.readInt();
438            String[] packages = data.readStringArray();
439            dispatchPackageBroadcast(cmd, packages);
440            return true;
441        }
442
443        case SCHEDULE_CRASH_TRANSACTION:
444        {
445            data.enforceInterface(IApplicationThread.descriptor);
446            String msg = data.readString();
447            scheduleCrash(msg);
448            return true;
449        }
450
451        case DUMP_HEAP_TRANSACTION:
452        {
453            data.enforceInterface(IApplicationThread.descriptor);
454            boolean managed = data.readInt() != 0;
455            String path = data.readString();
456            ParcelFileDescriptor fd = data.readInt() != 0
457                    ? data.readFileDescriptor() : null;
458            dumpHeap(managed, path, fd);
459            return true;
460        }
461
462        case DUMP_ACTIVITY_TRANSACTION: {
463            data.enforceInterface(IApplicationThread.descriptor);
464            ParcelFileDescriptor fd = data.readFileDescriptor();
465            final IBinder activity = data.readStrongBinder();
466            final String prefix = data.readString();
467            final String[] args = data.readStringArray();
468            if (fd != null) {
469                dumpActivity(fd.getFileDescriptor(), activity, prefix, args);
470                try {
471                    fd.close();
472                } catch (IOException e) {
473                }
474            }
475            return true;
476        }
477
478        case SET_CORE_SETTINGS_TRANSACTION: {
479            data.enforceInterface(IApplicationThread.descriptor);
480            Bundle settings = data.readBundle();
481            setCoreSettings(settings);
482            return true;
483        }
484
485        case UPDATE_PACKAGE_COMPATIBILITY_INFO_TRANSACTION: {
486            data.enforceInterface(IApplicationThread.descriptor);
487            String pkg = data.readString();
488            CompatibilityInfo compat = CompatibilityInfo.CREATOR.createFromParcel(data);
489            updatePackageCompatibilityInfo(pkg, compat);
490            return true;
491        }
492
493        case SCHEDULE_TRIM_MEMORY_TRANSACTION: {
494            data.enforceInterface(IApplicationThread.descriptor);
495            int level = data.readInt();
496            scheduleTrimMemory(level);
497            return true;
498        }
499
500        case DUMP_MEM_INFO_TRANSACTION:
501        {
502            data.enforceInterface(IApplicationThread.descriptor);
503            ParcelFileDescriptor fd = data.readFileDescriptor();
504            boolean checkin = data.readInt() != 0;
505            boolean all = data.readInt() != 0;
506            String[] args = data.readStringArray();
507            Debug.MemoryInfo mi = null;
508            if (fd != null) {
509                try {
510                    mi = dumpMemInfo(fd.getFileDescriptor(), checkin, all, args);
511                } finally {
512                    try {
513                        fd.close();
514                    } catch (IOException e) {
515                        // swallowed, not propagated back to the caller
516                    }
517                }
518            }
519            reply.writeNoException();
520            mi.writeToParcel(reply, 0);
521            return true;
522        }
523
524        case DUMP_GFX_INFO_TRANSACTION:
525        {
526            data.enforceInterface(IApplicationThread.descriptor);
527            ParcelFileDescriptor fd = data.readFileDescriptor();
528            String[] args = data.readStringArray();
529            if (fd != null) {
530                try {
531                    dumpGfxInfo(fd.getFileDescriptor(), args);
532                } finally {
533                    try {
534                        fd.close();
535                    } catch (IOException e) {
536                        // swallowed, not propagated back to the caller
537                    }
538                }
539            }
540            reply.writeNoException();
541            return true;
542        }
543        }
544
545        return super.onTransact(code, data, reply, flags);
546    }
547
548    public IBinder asBinder()
549    {
550        return this;
551    }
552}
553
554class ApplicationThreadProxy implements IApplicationThread {
555    private final IBinder mRemote;
556
557    public ApplicationThreadProxy(IBinder remote) {
558        mRemote = remote;
559    }
560
561    public final IBinder asBinder() {
562        return mRemote;
563    }
564
565    public final void schedulePauseActivity(IBinder token, boolean finished,
566            boolean userLeaving, int configChanges) throws RemoteException {
567        Parcel data = Parcel.obtain();
568        data.writeInterfaceToken(IApplicationThread.descriptor);
569        data.writeStrongBinder(token);
570        data.writeInt(finished ? 1 : 0);
571        data.writeInt(userLeaving ? 1 :0);
572        data.writeInt(configChanges);
573        mRemote.transact(SCHEDULE_PAUSE_ACTIVITY_TRANSACTION, data, null,
574                IBinder.FLAG_ONEWAY);
575        data.recycle();
576    }
577
578    public final void scheduleStopActivity(IBinder token, boolean showWindow,
579            int configChanges) throws RemoteException {
580        Parcel data = Parcel.obtain();
581        data.writeInterfaceToken(IApplicationThread.descriptor);
582        data.writeStrongBinder(token);
583        data.writeInt(showWindow ? 1 : 0);
584        data.writeInt(configChanges);
585        mRemote.transact(SCHEDULE_STOP_ACTIVITY_TRANSACTION, data, null,
586                IBinder.FLAG_ONEWAY);
587        data.recycle();
588    }
589
590    public final void scheduleWindowVisibility(IBinder token,
591            boolean showWindow) throws RemoteException {
592        Parcel data = Parcel.obtain();
593        data.writeInterfaceToken(IApplicationThread.descriptor);
594        data.writeStrongBinder(token);
595        data.writeInt(showWindow ? 1 : 0);
596        mRemote.transact(SCHEDULE_WINDOW_VISIBILITY_TRANSACTION, data, null,
597                IBinder.FLAG_ONEWAY);
598        data.recycle();
599    }
600
601    public final void scheduleSleeping(IBinder token,
602            boolean sleeping) throws RemoteException {
603        Parcel data = Parcel.obtain();
604        data.writeInterfaceToken(IApplicationThread.descriptor);
605        data.writeStrongBinder(token);
606        data.writeInt(sleeping ? 1 : 0);
607        mRemote.transact(SCHEDULE_SLEEPING_TRANSACTION, data, null,
608                IBinder.FLAG_ONEWAY);
609        data.recycle();
610    }
611
612    public final void scheduleResumeActivity(IBinder token, boolean isForward)
613            throws RemoteException {
614        Parcel data = Parcel.obtain();
615        data.writeInterfaceToken(IApplicationThread.descriptor);
616        data.writeStrongBinder(token);
617        data.writeInt(isForward ? 1 : 0);
618        mRemote.transact(SCHEDULE_RESUME_ACTIVITY_TRANSACTION, data, null,
619                IBinder.FLAG_ONEWAY);
620        data.recycle();
621    }
622
623    public final void scheduleSendResult(IBinder token, List<ResultInfo> results)
624    		throws RemoteException {
625        Parcel data = Parcel.obtain();
626        data.writeInterfaceToken(IApplicationThread.descriptor);
627        data.writeStrongBinder(token);
628        data.writeTypedList(results);
629        mRemote.transact(SCHEDULE_SEND_RESULT_TRANSACTION, data, null,
630                IBinder.FLAG_ONEWAY);
631        data.recycle();
632    }
633
634    public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
635            ActivityInfo info, Configuration curConfig, CompatibilityInfo compatInfo,
636            Bundle state, List<ResultInfo> pendingResults,
637    		List<Intent> pendingNewIntents, boolean notResumed, boolean isForward,
638    		String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler)
639    		throws RemoteException {
640        Parcel data = Parcel.obtain();
641        data.writeInterfaceToken(IApplicationThread.descriptor);
642        intent.writeToParcel(data, 0);
643        data.writeStrongBinder(token);
644        data.writeInt(ident);
645        info.writeToParcel(data, 0);
646        curConfig.writeToParcel(data, 0);
647        compatInfo.writeToParcel(data, 0);
648        data.writeBundle(state);
649        data.writeTypedList(pendingResults);
650        data.writeTypedList(pendingNewIntents);
651        data.writeInt(notResumed ? 1 : 0);
652        data.writeInt(isForward ? 1 : 0);
653        data.writeString(profileName);
654        if (profileFd != null) {
655            data.writeInt(1);
656            profileFd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
657        } else {
658            data.writeInt(0);
659        }
660        data.writeInt(autoStopProfiler ? 1 : 0);
661        mRemote.transact(SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION, data, null,
662                IBinder.FLAG_ONEWAY);
663        data.recycle();
664    }
665
666    public final void scheduleRelaunchActivity(IBinder token,
667            List<ResultInfo> pendingResults, List<Intent> pendingNewIntents,
668            int configChanges, boolean notResumed, Configuration config)
669            throws RemoteException {
670        Parcel data = Parcel.obtain();
671        data.writeInterfaceToken(IApplicationThread.descriptor);
672        data.writeStrongBinder(token);
673        data.writeTypedList(pendingResults);
674        data.writeTypedList(pendingNewIntents);
675        data.writeInt(configChanges);
676        data.writeInt(notResumed ? 1 : 0);
677        if (config != null) {
678            data.writeInt(1);
679            config.writeToParcel(data, 0);
680        } else {
681            data.writeInt(0);
682        }
683        mRemote.transact(SCHEDULE_RELAUNCH_ACTIVITY_TRANSACTION, data, null,
684                IBinder.FLAG_ONEWAY);
685        data.recycle();
686    }
687
688    public void scheduleNewIntent(List<Intent> intents, IBinder token)
689            throws RemoteException {
690        Parcel data = Parcel.obtain();
691        data.writeInterfaceToken(IApplicationThread.descriptor);
692        data.writeTypedList(intents);
693        data.writeStrongBinder(token);
694        mRemote.transact(SCHEDULE_NEW_INTENT_TRANSACTION, data, null,
695                IBinder.FLAG_ONEWAY);
696        data.recycle();
697    }
698
699    public final void scheduleDestroyActivity(IBinder token, boolean finishing,
700            int configChanges) throws RemoteException {
701        Parcel data = Parcel.obtain();
702        data.writeInterfaceToken(IApplicationThread.descriptor);
703        data.writeStrongBinder(token);
704        data.writeInt(finishing ? 1 : 0);
705        data.writeInt(configChanges);
706        mRemote.transact(SCHEDULE_FINISH_ACTIVITY_TRANSACTION, data, null,
707                IBinder.FLAG_ONEWAY);
708        data.recycle();
709    }
710
711    public final void scheduleReceiver(Intent intent, ActivityInfo info,
712            CompatibilityInfo compatInfo, int resultCode, String resultData,
713            Bundle map, boolean sync) throws RemoteException {
714        Parcel data = Parcel.obtain();
715        data.writeInterfaceToken(IApplicationThread.descriptor);
716        intent.writeToParcel(data, 0);
717        info.writeToParcel(data, 0);
718        compatInfo.writeToParcel(data, 0);
719        data.writeInt(resultCode);
720        data.writeString(resultData);
721        data.writeBundle(map);
722        data.writeInt(sync ? 1 : 0);
723        mRemote.transact(SCHEDULE_RECEIVER_TRANSACTION, data, null,
724                IBinder.FLAG_ONEWAY);
725        data.recycle();
726    }
727
728    public final void scheduleCreateBackupAgent(ApplicationInfo app,
729            CompatibilityInfo compatInfo, int backupMode) throws RemoteException {
730        Parcel data = Parcel.obtain();
731        data.writeInterfaceToken(IApplicationThread.descriptor);
732        app.writeToParcel(data, 0);
733        compatInfo.writeToParcel(data, 0);
734        data.writeInt(backupMode);
735        mRemote.transact(SCHEDULE_CREATE_BACKUP_AGENT_TRANSACTION, data, null,
736                IBinder.FLAG_ONEWAY);
737        data.recycle();
738    }
739
740    public final void scheduleDestroyBackupAgent(ApplicationInfo app,
741            CompatibilityInfo compatInfo) throws RemoteException {
742        Parcel data = Parcel.obtain();
743        data.writeInterfaceToken(IApplicationThread.descriptor);
744        app.writeToParcel(data, 0);
745        compatInfo.writeToParcel(data, 0);
746        mRemote.transact(SCHEDULE_DESTROY_BACKUP_AGENT_TRANSACTION, data, null,
747                IBinder.FLAG_ONEWAY);
748        data.recycle();
749    }
750
751    public final void scheduleCreateService(IBinder token, ServiceInfo info,
752            CompatibilityInfo compatInfo) throws RemoteException {
753        Parcel data = Parcel.obtain();
754        data.writeInterfaceToken(IApplicationThread.descriptor);
755        data.writeStrongBinder(token);
756        info.writeToParcel(data, 0);
757        compatInfo.writeToParcel(data, 0);
758        mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
759                IBinder.FLAG_ONEWAY);
760        data.recycle();
761    }
762
763    public final void scheduleBindService(IBinder token, Intent intent, boolean rebind)
764            throws RemoteException {
765        Parcel data = Parcel.obtain();
766        data.writeInterfaceToken(IApplicationThread.descriptor);
767        data.writeStrongBinder(token);
768        intent.writeToParcel(data, 0);
769        data.writeInt(rebind ? 1 : 0);
770        mRemote.transact(SCHEDULE_BIND_SERVICE_TRANSACTION, data, null,
771                IBinder.FLAG_ONEWAY);
772        data.recycle();
773    }
774
775    public final void scheduleUnbindService(IBinder token, Intent intent)
776            throws RemoteException {
777        Parcel data = Parcel.obtain();
778        data.writeInterfaceToken(IApplicationThread.descriptor);
779        data.writeStrongBinder(token);
780        intent.writeToParcel(data, 0);
781        mRemote.transact(SCHEDULE_UNBIND_SERVICE_TRANSACTION, data, null,
782                IBinder.FLAG_ONEWAY);
783        data.recycle();
784    }
785
786    public final void scheduleServiceArgs(IBinder token, boolean taskRemoved, int startId,
787	    int flags, Intent args) throws RemoteException {
788        Parcel data = Parcel.obtain();
789        data.writeInterfaceToken(IApplicationThread.descriptor);
790        data.writeStrongBinder(token);
791        data.writeInt(taskRemoved ? 1 : 0);
792        data.writeInt(startId);
793        data.writeInt(flags);
794        if (args != null) {
795            data.writeInt(1);
796            args.writeToParcel(data, 0);
797        } else {
798            data.writeInt(0);
799        }
800        mRemote.transact(SCHEDULE_SERVICE_ARGS_TRANSACTION, data, null,
801                IBinder.FLAG_ONEWAY);
802        data.recycle();
803    }
804
805    public final void scheduleStopService(IBinder token)
806            throws RemoteException {
807        Parcel data = Parcel.obtain();
808        data.writeInterfaceToken(IApplicationThread.descriptor);
809        data.writeStrongBinder(token);
810        mRemote.transact(SCHEDULE_STOP_SERVICE_TRANSACTION, data, null,
811                IBinder.FLAG_ONEWAY);
812        data.recycle();
813    }
814
815    public final void bindApplication(String packageName, ApplicationInfo info,
816            List<ProviderInfo> providers, ComponentName testName, String profileName,
817            ParcelFileDescriptor profileFd, boolean autoStopProfiler, Bundle testArgs,
818            IInstrumentationWatcher testWatcher, int debugMode, boolean restrictedBackupMode,
819            boolean persistent, Configuration config, CompatibilityInfo compatInfo,
820            Map<String, IBinder> services, Bundle coreSettings) throws RemoteException {
821        Parcel data = Parcel.obtain();
822        data.writeInterfaceToken(IApplicationThread.descriptor);
823        data.writeString(packageName);
824        info.writeToParcel(data, 0);
825        data.writeTypedList(providers);
826        if (testName == null) {
827            data.writeInt(0);
828        } else {
829            data.writeInt(1);
830            testName.writeToParcel(data, 0);
831        }
832        data.writeString(profileName);
833        if (profileFd != null) {
834            data.writeInt(1);
835            profileFd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
836        } else {
837            data.writeInt(0);
838        }
839        data.writeInt(autoStopProfiler ? 1 : 0);
840        data.writeBundle(testArgs);
841        data.writeStrongInterface(testWatcher);
842        data.writeInt(debugMode);
843        data.writeInt(restrictedBackupMode ? 1 : 0);
844        data.writeInt(persistent ? 1 : 0);
845        config.writeToParcel(data, 0);
846        compatInfo.writeToParcel(data, 0);
847        data.writeMap(services);
848        data.writeBundle(coreSettings);
849        mRemote.transact(BIND_APPLICATION_TRANSACTION, data, null,
850                IBinder.FLAG_ONEWAY);
851        data.recycle();
852    }
853
854    public final void scheduleExit() throws RemoteException {
855        Parcel data = Parcel.obtain();
856        data.writeInterfaceToken(IApplicationThread.descriptor);
857        mRemote.transact(SCHEDULE_EXIT_TRANSACTION, data, null,
858                IBinder.FLAG_ONEWAY);
859        data.recycle();
860    }
861
862    public final void scheduleSuicide() throws RemoteException {
863        Parcel data = Parcel.obtain();
864        data.writeInterfaceToken(IApplicationThread.descriptor);
865        mRemote.transact(SCHEDULE_SUICIDE_TRANSACTION, data, null,
866                IBinder.FLAG_ONEWAY);
867        data.recycle();
868    }
869
870    public final void requestThumbnail(IBinder token)
871            throws RemoteException {
872        Parcel data = Parcel.obtain();
873        data.writeInterfaceToken(IApplicationThread.descriptor);
874        data.writeStrongBinder(token);
875        mRemote.transact(REQUEST_THUMBNAIL_TRANSACTION, data, null,
876                IBinder.FLAG_ONEWAY);
877        data.recycle();
878    }
879
880    public final void scheduleConfigurationChanged(Configuration config)
881            throws RemoteException {
882        Parcel data = Parcel.obtain();
883        data.writeInterfaceToken(IApplicationThread.descriptor);
884        config.writeToParcel(data, 0);
885        mRemote.transact(SCHEDULE_CONFIGURATION_CHANGED_TRANSACTION, data, null,
886                IBinder.FLAG_ONEWAY);
887        data.recycle();
888    }
889
890    public void updateTimeZone() throws RemoteException {
891        Parcel data = Parcel.obtain();
892        data.writeInterfaceToken(IApplicationThread.descriptor);
893        mRemote.transact(UPDATE_TIME_ZONE_TRANSACTION, data, null,
894                IBinder.FLAG_ONEWAY);
895        data.recycle();
896    }
897
898    public void clearDnsCache() throws RemoteException {
899        Parcel data = Parcel.obtain();
900        data.writeInterfaceToken(IApplicationThread.descriptor);
901        mRemote.transact(CLEAR_DNS_CACHE_TRANSACTION, data, null,
902                IBinder.FLAG_ONEWAY);
903        data.recycle();
904    }
905
906    public void setHttpProxy(String proxy, String port, String exclList) throws RemoteException {
907        Parcel data = Parcel.obtain();
908        data.writeInterfaceToken(IApplicationThread.descriptor);
909        data.writeString(proxy);
910        data.writeString(port);
911        data.writeString(exclList);
912        mRemote.transact(SET_HTTP_PROXY_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
913        data.recycle();
914    }
915
916    public void processInBackground() throws RemoteException {
917        Parcel data = Parcel.obtain();
918        data.writeInterfaceToken(IApplicationThread.descriptor);
919        mRemote.transact(PROCESS_IN_BACKGROUND_TRANSACTION, data, null,
920                IBinder.FLAG_ONEWAY);
921        data.recycle();
922    }
923
924    public void dumpService(FileDescriptor fd, IBinder token, String[] args)
925            throws RemoteException {
926        Parcel data = Parcel.obtain();
927        data.writeInterfaceToken(IApplicationThread.descriptor);
928        data.writeFileDescriptor(fd);
929        data.writeStrongBinder(token);
930        data.writeStringArray(args);
931        mRemote.transact(DUMP_SERVICE_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
932        data.recycle();
933    }
934
935    public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent,
936            int resultCode, String dataStr, Bundle extras, boolean ordered, boolean sticky)
937            throws RemoteException {
938        Parcel data = Parcel.obtain();
939        data.writeInterfaceToken(IApplicationThread.descriptor);
940        data.writeStrongBinder(receiver.asBinder());
941        intent.writeToParcel(data, 0);
942        data.writeInt(resultCode);
943        data.writeString(dataStr);
944        data.writeBundle(extras);
945        data.writeInt(ordered ? 1 : 0);
946        data.writeInt(sticky ? 1 : 0);
947        mRemote.transact(SCHEDULE_REGISTERED_RECEIVER_TRANSACTION, data, null,
948                IBinder.FLAG_ONEWAY);
949        data.recycle();
950    }
951
952    public final void scheduleLowMemory() throws RemoteException {
953        Parcel data = Parcel.obtain();
954        data.writeInterfaceToken(IApplicationThread.descriptor);
955        mRemote.transact(SCHEDULE_LOW_MEMORY_TRANSACTION, data, null,
956                IBinder.FLAG_ONEWAY);
957        data.recycle();
958    }
959
960    public final void scheduleActivityConfigurationChanged(
961            IBinder token) throws RemoteException {
962        Parcel data = Parcel.obtain();
963        data.writeInterfaceToken(IApplicationThread.descriptor);
964        data.writeStrongBinder(token);
965        mRemote.transact(SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION, data, null,
966                IBinder.FLAG_ONEWAY);
967        data.recycle();
968    }
969
970    public void profilerControl(boolean start, String path,
971            ParcelFileDescriptor fd, int profileType) throws RemoteException {
972        Parcel data = Parcel.obtain();
973        data.writeInterfaceToken(IApplicationThread.descriptor);
974        data.writeInt(start ? 1 : 0);
975        data.writeInt(profileType);
976        data.writeString(path);
977        if (fd != null) {
978            data.writeInt(1);
979            fd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
980        } else {
981            data.writeInt(0);
982        }
983        mRemote.transact(PROFILER_CONTROL_TRANSACTION, data, null,
984                IBinder.FLAG_ONEWAY);
985        data.recycle();
986    }
987
988    public void setSchedulingGroup(int group) throws RemoteException {
989        Parcel data = Parcel.obtain();
990        data.writeInterfaceToken(IApplicationThread.descriptor);
991        data.writeInt(group);
992        mRemote.transact(SET_SCHEDULING_GROUP_TRANSACTION, data, null,
993                IBinder.FLAG_ONEWAY);
994        data.recycle();
995    }
996
997    public void getMemoryInfo(Debug.MemoryInfo outInfo) throws RemoteException {
998        Parcel data = Parcel.obtain();
999        Parcel reply = Parcel.obtain();
1000        data.writeInterfaceToken(IApplicationThread.descriptor);
1001        mRemote.transact(GET_MEMORY_INFO_TRANSACTION, data, reply, 0);
1002        reply.readException();
1003        outInfo.readFromParcel(reply);
1004        data.recycle();
1005        reply.recycle();
1006    }
1007
1008    public void dispatchPackageBroadcast(int cmd, String[] packages) throws RemoteException {
1009        Parcel data = Parcel.obtain();
1010        data.writeInterfaceToken(IApplicationThread.descriptor);
1011        data.writeInt(cmd);
1012        data.writeStringArray(packages);
1013        mRemote.transact(DISPATCH_PACKAGE_BROADCAST_TRANSACTION, data, null,
1014                IBinder.FLAG_ONEWAY);
1015        data.recycle();
1016
1017    }
1018
1019    public void scheduleCrash(String msg) throws RemoteException {
1020        Parcel data = Parcel.obtain();
1021        data.writeInterfaceToken(IApplicationThread.descriptor);
1022        data.writeString(msg);
1023        mRemote.transact(SCHEDULE_CRASH_TRANSACTION, data, null,
1024                IBinder.FLAG_ONEWAY);
1025        data.recycle();
1026
1027    }
1028
1029    public void dumpHeap(boolean managed, String path,
1030            ParcelFileDescriptor fd) throws RemoteException {
1031        Parcel data = Parcel.obtain();
1032        data.writeInterfaceToken(IApplicationThread.descriptor);
1033        data.writeInt(managed ? 1 : 0);
1034        data.writeString(path);
1035        if (fd != null) {
1036            data.writeInt(1);
1037            fd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1038        } else {
1039            data.writeInt(0);
1040        }
1041        mRemote.transact(DUMP_HEAP_TRANSACTION, data, null,
1042                IBinder.FLAG_ONEWAY);
1043        data.recycle();
1044    }
1045
1046    public void dumpActivity(FileDescriptor fd, IBinder token, String prefix, String[] args)
1047            throws RemoteException {
1048        Parcel data = Parcel.obtain();
1049        data.writeInterfaceToken(IApplicationThread.descriptor);
1050        data.writeFileDescriptor(fd);
1051        data.writeStrongBinder(token);
1052        data.writeString(prefix);
1053        data.writeStringArray(args);
1054        mRemote.transact(DUMP_ACTIVITY_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
1055        data.recycle();
1056    }
1057
1058    public void setCoreSettings(Bundle coreSettings) throws RemoteException {
1059        Parcel data = Parcel.obtain();
1060        data.writeInterfaceToken(IApplicationThread.descriptor);
1061        data.writeBundle(coreSettings);
1062        mRemote.transact(SET_CORE_SETTINGS_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
1063    }
1064
1065    public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info)
1066            throws RemoteException {
1067        Parcel data = Parcel.obtain();
1068        data.writeInterfaceToken(IApplicationThread.descriptor);
1069        data.writeString(pkg);
1070        info.writeToParcel(data, 0);
1071        mRemote.transact(UPDATE_PACKAGE_COMPATIBILITY_INFO_TRANSACTION, data, null,
1072                IBinder.FLAG_ONEWAY);
1073    }
1074
1075    public void scheduleTrimMemory(int level) throws RemoteException {
1076        Parcel data = Parcel.obtain();
1077        data.writeInterfaceToken(IApplicationThread.descriptor);
1078        data.writeInt(level);
1079        mRemote.transact(SCHEDULE_TRIM_MEMORY_TRANSACTION, data, null,
1080                IBinder.FLAG_ONEWAY);
1081    }
1082
1083    public Debug.MemoryInfo dumpMemInfo(FileDescriptor fd, boolean checkin, boolean all,
1084            String[] args) throws RemoteException {
1085        Parcel data = Parcel.obtain();
1086        Parcel reply = Parcel.obtain();
1087        data.writeInterfaceToken(IApplicationThread.descriptor);
1088        data.writeFileDescriptor(fd);
1089        data.writeInt(checkin ? 1 : 0);
1090        data.writeInt(all ? 1 : 0);
1091        data.writeStringArray(args);
1092        mRemote.transact(DUMP_MEM_INFO_TRANSACTION, data, reply, 0);
1093        reply.readException();
1094        Debug.MemoryInfo info = new Debug.MemoryInfo();
1095        info.readFromParcel(reply);
1096        data.recycle();
1097        reply.recycle();
1098        return info;
1099    }
1100
1101    public void dumpGfxInfo(FileDescriptor fd, String[] args) throws RemoteException {
1102        Parcel data = Parcel.obtain();
1103        data.writeInterfaceToken(IApplicationThread.descriptor);
1104        data.writeFileDescriptor(fd);
1105        data.writeStringArray(args);
1106        mRemote.transact(DUMP_GFX_INFO_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
1107        data.recycle();
1108    }
1109}
1110