Search in sources :

Example 41 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class AppOpsService method readUid.

void readUid(XmlPullParser parser, String pkgName) throws NumberFormatException, XmlPullParserException, IOException {
    int uid = Integer.parseInt(parser.getAttributeValue(null, "n"));
    String isPrivilegedString = parser.getAttributeValue(null, "p");
    boolean isPrivileged = false;
    if (isPrivilegedString == null) {
        try {
            IPackageManager packageManager = ActivityThread.getPackageManager();
            if (packageManager != null) {
                ApplicationInfo appInfo = ActivityThread.getPackageManager().getApplicationInfo(pkgName, 0, UserHandle.getUserId(uid));
                if (appInfo != null) {
                    isPrivileged = (appInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
                }
            } else {
                // Could not load data, don't add to cache so it will be loaded later.
                return;
            }
        } catch (RemoteException e) {
            Slog.w(TAG, "Could not contact PackageManager", e);
        }
    } else {
        isPrivileged = Boolean.parseBoolean(isPrivilegedString);
    }
    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        String tagName = parser.getName();
        if (tagName.equals("op")) {
            Op op = new Op(uid, pkgName, Integer.parseInt(parser.getAttributeValue(null, "n")));
            String mode = parser.getAttributeValue(null, "m");
            if (mode != null) {
                op.mode = Integer.parseInt(mode);
            }
            String time = parser.getAttributeValue(null, "t");
            if (time != null) {
                op.time = Long.parseLong(time);
            }
            time = parser.getAttributeValue(null, "r");
            if (time != null) {
                op.rejectTime = Long.parseLong(time);
            }
            String dur = parser.getAttributeValue(null, "d");
            if (dur != null) {
                op.duration = Integer.parseInt(dur);
            }
            String proxyUid = parser.getAttributeValue(null, "pu");
            if (proxyUid != null) {
                op.proxyUid = Integer.parseInt(proxyUid);
            }
            String proxyPackageName = parser.getAttributeValue(null, "pp");
            if (proxyPackageName != null) {
                op.proxyPackageName = proxyPackageName;
            }
            UidState uidState = getUidStateLocked(uid, true);
            if (uidState.pkgOps == null) {
                uidState.pkgOps = new ArrayMap<>();
            }
            Ops ops = uidState.pkgOps.get(pkgName);
            if (ops == null) {
                ops = new Ops(pkgName, uidState, isPrivileged);
                uidState.pkgOps.put(pkgName, ops);
            }
            ops.put(op.op, op);
        } else {
            Slog.w(TAG, "Unknown element under <pkg>: " + parser.getName());
            XmlUtils.skipCurrentTag(parser);
        }
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 42 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class PinnerService method pinCamera.

private boolean pinCamera(int userHandle) {
    //camera app, we're done.  otherwise, unpin and pin the new app
    if (alreadyPinned(userHandle)) {
        return true;
    }
    ApplicationInfo cameraInfo = getCameraInfo(userHandle);
    if (cameraInfo == null) {
        return false;
    }
    //unpin after checking that the camera intent has resolved
    //this prevents us from thrashing when switching users with
    //FBE enabled, because the intent won't resolve until the unlock
    unpinCameraApp();
    //pin APK
    String camAPK = cameraInfo.sourceDir;
    PinnedFile pf = pinFile(camAPK, 0, 0, MAX_CAMERA_PIN_SIZE);
    if (pf == null) {
        Slog.e(TAG, "Failed to pin " + camAPK);
        return false;
    }
    if (DEBUG) {
        Slog.i(TAG, "Pinned " + pf.mFilename);
    }
    mPinnedCameraFiles.add(pf);
    // determine the ABI from either ApplicationInfo or Build
    String arch = "arm";
    if (cameraInfo.primaryCpuAbi != null && VMRuntime.is64BitAbi(cameraInfo.primaryCpuAbi)) {
        arch = arch + "64";
    } else {
        if (VMRuntime.is64BitAbi(Build.SUPPORTED_ABIS[0])) {
            arch = arch + "64";
        }
    }
    // get the path to the odex or oat file
    String baseCodePath = cameraInfo.getBaseCodePath();
    String odex = null;
    try {
        odex = DexFile.getDexFileOutputPath(baseCodePath, arch);
    } catch (IOException ioe) {
    }
    if (odex == null) {
        return true;
    }
    //not pinning the oat/odex is not a fatal error
    pf = pinFile(odex, 0, 0, MAX_CAMERA_PIN_SIZE);
    if (pf != null) {
        mPinnedCameraFiles.add(pf);
        if (DEBUG) {
            Slog.i(TAG, "Pinned " + pf.mFilename);
        }
    }
    return true;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) IOException(java.io.IOException)

Example 43 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project dynamic-load-apk by singwhatiwanna.

the class DLUtils method getAppIcon.

public static Drawable getAppIcon(Context context, String apkFilepath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = getPackageInfo(context, apkFilepath);
    if (pkgInfo == null) {
        return null;
    }
    // Workaround for http://code.google.com/p/android/issues/detail?id=9151
    ApplicationInfo appInfo = pkgInfo.applicationInfo;
    if (Build.VERSION.SDK_INT >= 8) {
        appInfo.sourceDir = apkFilepath;
        appInfo.publicSourceDir = apkFilepath;
    }
    return pm.getApplicationIcon(appInfo);
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 44 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

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);
            scheduleWrite();
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) RemoteException(android.os.RemoteException)

Example 45 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class CompatModePackages method setPackageScreenCompatModeLocked.

public void setPackageScreenCompatModeLocked(String packageName, int mode) {
    ApplicationInfo ai = null;
    try {
        ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
    } catch (RemoteException e) {
    }
    if (ai == null) {
        Slog.w(TAG, "setPackageScreenCompatMode failed: unknown package " + packageName);
        return;
    }
    setPackageScreenCompatModeLocked(ai, mode);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)921 PackageManager (android.content.pm.PackageManager)345 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)274 RemoteException (android.os.RemoteException)204 Intent (android.content.Intent)103 ArrayList (java.util.ArrayList)98 IPackageManager (android.content.pm.IPackageManager)96 IOException (java.io.IOException)80 PackageInfo (android.content.pm.PackageInfo)79 ResolveInfo (android.content.pm.ResolveInfo)72 File (java.io.File)64 ComponentName (android.content.ComponentName)52 Context (android.content.Context)51 Bundle (android.os.Bundle)50 PendingIntent (android.app.PendingIntent)45 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)33