/* Launch an intent stated on the command line as an activity. -*- c-file-style: "GNU" -*- Copyright (C) 2025 Free Software Foundation, Inc. This file is part of GNU Emacs. GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ package ats; import android.app.ActivityManagerNative; import android.app.ActivityThread; import android.app.IActivityManager; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.os.Looper; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.net.Uri; import java.lang.IllegalArgumentException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public final class AtsStub { public static final String IDENT = "$Id: AtsStub.java,v 1.4 2024/06/30 04:24:39 jw Exp $"; private static void neutralizeApplicationThread (ActivityThread thread) { Field field; try { field = ActivityThread.class.getDeclaredField ("mAppThread"); field.setAccessible (true); field.set (thread, null); } catch (NoSuchFieldException x) { x.printStackTrace (); } catch (IllegalAccessException x) { x.printStackTrace (); } } private static int main1 (String[] argv) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { ActivityThread thread; Context context; Looper.prepare (); thread = ActivityThread.systemMain (); context = thread.getSystemContext (); if (argv.length < 1 || argv[0].equals ("--help")) { System.out.println ("AtsStub [start] [--user ] "); System.out.println (" where INTENT is a series of arguments defining an Intent,"); System.out.println (" namely,"); System.out.println (" -a "); System.out.println (" -d "); System.out.println (" -t "); System.out.println (" -c "); System.out.println (" -n "); System.out.println (" -e or --es "); System.out.println (" --esn "); System.out.println (" --ei "); System.out.println (" --eu "); System.out.println (" --ecn "); System.out.println (" --eia , ..."); System.out.println (" --el "); System.out.println (" --ela , ..."); System.out.println (" --ef "); System.out.println (" --efa "); System.out.println (" --esa , ..."); System.out.println (" --ez "); System.out.println (" -f "); return 0; } else if (argv[0].equals ("start")) { Intent intent; int i, userID = 0; String token, type; Uri data; boolean debug; intent = new Intent (); debug = false; data = null; type = null; for (i = 1; i < argv.length; ++i) { int j; token = argv[i]; if (token.equals ("-a")) intent.setAction (argv[++i]); else if (token.equals ("-d")) data = Uri.parse (argv[++i]); else if (token.equals ("-t")) type = argv[++i]; else if (token.equals ("-c")) intent.addCategory (argv[++i]); else if (token.equals ("-e") || token.equals ("--es")) { intent.putExtra (argv[i + 1], argv[i + 2]); i += 2; } else if (token.equals ("--esn")) intent.putExtra (argv[++i], (String) null); else if (token.equals ("--ei")) { int value = Integer.valueOf (argv[i + 2]); intent.putExtra (argv[i + 1], value); i += 2; } else if (token.equals ("--eu")) { Uri value = Uri.parse (argv[i + 2]); intent.putExtra (argv[i + 1], value); i += 2; } else if (token.equals ("--ecn")) { ComponentName value = ComponentName.unflattenFromString (argv[i + 2]); intent.putExtra (argv[i + 1], value); i += 2; } else if (token.equals ("--eia")) { String values[] = argv[i + 2].split (","); int array[] = new int[values.length]; for (j = 0; j < values.length; ++j) array[j] = Integer.valueOf (values[j]); intent.putExtra (argv[i + 1], array); i += 2; } else if (token.equals ("--el")) { long value = Long.valueOf (argv[i + 2]); intent.putExtra (argv[i + 1], value); i += 2; } else if (token.equals ("--ela")) { String values[] = argv[i + 2].split (","); long array[] = new long[values.length]; for (j = 0; j < values.length; ++j) array[j] = Long.valueOf (values[j]); intent.putExtra (argv[i + 1], array); i += 2; } else if (token.equals ("--ef")) { float value = Float.valueOf (argv[i + 2]); intent.putExtra (argv[i + 1], value); i += 2; } else if (token.equals ("--efa")) { String values[] = argv[i + 2].split (","); float array[] = new float[values.length]; for (j = 0; j < values.length; ++j) array[j] = Float.valueOf (values[j]); intent.putExtra (argv[i + 1], array); i += 2; } else if (token.equals ("--esa")) { String[] strings; strings = argv[i + 2].split ("(?