Search in sources :

Example 26 with ApplicationInfo

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

the class Vpn method establish.

/**
     * Establish a VPN network and return the file descriptor of the VPN
     * interface. This methods returns {@code null} if the application is
     * revoked or not prepared.
     *
     * @param config The parameters to configure the network.
     * @return The file descriptor of the VPN interface.
     */
public synchronized ParcelFileDescriptor establish(VpnConfig config) {
    // Check if the caller is already prepared.
    PackageManager pm = mContext.getPackageManager();
    ApplicationInfo app = null;
    try {
        app = pm.getApplicationInfo(mPackage, 0);
    } catch (Exception e) {
        return null;
    }
    if (Binder.getCallingUid() != app.uid) {
        return null;
    }
    // Check if the service is properly declared.
    Intent intent = new Intent(VpnConfig.SERVICE_INTERFACE);
    intent.setClassName(mPackage, config.user);
    ResolveInfo info = pm.resolveService(intent, 0);
    if (info == null) {
        throw new SecurityException("Cannot find " + config.user);
    }
    if (!BIND_VPN_SERVICE.equals(info.serviceInfo.permission)) {
        throw new SecurityException(config.user + " does not require " + BIND_VPN_SERVICE);
    }
    // Load the label.
    String label = app.loadLabel(pm).toString();
    // Load the icon and convert it into a bitmap.
    Drawable icon = app.loadIcon(pm);
    Bitmap bitmap = null;
    if (icon.getIntrinsicWidth() > 0 && icon.getIntrinsicHeight() > 0) {
        int width = mContext.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
        int height = mContext.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        icon.setBounds(0, 0, width, height);
        bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(bitmap);
        icon.draw(c);
        c.setBitmap(null);
    }
    // Configure the interface. Abort if any of these steps fails.
    ParcelFileDescriptor tun = ParcelFileDescriptor.adoptFd(jniCreate(config.mtu));
    try {
        updateState(DetailedState.CONNECTING, "establish");
        String interfaze = jniGetName(tun.getFd());
        if (jniSetAddresses(interfaze, config.addresses) < 1) {
            throw new IllegalArgumentException("At least one address must be specified");
        }
        if (config.routes != null) {
            jniSetRoutes(interfaze, config.routes);
        }
        Connection connection = new Connection();
        if (!mContext.bindService(intent, connection, Context.BIND_AUTO_CREATE)) {
            throw new IllegalStateException("Cannot bind " + config.user);
        }
        if (mConnection != null) {
            mContext.unbindService(mConnection);
        }
        if (mInterface != null && !mInterface.equals(interfaze)) {
            jniReset(mInterface);
        }
        mConnection = connection;
        mInterface = interfaze;
    } catch (RuntimeException e) {
        updateState(DetailedState.FAILED, "establish");
        IoUtils.closeQuietly(tun);
        throw e;
    }
    Log.i(TAG, "Established by " + config.user + " on " + mInterface);
    // Fill more values.
    config.user = mPackage;
    config.interfaze = mInterface;
    // Override DNS servers and show the notification.
    final long token = Binder.clearCallingIdentity();
    try {
        mCallback.override(config.dnsServers, config.searchDomains);
        showNotification(config, label, bitmap);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    // TODO: ensure that contract class eventually marks as connected
    updateState(DetailedState.AUTHENTICATING, "establish");
    return tun;
}
Also used : Canvas(android.graphics.Canvas) ApplicationInfo(android.content.pm.ApplicationInfo) Drawable(android.graphics.drawable.Drawable) ServiceConnection(android.content.ServiceConnection) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException) ResolveInfo(android.content.pm.ResolveInfo) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 27 with ApplicationInfo

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

the class CompatModePackages method saveCompatModes.

