Android Open Source - adb-idea Adb Util






From Project

Back to project page adb-idea.

License

The source code is released under:

Apache License

If you think the Android project adb-idea listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.developerphil.adbidea.adb;
//from w w w. j  a  v  a  2s. c  o m
import com.android.ddmlib.AdbCommandRejectedException;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.ShellCommandUnresponsiveException;
import com.android.ddmlib.TimeoutException;
import com.developerphil.adbidea.adb.command.receiver.GenericReceiver;
import org.jetbrains.android.facet.AndroidFacet;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class AdbUtil {

    public static boolean isAppInstalled(IDevice device, String packageName) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
        GenericReceiver receiver = new GenericReceiver();
        // "pm list packages com.my.package" will return one line per package installed that corresponds to this package.
        // if this list is empty, we know for sure that the app is not installed
        device.executeShellCommand("pm list packages " + packageName, receiver, 5L, TimeUnit.MINUTES);

        //TODO make sure that it is the exact package name and not a subset.
        // e.g. if our app is called com.example but there is another app called com.example.another.app, it will match and return a false positive
        return !receiver.getAdbOutputLines().isEmpty();
    }


    /**
     * Computes the project's package while preserving backward compatibility between android studio 0.4.3 and 0.4.4
     */
    public static String computePackageName(AndroidFacet facet) {
        try {
            Object androidModuleInfo = facet.getClass().getMethod("getAndroidModuleInfo").invoke(facet);
            return (String) androidModuleInfo.getClass().getMethod("getPackage").invoke(androidModuleInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

}




Java Source Code List

com.developerphil.TestProjectMultiModule.MyActivity.java
com.developerphil.adbidea.action.AdbAction.java
com.developerphil.adbidea.action.ClearDataAction.java
com.developerphil.adbidea.action.ClearDataAndRestartAction.java
com.developerphil.adbidea.action.KillAction.java
com.developerphil.adbidea.action.RestartAction.java
com.developerphil.adbidea.action.StartAction.java
com.developerphil.adbidea.action.UninstallAction.java
com.developerphil.adbidea.adb.AdbFacade.java
com.developerphil.adbidea.adb.AdbUtil.java
com.developerphil.adbidea.adb.command.ClearDataAndRestartCommand.java
com.developerphil.adbidea.adb.command.ClearDataCommand.java
com.developerphil.adbidea.adb.command.CommandList.java
com.developerphil.adbidea.adb.command.Command.java
com.developerphil.adbidea.adb.command.KillCommand.java
com.developerphil.adbidea.adb.command.RestartPackageCommand.java
com.developerphil.adbidea.adb.command.StartDefaultActivityCommand.java
com.developerphil.adbidea.adb.command.UninstallCommand.java
com.developerphil.adbidea.adb.command.receiver.GenericReceiver.java
com.developerphil.adbidea.ui.DeviceChooserDialog.java
com.developerphil.adbidea.ui.ModuleChooserDialogHelper.java
com.developerphil.adbidea.ui.NotificationHelper.java
com.example.SecondModule.MySecondModuleActivity.java
com.example.app.MainActivity.java
com.example.untitled.MyActivity.java
org.joor.ReflectException.java
org.joor.Reflect.java