Search in sources :

Example 6 with PackageInfo

use of android.content.pm.PackageInfo in project atlas by alibaba.

the class DelegateClassLoader method getPackageVersion.

private static int getPackageVersion() {
    PackageInfo packageInfo = null;
    // 获取当前的版本号
    try {
        PackageManager packageManager = RuntimeVariables.androidApplication.getPackageManager();
        packageInfo = packageManager.getPackageInfo(RuntimeVariables.androidApplication.getPackageName(), 0);
    } catch (Exception e) {
        // 不可能发生
        packageInfo = new PackageInfo();
    }
    return packageInfo.versionCode;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 7 with PackageInfo

use of android.content.pm.PackageInfo in project atlas by alibaba.

the class Framework method checkInstallDebugBundle.

/**
     * for debug not release
     */
static void checkInstallDebugBundle() {
    File debugDirectory = new File(ATLAS_DEBUG_DIRECTORY);
    if (debugDirectory.exists()) {
        File[] bundles = debugDirectory.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String filename) {
                if (filename.endsWith(".so")) {
                    return true;
                }
                return false;
            }
        });
        if (bundles != null) {
            String[] packageNames = new String[bundles.length];
            String[] versions = new String[bundles.length];
            for (int x = 0; x < bundles.length; x++) {
                versions[x] = "1.0.0";
                if (bundles[x].getName().startsWith("kernal") || bundles[x].getName().contains("com_taobao_mainDex")) {
                    //主dexbundle
                    packageNames[x] = "com.taobao.maindex";
                } else {
                    //业务bundle
                    PackageInfo info = RuntimeVariables.androidApplication.getPackageManager().getPackageArchiveInfo(bundles[x].getAbsolutePath(), 0);
                    if (info != null) {
                        packageNames[x] = info.applicationInfo.packageName;
                    } else {
                        String fileName = bundles[x].getName();
                        fileName = fileName.substring(3, fileName.length() - 3);
                        packageNames[x] = fileName.replace("_", ".");
                    }
                }
            }
            try {
                Atlas.getInstance().installOrUpdate(packageNames, bundles, versions, -1);
                Log.d("Framework", "patch success and delete file");
                try {
                    for (File installFile : bundles) {
                        if (installFile.exists()) {
                            installFile.delete();
                        }
                    }
                } catch (Exception e) {
                }
            } catch (BundleException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) PackageInfo(android.content.pm.PackageInfo) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleException(org.osgi.framework.BundleException) LowDiskException(android.taobao.atlas.runtime.LowDiskException) IOException(java.io.IOException)

Example 8 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class BackupManagerService method allAgentPackages.

// Returns the set of all applications that define an android:backupAgent attribute
List<PackageInfo> allAgentPackages() {
    // !!! TODO: cache this and regenerate only when necessary
    int flags = PackageManager.GET_SIGNATURES;
    List<PackageInfo> packages = mPackageManager.getInstalledPackages(flags);
    int N = packages.size();
    for (int a = N - 1; a >= 0; a--) {
        PackageInfo pkg = packages.get(a);
        try {
            ApplicationInfo app = pkg.applicationInfo;
            if (((app.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) || app.backupAgentName == null) {
                packages.remove(a);
            } else {
                // we will need the shared library path, so look that up and store it here
                app = mPackageManager.getApplicationInfo(pkg.packageName, PackageManager.GET_SHARED_LIBRARY_FILES);
                pkg.applicationInfo.sharedLibraryFiles = app.sharedLibraryFiles;
            }
        } catch (NameNotFoundException e) {
            packages.remove(a);
        }
    }
    return packages;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 9 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class BackupManagerService method clearApplicationDataSynchronous.

// clear an application's data, blocking until the operation completes or times out
void clearApplicationDataSynchronous(String packageName) {
    // Don't wipe packages marked allowClearUserData=false
    try {
        PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
        if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) == 0) {
            if (MORE_DEBUG)
                Slog.i(TAG, "allowClearUserData=false so not wiping " + packageName);
            return;
        }
    } catch (NameNotFoundException e) {
        Slog.w(TAG, "Tried to clear data for " + packageName + " but not found");
        return;
    }
    ClearDataObserver observer = new ClearDataObserver();
    synchronized (mClearDataLock) {
        mClearingData = true;
        try {
            mActivityManager.clearApplicationUserData(packageName, observer, 0);
        } catch (RemoteException e) {
        // can't happen because the activity manager is in this process
        }
        // only wait 10 seconds for the clear data to happen
        long timeoutMark = System.currentTimeMillis() + TIMEOUT_INTERVAL;
        while (mClearingData && (System.currentTimeMillis() < timeoutMark)) {
            try {
                mClearDataLock.wait(5000);
            } catch (InterruptedException e) {
                // won't happen, but still.
                mClearingData = false;
            }
        }
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Example 10 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class BackupManagerService method restoreAtInstall.

// An application being installed will need a restore pass, then the Package Manager
// will need to be told when the restore is finished.
public void restoreAtInstall(String packageName, int token) {
    if (Binder.getCallingUid() != Process.SYSTEM_UID) {
        Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid() + " attemping install-time restore");
        return;
    }
    long restoreSet = getAvailableRestoreToken(packageName);
    if (DEBUG)
        Slog.v(TAG, "restoreAtInstall pkg=" + packageName + " token=" + Integer.toHexString(token) + " restoreSet=" + Long.toHexString(restoreSet));
    if (mAutoRestore && mProvisioned && restoreSet != 0) {
        // okay, we're going to attempt a restore of this package from this restore set.
        // The eventual message back into the Package Manager to run the post-install
        // steps for 'token' will be issued from the restore handling code.
        // We can use a synthetic PackageInfo here because:
        //   1. We know it's valid, since the Package Manager supplied the name
        //   2. Only the packageName field will be used by the restore code
        PackageInfo pkg = new PackageInfo();
        pkg.packageName = packageName;
        mWakelock.acquire();
        Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
        msg.obj = new RestoreParams(getTransport(mCurrentTransport), null, restoreSet, pkg, token, true);
        mBackupHandler.sendMessage(msg);
    } else {
        // Manager to proceed with the post-install handling for this package.
        if (DEBUG)
            Slog.v(TAG, "No restore set -- skipping restore");
        try {
            mPackageManagerBinder.finishPackageInstall(token);
        } catch (RemoteException e) {
        /* can't happen */
        }
    }
}
Also used : Message(android.os.Message) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1566 PackageManager (android.content.pm.PackageManager)702 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