Search in sources :

Example 91 with PackageInfo

use of android.content.pm.PackageInfo in project DroidPlugin by DroidPluginTeam.

the class IPluginManagerImpl method loadAllPlugin.

private void loadAllPlugin(Context context) {
    long b = System.currentTimeMillis();
    ArrayList<File> apkfiles = null;
    try {
        apkfiles = new ArrayList<File>();
        File baseDir = new File(PluginDirHelper.getBaseDir(context));
        File[] dirs = baseDir.listFiles();
        for (File dir : dirs) {
            if (dir.isDirectory()) {
                File file = new File(dir, "apk/base-1.apk");
                if (file.exists()) {
                    apkfiles.add(file);
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "scan a apk file error", e);
    }
    Log.i(TAG, "Search apk cost %s ms", (System.currentTimeMillis() - b));
    b = System.currentTimeMillis();
    if (apkfiles != null && apkfiles.size() > 0) {
        for (File pluginFile : apkfiles) {
            long b1 = System.currentTimeMillis();
            try {
                PluginPackageParser pluginPackageParser = new PluginPackageParser(mContext, pluginFile);
                Signature[] signatures = readSignatures(pluginPackageParser.getPackageName());
                if (signatures == null || signatures.length <= 0) {
                    pluginPackageParser.collectCertificates(0);
                    PackageInfo info = pluginPackageParser.getPackageInfo(PackageManager.GET_SIGNATURES);
                    saveSignatures(info);
                } else {
                    mSignatureCache.put(pluginPackageParser.getPackageName(), signatures);
                    pluginPackageParser.writeSignature(signatures);
                }
                if (!mPluginCache.containsKey(pluginPackageParser.getPackageName())) {
                    mPluginCache.put(pluginPackageParser.getPackageName(), pluginPackageParser);
                }
            } catch (Throwable e) {
                Log.e(TAG, "parse a apk file error %s", e, pluginFile.getPath());
            } finally {
                Log.i(TAG, "Parse %s apk cost %s ms", pluginFile.getPath(), (System.currentTimeMillis() - b1));
            }
        }
    }
    Log.i(TAG, "Parse all apk cost %s ms", (System.currentTimeMillis() - b));
    b = System.currentTimeMillis();
    try {
        mActivityManagerService.onCreate(IPluginManagerImpl.this);
    } catch (Throwable e) {
        Log.e(TAG, "mActivityManagerService.onCreate", e);
    }
    Log.i(TAG, "ActivityManagerService.onCreate %s ms", (System.currentTimeMillis() - b));
}
Also used : PackageInfo(android.content.pm.PackageInfo) Signature(android.content.pm.Signature) PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) File(java.io.File) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 92 with PackageInfo

use of android.content.pm.PackageInfo in project DroidPlugin by DroidPluginTeam.

the class IPluginManagerImpl method getInstalledPackages.

@Override
public List<PackageInfo> getInstalledPackages(int flags) throws RemoteException {
    waitForReadyInner();
    try {
        enforcePluginFileExists();
        List<PackageInfo> infos = new ArrayList<PackageInfo>(mPluginCache.size());
        if (shouldNotBlockOtherInfo()) {
            for (PluginPackageParser pluginPackageParser : mPluginCache.values()) {
                infos.add(pluginPackageParser.getPackageInfo(flags));
            }
        } else {
            List<String> pkgs = mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid());
            for (PluginPackageParser pluginPackageParser : mPluginCache.values()) {
                if (pkgs.contains(pluginPackageParser.getPackageName())) {
                    infos.add(pluginPackageParser.getPackageInfo(flags));
                }
            }
        }
        return infos;
    } catch (Exception e) {
        handleException(e);
    }
    return null;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 93 with PackageInfo

use of android.content.pm.PackageInfo in project DroidPlugin by DroidPluginTeam.

the class IPluginManagerImpl method loadHostRequestedPermission.

private void loadHostRequestedPermission() {
    try {
        mHostRequestedPermission.clear();
        PackageManager pm = mContext.getPackageManager();
        PackageInfo pms = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_PERMISSIONS);
        if (pms != null && pms.requestedPermissions != null && pms.requestedPermissions.length > 0) {
            for (String requestedPermission : pms.requestedPermissions) {
                mHostRequestedPermission.add(requestedPermission);
            }
        }
    } catch (Exception e) {
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 94 with PackageInfo

use of android.content.pm.PackageInfo in project AndroidChromium by JackyAndroid.

the class WebApkUpdateManager method updateIfNeeded.

/**
     * Checks whether the WebAPK's Web Manifest has changed. Requests an updated WebAPK if the
     * Web Manifest has changed. Skips the check if the check was done recently.
     * @param tab  The tab of the WebAPK.
     * @param info The WebappInfo of the WebAPK.
     */
public void updateIfNeeded(Tab tab, WebappInfo info) {
    PackageInfo packageInfo = readPackageInfoFromAndroidManifest(info.webApkPackageName());
    if (packageInfo == null) {
        return;
    }
    mVersionCode = packageInfo.versionCode;
    final Bundle metadata = packageInfo.applicationInfo.metaData;
    mShellApkVersion = IntentUtils.safeGetInt(metadata, WebApkMetaDataKeys.SHELL_APK_VERSION, 0);
    mUpgradeDetector = new ManifestUpgradeDetector(tab, info, metadata, this);
    WebappRegistry.FetchWebappDataStorageCallback callback = new WebappRegistry.FetchWebappDataStorageCallback() {

        @Override
        public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
            if (forceUpgrade(storage)) {
                mForceUpgrade = true;
            }
            // TODO(pkotwicz|hanxi): Request upgrade if ShellAPK version changes if
            // ManifestUpgradeDetector cannot fetch the Web Manifest. For instance, the
            // web developer may have removed the Web Manifest from their site.
            // (http://crbug.com/639536)
            long sinceLastCheckDuration = System.currentTimeMillis() - storage.getLastCheckForWebManifestUpdateTime();
            if (sinceLastCheckDuration > FULL_CHECK_UPDATE_INTERVAL || mForceUpgrade) {
                if (mUpgradeDetector.start()) {
                    // crbug.com/636525. The timestamp of the last check for updated
                    // Web Manifest should be updated after the detector finds the
                    // Web Manifest, not when the detector is started.
                    storage.updateTimeOfLastCheckForUpdatedWebManifest();
                }
            }
        }
    };
    WebappRegistry.getWebappDataStorage(info.id(), callback);
}
Also used : FetchWebappDataStorageCallback(org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorageCallback) PackageInfo(android.content.pm.PackageInfo) Bundle(android.os.Bundle) FetchWebappDataStorageCallback(org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorageCallback)

Example 95 with PackageInfo

use of android.content.pm.PackageInfo in project AndroidDevelop by 7449.

the class RootUtils method isApk.

/**
     * hide之后的app是false
     */
static boolean isApk(String packageName) {
    final PackageManager packageManager = App.getApp().getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    if (pinfo != null) {
        for (PackageInfo packageInfo : pinfo) {
            if (packageInfo.packageName.equals(packageName)) {
                return true;
            }
        }
    }
    return false;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1567 PackageManager (android.content.pm.PackageManager)703 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)327 ApplicationInfo (android.content.pm.ApplicationInfo)217 Test (org.junit.Test)193 RemoteException (android.os.RemoteException)179 ArrayList (java.util.ArrayList)166 Intent (android.content.Intent)126 IOException (java.io.IOException)121 Context (android.content.Context)81 IPackageManager (android.content.pm.IPackageManager)65 ResolveInfo (android.content.pm.ResolveInfo)65 File (java.io.File)62 SuppressLint (android.annotation.SuppressLint)58 ComponentName (android.content.ComponentName)57 ActivityInfo (android.content.pm.ActivityInfo)57 View (android.view.View)57 TextView (android.widget.TextView)54 Signature (android.content.pm.Signature)51 OverlayInfo (android.content.om.OverlayInfo)42