diff options
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/pm/src/com/android/commands/pm/Pm.java | 101 | ||||
-rw-r--r-- | cmds/svc/src/com/android/commands/svc/DataCommand.java | 81 | ||||
-rw-r--r-- | cmds/svc/src/com/android/commands/svc/PowerCommand.java | 17 | ||||
-rw-r--r-- | cmds/svc/src/com/android/commands/svc/Svc.java | 29 | ||||
-rw-r--r-- | cmds/svc/src/com/android/commands/svc/WifiCommand.java | 78 |
5 files changed, 272 insertions, 34 deletions
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index b79ee26..09a140b 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -16,14 +16,15 @@ package com.android.commands.pm; +import android.content.ComponentName; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageDeleteObserver; import android.content.pm.IPackageInstallObserver; import android.content.pm.IPackageManager; +import android.content.pm.InstrumentationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; -import android.content.pm.PackageParser; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; import android.content.res.AssetManager; @@ -33,8 +34,9 @@ import android.os.RemoteException; import android.os.ServiceManager; import java.io.File; -import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.WeakHashMap; @@ -48,6 +50,9 @@ public final class Pm { private int mNextArg; private String mCurArgData; + private static final String PM_NOT_RUNNING_ERR = + "Error: Could not access the Package Manager. Is the system running?"; + public static void main(String[] args) { new Pm().run(args); } @@ -61,8 +66,7 @@ public final class Pm { mPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); if (mPm == null) { - System.err.println("Error Type 1: Could not access the Package Manager!"); - showUsage(); + System.err.println(PM_NOT_RUNNING_ERR); return; } @@ -114,6 +118,11 @@ public final class Pm { /** * Execute the list sub-command. + * + * pm list [package | packages] + * pm list permission-groups + * pm list permissions + * pm list instrumentation */ private void runList() { String type = nextArg(); @@ -128,6 +137,8 @@ public final class Pm { runListPermissionGroups(); } else if ("permissions".equals(type)) { runListPermissions(); + } else if ("instrumentation".equals(type)) { + runListInstrumentation(); } else { System.err.println("Error: unknown list type '" + type + "'"); showUsage(); @@ -173,6 +184,67 @@ public final class Pm { System.out.println(info.packageName); } } catch (RemoteException e) { + System.err.println(e.toString()); + System.err.println(PM_NOT_RUNNING_ERR); + } + } + + /** + * Lists all of the installed instrumentation, or all for a given package + * + * pm list instrumentation [package] [-f] + */ + private void runListInstrumentation() { + int flags = 0; // flags != 0 is only used to request meta-data + boolean showPackage = false; + String targetPackage = null; + + try { + String opt; + while ((opt=nextArg()) != null) { + if (opt.equals("-f")) { + showPackage = true; + } else if (opt.charAt(0) != '-') { + targetPackage = opt; + } else { + System.err.println("Error: Unknown option: " + opt); + showUsage(); + return; + } + } + } catch (RuntimeException ex) { + System.err.println("Error: " + ex.toString()); + showUsage(); + return; + } + + try { + List<InstrumentationInfo> list = mPm.queryInstrumentation(targetPackage, flags); + + // Sort by target package + Collections.sort(list, new Comparator<InstrumentationInfo>() { + public int compare(InstrumentationInfo o1, InstrumentationInfo o2) { + return o1.targetPackage.compareTo(o2.targetPackage); + } + }); + + int count = (list != null) ? list.size() : 0; + for (int p = 0; p < count; p++) { + InstrumentationInfo ii = list.get(p); + System.out.print("instrumentation:"); + if (showPackage) { + System.out.print(ii.sourceDir); + System.out.print("="); + } + ComponentName cn = new ComponentName(ii.packageName, ii.name); + System.out.print(cn.flattenToShortString()); + System.out.print(" (target="); + System.out.print(ii.targetPackage); + System.out.println(")"); + } + } catch (RemoteException e) { + System.err.println(e.toString()); + System.err.println(PM_NOT_RUNNING_ERR); } } @@ -190,6 +262,8 @@ public final class Pm { System.out.println(pgi.name); } } catch (RemoteException e) { + System.err.println(e.toString()); + System.err.println(PM_NOT_RUNNING_ERR); } } @@ -274,6 +348,8 @@ public final class Pm { -10000, 10000); } } catch (RemoteException e) { + System.err.println(e.toString()); + System.err.println(PM_NOT_RUNNING_ERR); } } @@ -472,6 +548,9 @@ public final class Pm { case PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY: s = "INSTALL_PARSE_FAILED_MANIFEST_EMPTY"; break; + case PackageManager.INSTALL_FAILED_OLDER_SDK: + s = "INSTALL_FAILED_OLDER_SDK"; + break; default: s = Integer.toString(result); break; @@ -523,6 +602,8 @@ public final class Pm { } } } catch (RemoteException e) { + System.err.println(e.toString()); + System.err.println(PM_NOT_RUNNING_ERR); } } @@ -575,6 +656,8 @@ public final class Pm { } } } catch (RemoteException e) { + System.err.println(e.toString()); + System.err.println(PM_NOT_RUNNING_ERR); } return obs.result; } @@ -591,6 +674,8 @@ public final class Pm { System.out.println(info.applicationInfo.sourceDir); } } catch (RemoteException e) { + System.err.println(e.toString()); + System.err.println(PM_NOT_RUNNING_ERR); } } @@ -606,7 +691,8 @@ public final class Pm { mResourceCache.put(pii.packageName, res); return res; } catch (RemoteException e) { - System.err.println("Package manager gone!"); + System.err.println(e.toString()); + System.err.println(PM_NOT_RUNNING_ERR); return null; } } @@ -662,6 +748,7 @@ public final class Pm { System.err.println(" pm list packages [-f]"); System.err.println(" pm list permission-groups"); System.err.println(" pm list permissions [-g] [-f] [-d] [-u] [GROUP]"); + System.err.println(" pm list instrumentation [-f] [TARGET-PACKAGE]"); System.err.println(" pm path PACKAGE"); System.err.println(" pm install [-l] [-r] PATH"); System.err.println(" pm uninstall [-k] PACKAGE"); @@ -680,6 +767,10 @@ public final class Pm { System.err.println("the -d option to only list dangerous permissions. Use"); System.err.println("the -u option to list only the permissions users will see."); System.err.println(""); + System.err.println("The list instrumentation command prints all instrumentations,"); + System.err.println("or only those that target a specified package. Use the -f option"); + System.err.println("to see their associated file."); + System.err.println(""); System.err.println("The path command prints the path to the .apk of a package."); System.err.println(""); System.err.println("The install command installs a package to the system. Use"); diff --git a/cmds/svc/src/com/android/commands/svc/DataCommand.java b/cmds/svc/src/com/android/commands/svc/DataCommand.java new file mode 100644 index 0000000..72cb86d --- /dev/null +++ b/cmds/svc/src/com/android/commands/svc/DataCommand.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.commands.svc; + +import android.os.ServiceManager; +import android.os.RemoteException; +import android.net.IConnectivityManager; +import android.net.ConnectivityManager; +import android.content.Context; +import com.android.internal.telephony.ITelephony; + +public class DataCommand extends Svc.Command { + public DataCommand() { + super("data"); + } + + public String shortHelp() { + return "Control mobile data connectivity"; + } + + public String longHelp() { + return shortHelp() + "\n" + + "\n" + + "usage: svc data [enable|disable]\n" + + " Turn mobile data on or off.\n\n" + + " svc data prefer\n" + + " Set mobile as the preferred data network\n"; + } + + public void run(String[] args) { + boolean validCommand = false; + if (args.length >= 2) { + boolean flag = false; + if ("enable".equals(args[1])) { + flag = true; + validCommand = true; + } else if ("disable".equals(args[1])) { + flag = false; + validCommand = true; + } else if ("prefer".equals(args[1])) { + IConnectivityManager connMgr = + IConnectivityManager.Stub.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); + try { + connMgr.setNetworkPreference(ConnectivityManager.TYPE_MOBILE); + } catch (RemoteException e) { + System.err.println("Failed to set preferred network: " + e); + } + return; + } + if (validCommand) { + ITelephony phoneMgr + = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); + try { + if (flag) { + phoneMgr.enableDataConnectivity(); + } else + phoneMgr.disableDataConnectivity(); + } + catch (RemoteException e) { + System.err.println("Mobile data operation failed: " + e); + } + return; + } + } + System.err.println(longHelp()); + } +}
\ No newline at end of file diff --git a/cmds/svc/src/com/android/commands/svc/PowerCommand.java b/cmds/svc/src/com/android/commands/svc/PowerCommand.java index 990837f..2b54f54 100644 --- a/cmds/svc/src/com/android/commands/svc/PowerCommand.java +++ b/cmds/svc/src/com/android/commands/svc/PowerCommand.java @@ -19,6 +19,8 @@ package com.android.commands.svc; import android.os.IPowerManager; import android.os.ServiceManager; import android.os.RemoteException; +import android.os.BatteryManager; +import android.content.Context; public class PowerCommand extends Svc.Command { public PowerCommand() { @@ -32,7 +34,7 @@ public class PowerCommand extends Svc.Command { public String longHelp() { return shortHelp() + "\n" + "\n" - + "usage: svc power stayon [true|false]\n" + + "usage: svc power stayon [true|false|usb|ac]\n" + " Set the 'keep awake while plugged in' setting.\n"; } @@ -40,18 +42,23 @@ public class PowerCommand extends Svc.Command { fail: { if (args.length >= 2) { if ("stayon".equals(args[1]) && args.length == 3) { - boolean val; + int val; if ("true".equals(args[2])) { - val = true; + val = BatteryManager.BATTERY_PLUGGED_AC | + BatteryManager.BATTERY_PLUGGED_USB; } else if ("false".equals(args[2])) { - val = false; + val = 0; + } else if ("usb".equals(args[2])) { + val = BatteryManager.BATTERY_PLUGGED_USB; + } else if ("ac".equals(args[2])) { + val = BatteryManager.BATTERY_PLUGGED_AC; } else { break fail; } IPowerManager pm - = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); + = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE)); try { pm.setStayOnSetting(val); } diff --git a/cmds/svc/src/com/android/commands/svc/Svc.java b/cmds/svc/src/com/android/commands/svc/Svc.java index ae397a0..1cd4c0d 100644 --- a/cmds/svc/src/com/android/commands/svc/Svc.java +++ b/cmds/svc/src/com/android/commands/svc/Svc.java @@ -16,20 +16,6 @@ package com.android.commands.svc; -import android.app.ActivityManagerNative; -import android.app.IActivityManager; -import android.app.IInstrumentationWatcher; -import android.content.ComponentName; -import android.content.Intent; -import android.net.Uri; -import android.os.RemoteException; -import android.os.Bundle; -import android.os.ServiceManager; -import android.view.IWindowManager; - -import java.util.Iterator; -import java.util.Set; - public class Svc { public static abstract class Command { @@ -49,13 +35,6 @@ public class Svc { } public static void main(String[] args) { - if (true) { - for (String a: args) { - System.err.print(a + " "); - } - System.err.println(); - } - if (args.length >= 1) { Command c = lookupCommand(args[0]); if (c != null) { @@ -66,7 +45,7 @@ public class Svc { COMMAND_HELP.run(args); } - private static final Command lookupCommand(String name) { + private static Command lookupCommand(String name) { final int N = COMMANDS.length; for (int i=0; i<N; i++) { Command c = COMMANDS[i]; @@ -112,7 +91,9 @@ public class Svc { }; public static final Command[] COMMANDS = new Command[] { - COMMAND_HELP, - new PowerCommand(), + COMMAND_HELP, + new PowerCommand(), + new DataCommand(), + new WifiCommand() }; } diff --git a/cmds/svc/src/com/android/commands/svc/WifiCommand.java b/cmds/svc/src/com/android/commands/svc/WifiCommand.java new file mode 100644 index 0000000..d29e8b2 --- /dev/null +++ b/cmds/svc/src/com/android/commands/svc/WifiCommand.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.commands.svc; + +import android.os.ServiceManager; +import android.os.RemoteException; +import android.net.wifi.IWifiManager; +import android.net.IConnectivityManager; +import android.net.ConnectivityManager; +import android.content.Context; + +public class WifiCommand extends Svc.Command { + public WifiCommand() { + super("wifi"); + } + + public String shortHelp() { + return "Control the Wi-Fi manager"; + } + + public String longHelp() { + return shortHelp() + "\n" + + "\n" + + "usage: svc wifi [enable|disable]\n" + + " Turn Wi-Fi on or off.\n\n" + + " svc wifi prefer\n" + + " Set Wi-Fi as the preferred data network\n"; + } + + public void run(String[] args) { + boolean validCommand = false; + if (args.length >= 2) { + boolean flag = false; + if ("enable".equals(args[1])) { + flag = true; + validCommand = true; + } else if ("disable".equals(args[1])) { + flag = false; + validCommand = true; + } else if ("prefer".equals(args[1])) { + IConnectivityManager connMgr = + IConnectivityManager.Stub.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); + try { + connMgr.setNetworkPreference(ConnectivityManager.TYPE_WIFI); + } catch (RemoteException e) { + System.err.println("Failed to set preferred network: " + e); + } + return; + } + if (validCommand) { + IWifiManager wifiMgr + = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE)); + try { + wifiMgr.setWifiEnabled(flag); + } + catch (RemoteException e) { + System.err.println("Wi-Fi operation failed: " + e); + } + return; + } + } + System.err.println(longHelp()); + } +}
\ No newline at end of file |