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