void saveCompatModes() {
    HashMap<String, Integer> pkgs;
    synchronized (mService) {
        pkgs = new HashMap<String, Integer>(mPackages);
    }
    FileOutputStream fos = null;
    try {
        fos = mFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, "utf-8");
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        out.startTag(null, "compat-packages");
        final IPackageManager pm = AppGlobals.getPackageManager();
        final int screenLayout = mService.mConfiguration.screenLayout;
        final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
        final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Integer> entry = it.next();
            String pkg = entry.getKey();
            int mode = entry.getValue();
            if (mode == 0) {
                continue;
            }
            ApplicationInfo ai = null;
            try {
                ai = pm.getApplicationInfo(pkg, 0, 0);
            } catch (RemoteException e) {
            }
            if (ai == null) {
                continue;
            }
            CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, smallestScreenWidthDp, false);
            if (info.alwaysSupportsScreen()) {
                continue;
            }
            if (info.neverSupportsScreen()) {
                continue;
            }
            out.startTag(null, "pkg");
            out.attribute(null, "name", pkg);
            out.attribute(null, "mode", Integer.toString(mode));
            out.endTag(null, "pkg");
        }
        out.endTag(null, "compat-packages");
        out.endDocument();
        mFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing compat packages", e1);
        if (fos != null) {
            mFile.failWrite(fos);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageManager(android.content.pm.IPackageManager) FileOutputStream(java.io.FileOutputStream) RemoteException(android.os.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 28 with ApplicationInfo

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

the class CompatModePackages method handlePackageAddedLocked.

public void handlePackageAddedLocked(String packageName, boolean updated) {
    ApplicationInfo ai = null;
    try {
        ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
    } catch (RemoteException e) {
    }
    if (ai == null) {
        return;
    }
    CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
    final boolean mayCompat = !ci.alwaysSupportsScreen() && !ci.neverSupportsScreen();
    if (updated) {
        // any current settings for it.
        if (!mayCompat && mPackages.containsKey(packageName)) {
            mPackages.remove(packageName);
            mHandler.removeMessages(MSG_WRITE);
            Message msg = mHandler.obtainMessage(MSG_WRITE);
            mHandler.sendMessageDelayed(msg, 10000);
        }
    }
}
Also used : Message(android.os.Message) ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) RemoteException(android.os.RemoteException)

Example 29 with ApplicationInfo

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

the class NetworkPolicyManagerService method updateRulesForRestrictBackgroundLocked.

/**
     * Update rules that might be changed by {@link #mRestrictBackground} value.
     */
private void updateRulesForRestrictBackgroundLocked() {
    final PackageManager pm = mContext.getPackageManager();
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    // update rules for all installed applications
    final List<UserInfo> users = um.getUsers();
    final List<ApplicationInfo> apps = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
    for (UserInfo user : users) {
        for (ApplicationInfo app : apps) {
            final int uid = UserHandle.getUid(user.id, app.uid);
            updateRulesForUidLocked(uid);
        }
    }
    // limit data usage for some internal system services
    updateRulesForUidLocked(android.os.Process.MEDIA_UID);
    updateRulesForUidLocked(android.os.Process.DRM_UID);
}
Also used : PackageManager(android.content.pm.PackageManager) UserManager(android.os.UserManager) ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo)

Example 30 with ApplicationInfo

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

the class PackageManagerService method getPackageSizeInfoLI.

private boolean getPackageSizeInfoLI(String packageName, int userHandle, PackageStats pStats) {
    if (packageName == null) {
        Slog.w(TAG, "Attempt to get size of null packageName.");
        return false;
    }
    PackageParser.Package p;
    boolean dataOnly = false;
    String libDirPath = null;
    String asecPath = null;
    synchronized (mPackages) {
        p = mPackages.get(packageName);
        PackageSetting ps = mSettings.mPackages.get(packageName);
        if (p == null) {
            dataOnly = true;
            if ((ps == null) || (ps.pkg == null)) {
                Slog.w(TAG, "Package named '" + packageName + "' doesn't exist.");
                return false;
            }
            p = ps.pkg;
        }
        if (ps != null) {
            libDirPath = ps.nativeLibraryPathString;
        }
        if (p != null && (isExternal(p) || isForwardLocked(p))) {
            String secureContainerId = cidFromCodePath(p.applicationInfo.sourceDir);
            if (secureContainerId != null) {
                asecPath = PackageHelper.getSdFilesystem(secureContainerId);
            }
        }
    }
    String publicSrcDir = null;
    if (!dataOnly) {
        final ApplicationInfo applicationInfo = p.applicationInfo;
        if (applicationInfo == null) {
            Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
            return false;
        }
        if (isForwardLocked(p)) {
            publicSrcDir = applicationInfo.publicSourceDir;
        }
    }
    int res = mInstaller.getSizeInfo(packageName, userHandle, p.mPath, libDirPath, publicSrcDir, asecPath, pStats);
    if (res < 0) {
        return false;
    }
    // Fix-up for forward-locked applications in ASEC containers.
    if (!isExternal(p)) {
        pStats.codeSize += pStats.externalCodeSize;
        pStats.externalCodeSize = 0L;
    }
    return true;
}
Also used : PackageParser(android.content.pm.PackageParser) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)908 PackageManager (android.content.pm.PackageManager)339 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)272 RemoteException (android.os.RemoteException)204 Intent (android.content.Intent)100 ArrayList (java.util.ArrayList)98 IPackageManager (android.content.pm.IPackageManager)96 IOException (java.io.IOException)80 PackageInfo (android.content.pm.PackageInfo)78 ResolveInfo (android.content.pm.ResolveInfo)72 File (java.io.File)64 ComponentName (android.content.ComponentName)52 Bundle (android.os.Bundle)48 Context (android.content.Context)47 PendingIntent (android.app.PendingIntent)43 Drawable (android.graphics.drawable.Drawable)43 UserInfo (android.content.pm.UserInfo)40 ActivityInfo (android.content.pm.ActivityInfo)35 ServiceInfo (android.content.pm.ServiceInfo)35 Resources (android.content.res.Resources)32