Search in sources :

Example 6 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class Pm method runCreateUser.

public void runCreateUser() {
    String name;
    String arg = nextArg();
    if (arg == null) {
        System.err.println("Error: no user name specified.");
        return;
    }
    name = arg;
    try {
        final UserInfo info = mUm.createUser(name, 0);
        if (info != null) {
            System.out.println("Success: created user id " + info.id);
        } else {
            System.err.println("Error: couldn't create User.");
        }
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
}
Also used : UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException)

Example 7 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class Pm method runInstall.

private void runInstall() {
    int installFlags = PackageManager.INSTALL_ALL_USERS;
    String installerPackageName = null;
    String opt;
    String algo = null;
    byte[] iv = null;
    byte[] key = null;
    String macAlgo = null;
    byte[] macKey = null;
    byte[] tag = null;
    String originatingUriString = null;
    String referrer = null;
    while ((opt = nextOption()) != null) {
        if (opt.equals("-l")) {
            installFlags |= PackageManager.INSTALL_FORWARD_LOCK;
        } else if (opt.equals("-r")) {
            installFlags |= PackageManager.INSTALL_REPLACE_EXISTING;
        } else if (opt.equals("-i")) {
            installerPackageName = nextOptionData();
            if (installerPackageName == null) {
                System.err.println("Error: no value specified for -i");
                return;
            }
        } else if (opt.equals("-t")) {
            installFlags |= PackageManager.INSTALL_ALLOW_TEST;
        } else if (opt.equals("-s")) {
            // Override if -s option is specified.
            installFlags |= PackageManager.INSTALL_EXTERNAL;
        } else if (opt.equals("-f")) {
            // Override if -s option is specified.
            installFlags |= PackageManager.INSTALL_INTERNAL;
        } else if (opt.equals("-d")) {
            installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE;
        } else if (opt.equals("--algo")) {
            algo = nextOptionData();
            if (algo == null) {
                System.err.println("Error: must supply argument for --algo");
                return;
            }
        } else if (opt.equals("--iv")) {
            iv = hexToBytes(nextOptionData());
            if (iv == null) {
                System.err.println("Error: must supply argument for --iv");
                return;
            }
        } else if (opt.equals("--key")) {
            key = hexToBytes(nextOptionData());
            if (key == null) {
                System.err.println("Error: must supply argument for --key");
                return;
            }
        } else if (opt.equals("--macalgo")) {
            macAlgo = nextOptionData();
            if (macAlgo == null) {
                System.err.println("Error: must supply argument for --macalgo");
                return;
            }
        } else if (opt.equals("--mackey")) {
            macKey = hexToBytes(nextOptionData());
            if (macKey == null) {
                System.err.println("Error: must supply argument for --mackey");
                return;
            }
        } else if (opt.equals("--tag")) {
            tag = hexToBytes(nextOptionData());
            if (tag == null) {
                System.err.println("Error: must supply argument for --tag");
                return;
            }
        } else if (opt.equals("--originating-uri")) {
            originatingUriString = nextOptionData();
            if (originatingUriString == null) {
                System.err.println("Error: must supply argument for --originating-uri");
                return;
            }
        } else if (opt.equals("--referrer")) {
            referrer = nextOptionData();
            if (referrer == null) {
                System.err.println("Error: must supply argument for --referrer");
                return;
            }
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    final ContainerEncryptionParams encryptionParams;
    if (algo != null || iv != null || key != null || macAlgo != null || macKey != null || tag != null) {
        if (algo == null || iv == null || key == null) {
            System.err.println("Error: all of --algo, --iv, and --key must be specified");
            return;
        }
        if (macAlgo != null || macKey != null || tag != null) {
            if (macAlgo == null || macKey == null || tag == null) {
                System.err.println("Error: all of --macalgo, --mackey, and --tag must " + "be specified");
                return;
            }
        }
        try {
            final SecretKey encKey = new SecretKeySpec(key, "RAW");
            final SecretKey macSecretKey;
            if (macKey == null || macKey.length == 0) {
                macSecretKey = null;
            } else {
                macSecretKey = new SecretKeySpec(macKey, "RAW");
            }
            encryptionParams = new ContainerEncryptionParams(algo, new IvParameterSpec(iv), encKey, macAlgo, null, macSecretKey, tag, -1, -1, -1);
        } catch (InvalidAlgorithmParameterException e) {
            e.printStackTrace();
            return;
        }
    } else {
        encryptionParams = null;
    }
    final Uri apkURI;
    final Uri verificationURI;
    final Uri originatingURI;
    final Uri referrerURI;
    if (originatingUriString != null) {
        originatingURI = Uri.parse(originatingUriString);
    } else {
        originatingURI = null;
    }
    if (referrer != null) {
        referrerURI = Uri.parse(referrer);
    } else {
        referrerURI = null;
    }
    // Populate apkURI, must be present
    final String apkFilePath = nextArg();
    System.err.println("\tpkg: " + apkFilePath);
    if (apkFilePath != null) {
        apkURI = Uri.fromFile(new File(apkFilePath));
    } else {
        System.err.println("Error: no package specified");
        return;
    }
    // Populate verificationURI, optionally present
    final String verificationFilePath = nextArg();
    if (verificationFilePath != null) {
        System.err.println("\tver: " + verificationFilePath);
        verificationURI = Uri.fromFile(new File(verificationFilePath));
    } else {
        verificationURI = null;
    }
    PackageInstallObserver obs = new PackageInstallObserver();
    try {
        VerificationParams verificationParams = new VerificationParams(verificationURI, originatingURI, referrerURI, VerificationParams.NO_UID, null);
        mPm.installPackageWithVerificationAndEncryption(apkURI, obs, installFlags, installerPackageName, verificationParams, encryptionParams);
        synchronized (obs) {
            while (!obs.finished) {
                try {
                    obs.wait();
                } catch (InterruptedException e) {
                }
            }
            if (obs.result == PackageManager.INSTALL_SUCCEEDED) {
                System.out.println("Success");
            } else {
                System.err.println("Failure [" + installFailureToString(obs.result) + "]");
            }
        }
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ContainerEncryptionParams(android.content.pm.ContainerEncryptionParams) VerificationParams(android.content.pm.VerificationParams) Uri(android.net.Uri) SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) RemoteException(android.os.RemoteException) File(java.io.File) IPackageInstallObserver(android.content.pm.IPackageInstallObserver)

Example 8 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class Pm method runListFeatures.

/**
     * Lists all of the features supported by the current device.
     *
     * pm list features
     */
private void runListFeatures() {
    try {
        List<FeatureInfo> list = new ArrayList<FeatureInfo>();
        FeatureInfo[] rawList = mPm.getSystemAvailableFeatures();
        for (int i = 0; i < rawList.length; i++) {
            list.add(rawList[i]);
        }
        // Sort by name
        Collections.sort(list, new Comparator<FeatureInfo>() {

            public int compare(FeatureInfo o1, FeatureInfo o2) {
                if (o1.name == o2.name)
                    return 0;
                if (o1.name == null)
                    return -1;
                if (o2.name == null)
                    return 1;
                return o1.name.compareTo(o2.name);
            }
        });
        int count = (list != null) ? list.size() : 0;
        for (int p = 0; p < count; p++) {
            FeatureInfo fi = list.get(p);
            System.out.print("feature:");
            if (fi.name != null)
                System.out.println(fi.name);
            else
                System.out.println("reqGlEsVersion=0x" + Integer.toHexString(fi.reqGlEsVersion));
        }
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
}
Also used : ArrayList(java.util.ArrayList) FeatureInfo(android.content.pm.FeatureInfo) RemoteException(android.os.RemoteException)

Example 9 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class Pm method runListInstrumentation.

/**
     * Lists all of the installed instrumentation, or all for a given package
     *
     * pm list instrumentation [package] [-f]
     */
private void runListInstrumentation() {
    // flags != 0 is only used to request meta-data
    int flags = 0;
    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);
                return;
            }
        }
    } catch (RuntimeException ex) {
        System.err.println("Error: " + ex.toString());
        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);
    }
}
Also used : InstrumentationInfo(android.content.pm.InstrumentationInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 10 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class Pm method runListPermissionGroups.

/**
     * Lists all the known permission groups.
     */
private void runListPermissionGroups() {
    try {
        List<PermissionGroupInfo> pgs = mPm.getAllPermissionGroups(0);
        int count = pgs.size();
        for (int p = 0; p < count; p++) {
            PermissionGroupInfo pgi = pgs.get(p);
            System.out.print("permission group:");
            System.out.println(pgi.name);
        }
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
}
Also used : PermissionGroupInfo(android.content.pm.PermissionGroupInfo) RemoteException(android.os.RemoteException)

Aggregations

RemoteException (android.os.RemoteException)4527 Intent (android.content.Intent)595 IBinder (android.os.IBinder)480 Bundle (android.os.Bundle)461 Point (android.graphics.Point)423 IOException (java.io.IOException)381 PendingIntent (android.app.PendingIntent)274 ComponentName (android.content.ComponentName)265 ArrayList (java.util.ArrayList)248 ApplicationInfo (android.content.pm.ApplicationInfo)190 IPackageManager (android.content.pm.IPackageManager)190 Message (android.os.Message)184 Uri (android.net.Uri)157 UserHandle (android.os.UserHandle)154 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)151 Cursor (android.database.Cursor)150 Configuration (android.content.res.Configuration)133 UserInfo (android.content.pm.UserInfo)129 AndroidRuntimeException (android.util.AndroidRuntimeException)128 ParcelFileDescriptor (android.os.ParcelFileDescriptor)126